Swimming pool P11888


Statement
 

pdf   zip

thehtml

(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

Input consists of several cases. Every case begins with the number of slots n, followed by n pairs of triplets h1:m1:s1 h2:m2:s2, which indicate that there is a slot from h1:m1:s1 until h2:m2:s2. Assume 1 ≤ n ≤ 1000, that hours are between 0 and 23, that minutes are between 0 and 59, and that h1:m1:s1 is smaller than h2:m2:s2. The end of input is marked with a special case with n = 0.

Output

For every case, print the maximum number of seconds that you can swim.

Public test cases
  • 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
    
  • Information
    Author
    Lander Ramos
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++