Clock Hands#6781

Clock Hands

10 seconds
256 megabytes
Hard

We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands.

Write a program to find the time at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on or after a given time.

Figure 1. Angles between the second hand and two other hands

Clocks are not limited to -hour clocks. The hour hand of an -hour clock goes around once in hours. The minute hand still goes around once every hour, and the second hand goes around once every minute. At 0:0:0 (midnight), all the hands are at the upright position.

Input

The input consists of multiple datasets. Each of the dataset has four integers , , and in one line, separated by a space. means that the clock is an -hour clock. , and mean hour, minute and second of the specified time, respectively.

You may assume 2 \leq H \leq 100, 0 \leq h < H, 0 \leq m < 60, and 0 \leq s < 60.

The end of the input is indicated by a line containing four zeros.

Figure 2. Examples of -hour clock (-hour clock and -hour clock)

Output

Output the time at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on and after the specified time.

For being h_o : m_o : s_o (s_o seconds past m_o minutes past h_o o'clock), output four non-negative integers h_o, m_o, , and in one line, separated by a space, where is the irreducible fraction representing s_o. For integer s_o including , let be .

The time should be expressed in the remainder of hours. In other words, one second after (H-1):59:59 is 0:0:0, not H:0:0.

Examples

Example 1

Loading
Loading