#P3462. Date

    ID: 2346 远端评测题 3000ms 64MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2010 ACM-ICPC Multi-University Training Contest(3)——Host by WHU

Date

Problem Description

Is it just another problem about year, month and day? No, today we have a more romantic meaning – dating with a girl.
iSea now has a date to be anxious to rush, unfortunately, the city's way is always so complicated, so time goes unconsciously and fast. In order to more quickly rushed to rendezvous, iSea has already drawn a topographic map of this city, he find that the city is composed of a number of equal squares, between the squares, there are some traffic lights controlling the traffic, a basic map example:

Each time, iSea must proceed from the starting point of the upper left corner to reach the lower right corner. The squares’ size is fixed, with a length of two meters and a width of one meter. iSea usually only go across the intersection under the green light, the time he costs is one minute, for safety's sake, in the whole one minute the green light should be lighten, we also know, iSea’s speed along the grid is a constant, one meter per minute.
iSea’s map gives some more specific information about the city, the number of vertical grid N, the number of horizontal grid M, and the time the traffic lights change alternating. In order to simplify the problem, we assume that one day start at 0 hour, traffic lights first allow passengers traverse the intersection from left and right, but block up and down in the intersection, after a time Ti, the traffic lights block left and right to allow access up and down, the time is also the Ti, so the cycle goes.
After simple calculation, iSea finds he may be late for this date, in order to reach the destination in time, he decides to make one exception, in an emergency he would pass through a intersection even if a red light was lighten, but not to loss of too many RP, he asks himself go across the red light at most once, then, can you help him, calculate when he could arrive in rendezvous at the earliest?

Input

There are several test cases in the input.

Each test case begin with two integers N, M (1 < N, M ≤ 30), indicating the number of the vertical grid and the horizontal grid.
Then N-1 lines follow, each line contains M-1 numbers Ti (0 < Ti ≤ 10), their meaning is in the description.
The last line is the start time of iSea, in the form of HH:MM.

The input terminates by end of file marker.

Output

For each test case, output the earliest time iSea can arrive, in the form of HH:MM, you may assume that all the things happen within the same day

2 2 3 12:03 2 3 2 2 12:00
12:05 12:05

Author

iSea @ WHU