atcoder#ARC152E. [ARC152E] Xor Annihilation
[ARC152E] Xor Annihilation
Score : points
Problem Statement
On a number line, there are balls at the coordinates , and the ball at has a weight of . Here, is a permutation of the integers from through . You will choose a non-negative integer at most and attach a weight of at each of the coordinates . Then, the balls will simultaneously start moving as follows.
- At each time, let be the total of the weights of the balls and attached weights that are strictly to the right of the coordinate of a ball, and be the total of the weights of the balls and attached weights that are strictly to the left. If , the ball moves to the right at a speed of per second; if , the ball moves to the left at a speed of per second; if , 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 of their former weights.
For how many values of will all balls come to rest within 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.
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
- if .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
2
1 2 3
1
Let us call a ball with a weight of simply .
If , for instance, and first move to the right, and moves to the left. Then, the moment and collide and combine into one ball, it starts moving to the left. Afterward, the moment all balls from to combine into one ball, it stands still. Thus, satisfies the condition.
On the other hand, if , then and keep moving to the left, and keeps moving to the right, toward the attached weights for approximately seconds. Thus, does not satisfy the condition.
It turns out that is the only value that satisfies the condition, so you should print .
3
7 1 2 3 4 5 6
2