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

Задача 38195. Checkout


At one of the Moscow railway stations tickets are sold by N cash desks. 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, a single integer N (0 < N ≤ 1000) is entered.

Each of the next N lines contains 4 space-separated integers, the first two of which indicate the opening time of the cash desk in hours and minutes (hours — integer from 0 to 23, minutes — integer from 0 to 59), the remaining two &mdash ; closing time in the same format. Numbers are separated by spaces.

The opening time means that at the corresponding minute the cash desk is already working, and the closing time — that at the appropriate moment the cashier is no longer working. For example, a cash desk open from 10:30 a.m. until 18:30, 480 minutes daily.

If the opening time coincides with the closing time, then the cash desk 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.

Imprint
It is required to print one number — the total time per day (in minutes), during which all N cash desks work.
Examples
# Input Output Explanations
1 3
1 0 23 0
12 0 12 0
22 0 2 0
120 The first cash desk is open from 1:00 to 23:00, the second – around the clock, the third – from 10 p.m. to 2 a.m. the next day. Thus, all three cash desks work simultaneously from 22:00 to 23:00 and from 1:00 to 2:00, that is, 120 minutes.
2 2
9 30 14 0
14 15 21 0
0 The first cash desk is open until 14:00, and the second starts at 14:15, that is, the cash desks do not work at the same time.
3 2
14 00 18 00
10 00 14 01
1 Together, cash registers work only for one minute – from 14:00 to 14:01 (at 14:01 the second ticket office is no longer open).