Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/hafta-kuni-va-vaqt

Weekday and time

Medium 1000 ms 64 MB 38%
Share

The days of the week are numbered: $1$ — Monday, $2$ — Tuesday, …, $7$ — Sunday. It is now day $d$ of the week, $h$ hours $m$ minutes (in $24$-hour format). Find the day of the week and the time in $t$ minutes. At midnight the clock shows $0$ hours $0$ minutes and the next day begins.

A circle of the weekdays: which day and time it will be t minutes after the given day and time

Input

One line with four integers: $d$, $h$, $m$ and $t$.

Output

One line with three integers: the weekday (from $1$ to $7$), hours (from $0$ to $23$) and minutes (from $0$ to $59$).

Note

$1 \le d \le 7$
$0 \le h \le 23$
$0 \le m \le 59$
$0 \le t \le 10^{9}$

Examples

Input #1
7 22 30 200
Output #1
1 1 50
Input #2
3 9 15 0
Output #2
3 9 15

Sign in to submit a solution

Signing up is free and takes a minute.