#ARC152E. [ARC152E] Xor Annihilation

[ARC152E] Xor Annihilation

Score : 800800 points

Problem Statement

On a number line, there are 2N12^N-1 balls at the coordinates x=1,2,3,...,2N1x=1,2,3,...,2^N-1, and the ball at x=ix=i has a weight of wiw_i. Here, w1,w2,...,w2N1w_1, w_2,...,w_{2^N-1} is a permutation of the integers from 11 through 2N12^N-1. You will choose a non-negative integer ZZ at most 2N12^N-1 and attach a weight of ZZ at each of the coordinates x=±100100100x=\pm 100^{100^{100}}. Then, the balls will simultaneously start moving as follows.

  • At each time, let RR be the total XOR\mathrm{XOR} of the weights of the balls and attached weights that are strictly to the right of the coordinate of a ball, and LL be the total XOR\mathrm{XOR} of the weights of the balls and attached weights that are strictly to the left. If R>LR>L, the ball moves to the right at a speed of 11 per second; if L>RL>R, the ball moves to the left at a speed of 11 per second; if L=RL=R, the ball stands still.
  • If multiple balls exist at the same coordinate (when, for instance, two balls coming from the left and right reach there), the balls combine into one whose weight is the total XOR\mathrm{XOR} of their former weights.

For how many values of ZZ will all balls come to rest within 100100100^{100} seconds?

What is $\mathrm{XOR}$?

The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows.

  • When $A \oplus B$ is written in binary, the $k$-th lowest bit ($k \geq 0$) is $1$ if exactly one of the $k$-th lowest bits of $A$ and $B$ is $1$, and $0$ otherwise.
For instance, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110).
Generally, the bitwise \mathrm{XOR} of k non-negative integers p_1, p_2, p_3, \dots, p_k is defined as (\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k), which can be proved to be independent of the order of p_1, p_2, p_3, \dots, p_k.

Constraints

  • 2N182\leq N\leq 18
  • 1wi2N11\leq w_i\leq 2^N-1
  • wiwjw_i\neq w_j if iji\neq j.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

w1w_1 w2w_2 \ldots w2N1w_{2^N-1}

Output

Print the answer as an integer.

2
1 2 3
1

Let us call a ball with a weight of ii simply ii.

If Z=0Z=0, for instance, 11 and 22 first move to the right, and 33 moves to the left. Then, the moment 22 and 33 collide and combine into one ball, it starts moving to the left. Afterward, the moment all balls from 11 to 33 combine into one ball, it stands still. Thus, Z=0Z=0 satisfies the condition.

On the other hand, if Z=3Z=3, then 11 and 22 keep moving to the left, and 33 keeps moving to the right, toward the attached weights for approximately 100100100100^{100^{100}} seconds. Thus, Z=3Z=3 does not satisfy the condition.

It turns out that Z=0Z=0 is the only value that satisfies the condition, so you should print 11.

3
7 1 2 3 4 5 6
2