#P5944. [POI 2002] 出圈游戏
[POI 2002] 出圈游戏
Problem Description
There are children numbered from to playing a circle elimination game. Child stands to the left of child . Child stands to the left of child . First, child starts counting, then the child on the left continues counting in order. Whenever the count reaches a certain number , that child leaves the circle. The game ends when all children have left the circle.
Now you are given the elimination order. Find the smallest .
Input Format
The first line contains a positive integer .
The second line contains integers . The -th integer means that the child numbered is the -th to leave the circle.
Output Format
Output the smallest . If it does not exist, output the word NIE.
4
1 4 3 2
NIE
4
1 4 2 3
5
Hint
For of the testdata, .
: A new set of hack testdata has been added.
Translated by ChatGPT 5