#K82647. Next Alarm

    ID: 36022 Type: Default 1000ms 256MiB

Next Alarm

Next Alarm

You are given a list of alarm times in the format HH:MM:SS and a current time. Your task is to determine the next alarm time that will ring after the current time. Note that the times are considered on a cyclic 24-hour clock. In other words, if the current time is later than some alarm times, those alarms will trigger on the next day.

We can convert a time in the format HH:MM:SS into seconds using the formula: [ \text{seconds} = 3600 \times h + 60 \times m + s ]

Then, for each alarm, compute the difference as: [ \text{diff} = (\text{alarm_seconds} - \text{current_seconds}) \mod 86400 ]

The alarm with the smallest non-negative difference is the next alarm to ring.

inputFormat

The input consists of multiple test cases. Each test case is formatted as follows:

  1. An integer n (> 0) representing the number of alarms.
  2. n lines, each containing an alarm time in the format HH:MM:SS.
  3. A line containing the current time in HH:MM:SS format.

The sequence of test cases ends when a test case starts with 0 (zero).

outputFormat

For each test case, output a single line containing the next alarm time in HH:MM:SS format.

## sample
2
08:30:00
12:45:00
09:20:00
0
12:45:00

</p>