#C11665. Next Closest Time

    ID: 41006 Type: Default 1000ms 256MiB

Next Closest Time

Next Closest Time

You are given a time in the format HH:MM. The task is to find the next closest time that can be formed by reusing the exact same digits as in the given time. The next closest time is defined as the smallest time (in minutes) that is strictly greater than the given time. If no such time exists on the same day, the result wraps around to the next day using the smallest possible valid time.

For instance, if the given time is 19:34, the next closest time is 19:39, and if the given time is 23:59, the answer becomes 22:22 because after 23:59 the clock wraps to the next day. The validation of time is subject to the condition:

\(0 \leq \text{HH} < 24\) and \(0 \leq \text{MM} < 60\).

You must use only the digits that appear in the given time to form a new valid time.

inputFormat

The input consists of a single line containing a string in HH:MM format.

outputFormat

Output a string representing the next closest time in HH:MM format, formed using exactly the same digits as the input.## sample

19:34
19:39