In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
Children have gathered in a circle and are playing with a counting-out rhyme. The children are numbered to so that (for ) the child number stands to the left of the child number , and the child number stands to the left of the child number . The child who is counted out in the rhyme leaves the circle. The counting out is repeated until there is no one left in the circle. The rules of the play are as follows:
We observe the children playing counting out and we notice the order in which they leave the circle. Basing on this information we try to guess how many syllables the counting-out rhyme consists of.
Write a program which:
In the first line of the standard input there is one positive integer , . In the second line there are integers separated by single spaces. The -th number tells at which turn of the counting out the child of number left the circle.
Your program should write in the first and only line of the standard output either one integer: the smallest number of syllables that the counting-out rhyme can consist of, or one word NIE, if such a number does not exist.
For the input data:
4 1 4 2 3
the correct result is:
Task author: Jakub Pawlewicz.