Programming Problem #32
"Syncing Signals"

Boulevard Avenue is a long street that runs downhill for many blocks. At each block is an intersection and a traffic light. From the top of the hill you can see between two and ten of the upcoming traffic lights, depending on how foggy it is. Most of the times that you drive down this street the upcoming lights are a random combination of red, green, and yellow, but occassionally they are all green. Given the cycle times of each of the upcoming traffic lights, how often will this happen? In other words, given that the next N lights all simultaneously turn green, how long will it be before they are all green again?

The input consists of one or more lines, each of which contains an integer N indicating the number of traffic lights, followed by N integers representing the cycle time for each light. N will be between 2 and 10 (inclusive) and each cycle time will be between 10 and 90 seconds (inclusive). The cycle time is the length of time that a light will be green or yellow; it will stay red for the same amount of time. Lights will always show yellow for 5 seconds before turning red. For example, a light with a cycle time of 30 seconds will show green for 25 seconds, then yellow for 5 seconds, then red for 30 seconds, and then the cycle will repeat.

For each input line, assume that all traffic lights simultaneously turn green, and then display the next time that they all simultaneously show green after at least one of them has turned yellow. Note that since the cycle times can be different for each light, all lights might show green even though they didn't turn green at the same time. Display the time in minutes and seconds in the format MM:SS. If it will be more than one hour before the lights simultaneously show green, output ??:??.

Input must be read from the file "prob32.in", and output must be written to the file "prob32.out". All output to the screen will be ignored.


Example Input

<BOF>
3 30 25 35
6 25 25 25 25 25 25
2 15 30
8 20 21 30 23 29 25 27 22
2 19 20
<EOF>

Example Output

05:00
00:50
01:00
??:??
00:40

A version of this problem originally appeared in the 1991 ACM North Central regional programming contest.

Dr. Eric Shade