Just thinking aloud about how NOT_STARTING_ON_SPECIAL_PENALTY affects this... I think none of this code needs to change?  It's really the leftmost starting char that controls whether the combined pair of ranges deserves a penalty, and the leftmost range _will_ contain / not contain that penalty correctly.  (And the rightmost range will never contain a spurious penalty since it's guaranteed to start on a special).