#CCBOTPBA0000062. Bộ đếm thời gian kết hợp (Combined Time Counter)

Bộ đếm thời gian kết hợp (Combined Time Counter)

Combined Time Counter

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

A 24-hour clock starts at hour hh and minute mm. There are nn non-negative minute increments did_i, applied in input order. Minutes wrap at 60 and hours wrap at 24; one increment may cross several hours or days. Print the clock time after all nn increments.

Input

The first line contains integers hh and mm. The next line contains integer nn. Then follow nn integers d1,d2,…,dnd_1,d_2,\ldots,d_n indicating the minute increments, separated by whitespace.

Output

Print two integers, the final hour hh and minute mm, separated by one space. Leading zero padding is not required.

Subtasks

  • Subtask 1 (20%): $0\le h\le23,\ 0\le m\le59,\ 0\le n\le20,\ 0\le d_i\le60$.
  • Subtask 2 (30%): $0\le h\le23,\ 0\le m\le59,\ 0\le n\le1000,\ 0\le d_i\le1440$.
  • Subtask 3 (50%): $0\le h\le23,\ 0\le m\le59,\ 0\le n\le100000,\ 0\le d_i\le100000$.

Examples

Example 1

Input:

23 59
3
1 60 1440

Output:

1 0

Explanation: Starting at 23:59, adding 1 yields 00:00, adding 60 yields 01:00, and adding 1440 (one day) leaves 01:00. Print 1 0.

Example 2

Input:

9 7
0

Output:

9 7

Explanation: There are no increments; the initial time 09:07 remains unchanged.

Example 3

Input:

10 30
2
90 30

Output:

12 30

Explanation: 10:30 + 90 minutes = 12:00; adding another 30 minutes gives 12:30. Print 12 30.