(The original statement in Catalan has some private jokes. This English version goes straight to the point of the problem.)
There is a swimming pool with some free slots of time. There are two rules:
A slot can only be used from its beginning.
If a slot is used, even if partially, you must wait for at least one hour from the end of the slot before you can use another slot.
Input consists of several cases. Every case begins with the number of slots , followed by pairs of triplets :: ::, which indicate that there is a slot from :: until ::. Assume , that hours are between 0 and 23, that minutes are between 0 and 59, and that :: is smaller than ::. The end of input is marked with a special case with .
For every case, print the maximum number of seconds that you can swim.
Input
1 00:00:00 00:10:00 2 01:10:00 02:10:00 00:00:00 00:10:00 2 01:09:59 02:10:00 00:00:00 00:10:00 4 00:10:40 00:35:30 01:00:00 01:55:00 02:10:00 03:15:00 12:00:20 23:59:59 5 12:00:00 13:00:00 12:30:00 14:30:00 14:00:00 15:00:00 15:30:00 17:30:00 16:00:00 17:00:00 0
Output
600 4200 3601 48569 14400