You are the owner of a railway system between n cities, numbered by integers from 1 to n. Each train travels from the start station to the end station according to a very specific timetable (always on time), not stopping anywhere between. On each station a departure timetable is available. Unfortunately each timetable contains only direct connections. A passenger that wants to travel from city p to city q is not limited to direct connections however: he or she can change trains. Each change takes zero time, but a passenger can only change from one train to another if the latter departs after the first train arrives. People would like to have a timetable of all optimal connections. A connection departing from city p at A o'clock and arriving in city q at B o'clock is called optimal if there is no connection that begins in p not sooner than at A and ends in q not later than at B . We are only interested in connections that can be completed during the same day.
The first line of the timetable description contains only one integer m
. Each of the following m
lines corresponds to one position in the timetable and contains: departure time A
, arrival time B
and destination city number t
separated by single spaces. Departure time A
and arrival time B
are written in format hh : mm
, where hh
are two digits representing full hours
and mm
are two digits representing minutes
. Positions in the timetable are given in non-decreasing order according to the departure times. The number of all positions in all timetables does not exceed 1000000
.
3 3 09:00 15:00 3 10:00 12:00 2 11:00 20:00 3 2 11:30 13:00 3 12:30 14:00 3 0
2 10:00 14:00 11:00 20:00