Five Nights at Freddy's
Time limit2sMemory limit512 MB
Construct a cyclic sequence containing every camera so that repeats of camera i are at most a_i positions apart, or report that it is impossible.
- Level
Hard8 of 10
- Topics
- Number theory, Greedy, Implementation
- Solved
- No attempts yet
Problem
Maria has finally got her dream job. She became a professional night guard at the Sky Tower. One of her duties is to report unwanted activity in the building. Fortunately, she can do her job without leaving her comfortable chair. All she has to do is keep track of the cameras installed in the skyscraper. To do so, she must handle different cameras, numbered from to . She wants to create a transmission cycle in which she will process information from the cameras. She will watch the transmission from one camera for one minute and then switch to the next camera in the cycle. Every camera must appear at least once in the cycle. There are additional constraints. In the cycle, two consecutive appearances of camera cannot be more than positions apart. Fortunately for Maria, for every , at least one of and is a multiple of the other. If possible, help Maria create such a cycle with length at most .
Input
The first line contains one integer , the number of test cases described in the following lines.
The first line of each test case contains one integer , the number of cameras in the Sky Tower.
The next line describes the cameras. The -th number is the parameter of the -th camera.
Output
For each test case:
If it is impossible to construct such a cycle, the first and only line of the output should consist of the single word NIE.
If it is possible to construct such a cycle, output the single word TAK on the first line. The following line should contain a description of a transmission cycle. The first number is the length of the cycle. The next numbers are the camera numbers in the order they appear in the cycle.
If there are several possible answers, print any of them.