Hyperclock
Time limit1sMemory limit128 MB
Given the cycle sizes of N clocks, the tour visits every configuration once; its length is the number of configurations, the product of the sizes.
- Level
Medium4 of 10
- Topics
- Math, Combinatorics
- Solved
- No attempts yet
Problem
Brainy Smurf decided that days were simply too short. At this rate he would never finish writing every volume of Quotations of Brainy Smurf, so he went to Father Time and asked him to stretch each day to 48 hours. Father Time was reluctant, but after enough pestering he gave in, on one condition: Brainy Smurf must first solve the Hyperclock puzzle.
The Hyperclock is built from clocks. Each clock has a single hand and some numbers printed around its face. The face of clock (for ) is marked with the numbers through , arranged in a circle. At the start every hand points to .
In one move you turn the hand of any single clock one position clockwise or counterclockwise. Because each face is circular, position and position are neighbors, so a hand can step directly from one to the other.
A configuration is the combination of numbers that the hands currently point to. There are exactly different configurations.
A complete tour is a sequence of moves that starts from the initial configuration (every hand on ), passes through every possible configuration exactly once, and after the final move returns all hands to their initial positions. Help Brainy Smurf work out how long such a tour is.
Input
The first line contains one positive integer , the number of clocks.
Each of the next lines contains one integer (with ): the amount of numbers on the face of clock .
The total number of configurations is at most .
Output
It can be shown that a complete tour always exists. Output a single integer: the number of moves in a complete tour of the Hyperclock.