def get_headway(veh, lead):
    """Calculates distance from Vehicle veh to the back of Vehicle lead."""
    hd = lead.pos - veh.pos - lead.len
    if veh.road != lead.road:
        hd += veh.lane.roadlen[lead.road]  # lead.road is hashable because its a string
    return hd