An antique brass chronometer displays time using two independent rings of tiny indicator lamps instead of hands. The hour ring has 4 lamps, weighted 8, 4, 2, 1; whichever lamps are lit, their weights sum to the current hour, an integer from 0 to 11. The minute ring has 6 lamps, weighted 32, 16, 8, 4, 2, 1; the lit lamps on that ring sum to the current minute, an integer from 0 to 59. A restorer knows that exactly k lamps are lit across both rings combined, but the chronometer's glass is too fogged to see which ones. Determine every hour:minute reading that is consistent with exactly k lamps being lit in total.
A single line containing one integer k, the total number of lit lamps across both rings.
Print an integer C — the number of distinct valid readings — on the first line. Then print C more lines, one per reading, formatted as H:MM (the hour with no leading zero, the minute zero-padded to exactly two digits), sorted by hour ascending and then by minute ascending. Print no further lines if C is 0.
0 <= k <= 10.Example 1
Input
1
Expected
10 0:01 0:02 0:04 0:08 0:16 0:32 1:00 2:00 4:00 8:00
Explanation
With exactly one lamp lit, either exactly one minute-ring lamp is lit while the hour ring is fully dark (giving minute values equal to one of the six weights 1,2,4,8,16,32 with hour 0), or exactly one hour-ring lamp is lit while the minute ring is fully dark (giving hour values equal to one of the four weights 1,2,4,8 with minute 0). That is 6+4=10 readings total: 0:01, 0:02, 0:04, 0:08, 0:16, 0:32, 1:00, 2:00, 4:00, 8:00, sorted by hour then minute.
Example 2
Input
8
Expected
8 7:31 7:47 7:55 7:59 11:31 11:47 11:55 11:59
Explanation
8 is the maximum number of lamps that can be lit at once while both rings stay within their valid ranges. The hour ring can show at most 3 lit lamps within 0-11 (hour 7=4+2+1 or hour 11=8+2+1), and the minute ring can show at most 5 lit lamps within 0-59 (minute 31=16+8+4+2+1, 47=32+8+4+2+1, 55=32+16+4+2+1, or 59=32+16+8+2+1 — all 6 lamps would need value 63, which exceeds 59). Pairing each of the 2 valid 3-lamp hours with each of the 4 valid 5-lamp minutes gives 2x4=8 readings, all using exactly 8 lamps: 7:31, 7:47, 7:55, 7:59, 11:31, 11:47, 11:55, 11:59.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →