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 (`irc.pirc.pl`

) in `#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.

*The following task is a significantly harder version of task
Words from the third
stage of 16th Polish OI. It wasn't used in the contest itself, but is an extension for those
who solved "Words" and want more. :-)*

We are interested in the strings of the form for This sequence begins with the following strings:

, , , , , .

We call the string a *substring* of the string if it occurs
in as a contiguous (i.e. one-block) subsequence.
A sequence of integers is given.
Your task is to check whether a string of the form
is a substring of for some , and if it is,
you shuold find minimal such .

The first line of the standard input contains a single integer , . The second line of standard input holds non-negative integers (), separated by single spaces.

Your programme should print out lines to the standard output,
one for each test unit.
Your programm should print to standard output minimal non-negative integer ,
such that is a substring of
, or `NIE` (*no* in Polish) if such doesn't exist.

For the input data:

2 1 2

the correct result is:

4

while for following input data:

2 2 0

the correct answer is

NIE

**Explanation of the example:**
The string from the first test case is - it is a substring
of .
In the second test unit there is a string ,
which is not a substring of for any .

*Task author: Bartosz Walczak.*