#P4483. Magical Clock Triples

    ID: 17729 Type: Default 1000ms 256MiB

Magical Clock Triples

Magical Clock Triples

In this problem, you are given a positive integer (k). A clock time is represented in the format hh:mm where (0 \leq hh < 24) and (1 \leq mm < 60) (i.e. the minutes are nonzero so that the time is not a whole hour). For any time, we define its ratio as (\frac{hh}{mm}).

Consider three clock times ((h_1:m_1,; h_2:m_2,; h_3:m_3)). Their "sum" is defined by adding the hours and minutes normally with minute carry‐over: let (S_h = h_1+h_2+h_3) and (S_m = m_1+m_2+m_3). Write (q = \lfloor S_m/60 \rfloor) and (r = S_m \bmod 60); then the summed time is ((S_h+q):r). (Note that (r) is guaranteed to be nonzero so that the result is not a whole hour, and (S_h+q < 24) so that the result is a valid time.)

The triple of clock times is said to be magical if the sum of their ratios equals the ratio of the summed time. In other words, the following equation holds: [ \frac{h_1}{m_1}+\frac{h_2}{m_2}+\frac{h_3}{m_3} = \frac{S_h+q}{r}, \quad\text{where } S_m = 60q+r,; 1\le r<60,; S_h+q<24. ]<br> All magical clock triples (where the clocks are considered as an unordered set) are collected and then each triple is sorted in lexicographical order (comparing the strings in hh:mm format) and the list of triples is sorted in lexicographical order. Your task is: given (k), output the (k)th smallest magical clock triple. The output triple should list the three times (each in the format hh:mm) separated by a space.
Note: It is guaranteed that (k) is valid (i.e. there exists at least (k) magical triples).

inputFormat

The input consists of a single integer \(k\) on a line.

outputFormat

Output the \(k\)th lexicographically smallest magical clock triple. The three times should be output in the format hh:mm (with leading zeros) and separated by a single space.

sample

1
00:01 00:02 00:03