Hyperclock
Memory limit: 32 MB
Brainy Smurf concluded that days were too short, and, because of that,
he would not manage to write all the volumes of Quotations of Brainy Smurf.
He decided to visit Father Time and ask him to extend each day to 48 hours. Father Time
didn't want to accept his request, but, after Brainy Smurf's importunate demands,
eventually agreed. However, he imposed a condition: Brainy Smurf must first solve the Hyperclock puzzle.
The Hyperclock consists of clocks. Each clock has one hand and some numbers on its face.
On the face of -th clock () there are numbers from to .
At the very beginning, all hands point to the number . The puzzle was explained by Father Time as follows:
You have to perform a sequence of moves. In one move you can turn
the hand of an arbitrary clock one position clockwise or counterclockwise.
After the last move, the Hyperclock's hands must return to their initial positions.
Moreover, each possible configuration of the Hyperclock must appear exactly once.
Brainy Smurf has been tinkering with the Hyperclock for over an hour and is
becoming increasingly convinced that, despite his wisdom, he will not manage
to solve the puzzle. Help him!
Input
The first row of the input contains one positive integer . In each of the following rows there is
one integer greater than : in the -th row there is the number .
The number of all possible configurations (namely ) is not greater than .
Output
If there is no solution for the puzzle, output the single word NIE (Polish for no).
Otherwise, rows should be
output, describing the subsequent moves. Each row must contain two integers. The first
number () is the number of the clock whose hand is turned. The second number indicates
a direction: (for clockwise) or (for counterclockwise).
If there are many possible solutions, you can output any of them.
Example
For the input data:
3
2
2
3
the correct result is:
1 1
2 1
1 -1
3 1
1 1
2 -1
3 1
2 1
1 -1
2 -1
3 -1
3 -1
Task author: Jakub Pawlewicz (story by Tomasz Idziaszek).