5493.New Time

Time Limit: 1s Memory Limit: 256MB

Nikolay has a digital clock that displays time in 24-hour format, showing two integers: hours (from $00$ to~$23$) and minutes (from $00$ to $59$). For example, the clock can show ${00:00}, {18:42}$, or ${23:59}$.

The clock has two buttons that can be used for manual adjustment:

  • Button A sets the clock forward by $1$ minute. For example, ${05:33}$ becomes ${05:34}$, ${16:59}$ becomes ${17:00}$, and ${23:59}$ becomes ${00:00}$.
  • Button B sets the clock forward by $1$ hour. For example, ${01:42}$ becomes ${02:42}$, and ${23:14}$ becomes ${00:14}$.

Nikolay has noticed that the time on his clock does not look right. He wants to adjust the clock to the correct time by pressing the buttons as few times as possible.

Find the smallest number of button presses needed to adjust the clock.

Input Format(From the terminal/stdin)

The first line contains the time shown on the clock in the ${hh:mm}$ format ($00 \le \mathtt{hh} \le 23$; $00 \le \mathtt{mm} \le 59$).

The second line contains the correct time in the same format.

Output Format(To the terminal/stdout)

Print a single integer--- the smallest number of button presses Nikolay needs to adjust the time on his clock.

Sample Input 1

Copy
11:57
12:00
     \n
     \n

Sample Output 1

Copy
3
 \n

Sample Input 2

Copy
09:09
21:21
     \n
     \n

Sample Output 2

Copy
24
  \n

Sample Input 3

Copy
19:44
08:50
     \n
     \n

Sample Output 3

Copy
19
  \n

Hints

In the first example test, Nikolay can adjust the time by pressing button A three times.

In the second example test, Nikolay should press button A and button B $12$ times each.

Source: NWRRC 2022

Submit

请先 登录

© 2025 FAQs