Problem list
Log in
#coci00697 · COCI 2024/2025 Contest 4

Xor

Gold IV 1.0 s 512 MB

Fran recently learned the operation xor, which for two integers $x$ and $y$ returns the result by applying the bitwise exclusive or (exclusive $or$). The operation xor, denoted as ⊕, compares the corresponding bits of the numbers $x$ and $y$ and sets the result bit at each position according to the following rule:

  • If the bits at the corresponding position are different (0 and 1, or 1 and 0), then the result bit is 1.
  • If the bits are the same (0 and 0, or 1 and 1), then the result bit is 0. For example, for $x = 5$ and $y = 3$, the binary representations are: $x = 101_{2}$, $y = 011_{2}$. Applying xor to the corresponding bits gives $x$ ⊕$y = 101_{2}$ ⊕$011_{2}$ = $110_{2}$ = 6. In other words, 5 ⊕$3 = 6$. Fran received an array of $n$ integers $a_{1}$, $a_{2}$, . . . , $a_{n}$ and decided to do the following:
  1. For every pair of indices (i, j) where $1 \le i \le j \le n$, he calculated the sum $a_{i} + a_{j}$.
  2. Now he wants to calculate the result of the xor of all the obtained sums. Help Fran calculate the required result.

Input

In the first line of input, there is $n$ ($1 \le n \le 5 \cdot 10^{5}$), the length of the array. In the second line, there are $n$ numbers $a_{1}$, $a_{2}$, . . . , $a_{n}$ ($0 \le a_{i} < 2^{30}$) as described in the problem statement.

Output

In the only line of output, print the required result.

Example 1

Input
3
2 4 5
Output
14

Example 2

Input
4
6 7 3 1
Output
3

Example 3

Input
7
2 3 5 7 9 11 13
Output
6

Clarification of the first example: The sums are 2 + 2 = 4, 2 + 4 = 6, 2 + 5 = 7, 4 + 4 = 8, 4 + 5 = 9, and 5 + 5 = 10. The result is 4 ⊕6 ⊕7 ⊕8 ⊕9 ⊕10 = 14.

Source
COCI 2024/2025 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code