Codeforces Round 885 (Div. 2)
F
Vika and Wiki
Codeforces
2400
原题
← E→
翻译中…

Recently, Vika was studying her favorite internet resource - Wikipedia.

翻译中…

On the expanses of Wikipedia, she read about an interesting mathematical operation bitwise XOR, denoted by $\oplus$.

翻译中…

Vika began to study the properties of this mysterious operation. To do this, she took an array $a$ consisting of $n$ non-negative integers and applied the following operation to all its elements at the same time: $a_i = a_i \oplus a_{(i+1) \bmod n}$. Here $x \bmod y$ denotes the remainder of dividing $x$ by $y$. The elements of the array are numbered starting from $0$.

翻译中…

Since it is not enough to perform the above actions once for a complete study, Vika repeats them until the array $a$ becomes all zeros.

翻译中…

Determine how many of the above actions it will take to make all elements of the array $a$ zero. If this moment never comes, output $-1$.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \le n \le 2^{20}$) - the length of the array $a$.

翻译中…

It is guaranteed that $n$ can be represented as $2^k$ for some integer $k$ ($0 \le k \le 20$).

翻译中…

The second line contains $n$ integers $a_0, a_1, a_2, \dots, a_{n-1}$ ($0 \le a_i \le 10^9$) - the elements of the array $a$.

翻译中…

Output

翻译中…

Output a single number - the minimum number of actions required to make all elements of the array $a$ zero, or $-1$ if the array $a$ will never become zero.

翻译中…

Note

翻译中…

In the first example, after one operation, the array $a$ will become equal to $[3, 3, 3, 3]$. After one more operation, it will become equal to $[0, 0, 0, 0]$.

翻译中…

In the second example, the array $a$ initially consists only of zeros.

翻译中…

In the third example, after one operation, the array $a$ will become equal to $[0]$.

翻译中…

样例

Input #1
4
1 2 1 2
Output #1
2
InputCopy OutputCopy
Input #2
2
0 0
Output #2
0
InputCopy OutputCopy
Input #3
1
14
Output #3
1
InputCopy OutputCopy
Input #4
8
0 1 2 3 4 5 6 7
Output #4
5
InputCopy OutputCopy
题目信息
题号
1848F
时间限制
2 s
内存限制
256 MB
标签
二分
位运算
组合数学
分治
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。