~/algor $ cat problems/integer-keyingi-avtobus
Next bus
The first bus leaves the stop at $h_{1}$ hours $m_{1}$ minutes, and then a bus leaves every $d$ minutes. A passenger came to the stop on the same day at $h_{2}$ hours $m_{2}$ minutes. Find how many minutes they will wait for the next bus. If a bus leaves exactly at the minute the passenger arrives, the wait is $0$ (the passenger makes it). For example, if the first bus leaves at $6{:}00$ and $d = 15$, buses leave at $6{:}00$, $6{:}15$, $6{:}30$, …; a passenger who arrives at $6{:}20$ waits $10$ minutes.
Input
The first line contains three integers: $h_{1}$, $m_{1}$ and $d$.
The second line contains two integers: $h_{2}$ and $m_{2}$.
Output
One integer — the waiting time in minutes.
Note
$0 \le h_{1}, h_{2} \le 23$
$0 \le m_{1}, m_{2} \le 59$
$1 \le d \le 1440$
$h_{2}$ hours $m_{2}$ minutes is not earlier than $h_{1}$ hours $m_{1}$ minutes.
Examples
6 0 15 6 20
10
7 30 25 8 0
20