Plus
Pin


Problem description Progress
ID 38195. Checkout
Темы: Simulation tasks    date and time   

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).

ID 38210. alarm clocks
Темы: Conditional operator    One-Dimensional Arrays    date and time    Bust   

The alarm clock on a cell phone can be set to ring at the same time every day, or at a specified time on a specific day of the week. Multiple alarms can be set independently.

Use the information about alarms and the current time and day of the week to determine when the next alarm will sound.

Input
The first line contains three numbers that specify the current time: the day of the week (from 1 to 7), hours and minutes.

The second line contains one natural number N, not exceeding 100 – number of alarms.

The next N lines contain descriptions of N alarm clocks. The description of each alarm consists of three numbers: day of the week (a number from 1 to 7 for Monday,  …, Sunday, respectively, 0 – if the alarm should ring every day), hours (from 0 to 23), minutes (from 0 to 59).


Imprint
Print  separated by a space, three numbers specifying the day of the week, hours and minutes when the next alarm clock rings.
 

Examples
# Input Output Explanation
1 2 10 20
2
1 23 15
0 10 10
3 10 10  
2 7 1 1
3
7059
7 23 59
7 1 1
7 1 1 In the second example, the third alarm will ring at the start time.

ID 38235. diary
Темы: date and time   

Vasya was presented with two diaries for the i-th year. He used one in the i-th year and now he wonders when the next year will come with exactly the same calendar so that he can use the second diary.

Input
One natural number i is entered, not exceeding 2011.

Imprint
Print a single number - the number of the year when the second diary can be used.

Examples

# Input Output
1 2011 2022
2 1 7

ID 38467. Time Zones
Темы: date and time   

Tanya decided to call her friend, but remembered that she lives very far away, so it may be too late or early in her friend's time zone. Tanya's clock shows exactly H hours, Tanya lives in the time zone with them UTC + A, and her friend – in the UTC+B time zone. Help Tanya determine the time in her friend's time zone at this moment.
The program receives as input three integers H, A and B, 0 ≤ H≤ 23, ?11 ? A≤ 12, −11≤ B≤ 12.

In the UTC+A time zone, the local time is greater than the time in the UTC+0 time zone by A hours (if A < 0, then |A| hours less). For example, if it is 12 o'clock in the UTC+0  time zone, then in the UTC+1 time zone – 13 hours, and in the time zone UTC−1 – 11 o'clock. 
The program should output a single number – time (number of hours) in the girlfriend's time zone.
Time in this task means the number of hours that can take values ​​from 0 to 23. When solving the problem, please note that in the friend time zone there may already be the next date or the previous date, the program should display the number of hours on the friend's watch in this moment, that is, a number from 0 to 23.
 

Examples
# Input Output Explanation
1 15
3
-5
7 Tanya's – 15 hours, she lives in the UTC + 3 time zone. In the hour
UTC+0 is now 12 o'clock. Girlfriend lives in UTC−5,
and it's 7 o'clock now.