#P5514. Minimizing XOR Group Sum

    ID: 18746 Type: Default 1000ms 256MiB

Minimizing XOR Group Sum

Minimizing XOR Group Sum

You are given n non-negative integers \(a_1, a_2, \dots, a_n\). You need to partition these numbers into one or more groups such that each number belongs to exactly one group and every group contains at least one number.

The weight of a group is defined as the bitwise XOR of all the numbers in that group. In other words, for a group \(G\), its weight is:

\[ w(G)=\bigoplus_{a_i\in G}a_i, \]

Your task is to find a partitioning scheme that minimizes the sum of the weights of all groups. In fact, it can be shown that the minimum total weight is always equal to the XOR of all the numbers, i.e.,

\[ \min\,\text{Total Weight} = a_1 \oplus a_2 \oplus \cdots \oplus a_n. \]

Output the minimum possible total weight.

Note: Although there might be several partitioning schemes achieving the minimum total weight, you only need to output the minimum value.

inputFormat

The first line of input contains an integer n (1 ≤ n ≤ 10^5), which is the number of integers. The second line contains n non-negative integers a1, a2, ..., an separated by spaces.

outputFormat

Output a single integer representing the minimum total weight, which is (a_1 \oplus a_2 \oplus \cdots \oplus a_n).

sample

2
1 1
0

</p>