Words 2

No attempts yetTime limit1sMemory limit128 MB

Problem

Define a function hh that acts on binary strings (strings over the digits 0 and 1). hh transforms a string by replacing every 0 with 1 and every 1 with the two-character string 10, with all replacements done simultaneously and independently. For example, hh maps 1001 to 101110, and it maps the empty string to the empty string. The function hh is injective. Let hkh_k denote hh composed with itself kk times; h0h_0 is the identity, so h0(w)=wh_0(w) = w.

Consider the one-character string 0 and the strings hk(0)h_k(0) for k=0,1,2,k = 0, 1, 2, \dots. This sequence begins:

0, 1, 10, 101, 10110, 10110101, ...

A string xx is a substring of a string yy if it occurs in yy as a contiguous block. Given integers k1,k2,,knk_1, k_2, \dots, k_n, decide whether the concatenation

hk1(0)hk2(0)hkn(0)h_{k_1}(0)\,h_{k_2}(0)\cdots h_{k_n}(0)

is a substring of hm(0)h_m(0) for some mm, and if so find the smallest such mm.

Input

The first line contains one integer nn (1n1,000,0001 \le n \le 1{,}000{,}000). The second line contains nn non-negative integers k1,k2,,knk_1, k_2, \dots, k_n (0ki1090 \le k_i \le 10^9), separated by single spaces.

Output

Print the smallest non-negative integer mm such that hk1(0)hk2(0)hkn(0)h_{k_1}(0)\,h_{k_2}(0)\cdots h_{k_n}(0) is a substring of hm(0)h_m(0). If no such mm exists, print NIE.