Олимпиадный тренинг

Задача 33140. Checkout


Задача

Темы: "Два указателя"
N tickets are sold at one of the Moscow railway stations. Each cash desk works without interruption for a certain period of time according to a fixed schedule (the same every day). It is required to determine how long during the day all cash desks work at the same time.
 
Input
First enter one integer N (0<N<=10000).
 
In each of the next N lines there are 6 space-separated integers, the first three of which indicate the opening time of the cash desk in hours, minutes and seconds (hours — integer from 0 to 23, minutes and seconds — integers from 0 up to 59), the remaining three — closing time in the same format. Numbers are separated by spaces.
 
The opening time means that the cashier is already open at the corresponding second, and the closing time — that at the corresponding second the cashier is no longer working. For example, a cash desk that is open from 10:30:30 to 10:35:30 is open for 300 seconds a day.
 
If the opening time coincides with the closing time, then the ticket office is open around the clock. If the first time is greater than the second, then the cash desk starts work before midnight, and ends — the next day.
 
Output
Required to output a single number — total time per day (in seconds) during which all N cash desks work.
 
Input Output
3
1 0 0 23 0 0
12 0 0 12 0 0
22 0 0 2 0 0
7200
2
9 30 0 14 0 0
14 15 0 21 0 0
0
2
14 0 0 18 0 0
10 0 0 14 0 1
1