#B3908. Minimizing XOR Sum with an Extra Number
Minimizing XOR Sum with an Extra Number
Minimizing XOR Sum with an Extra Number
You are given (n) non-negative integers (a_1, a_2, \ldots, a_n). Your task is to determine a non-negative integer (x) such that the value of (a_1 \oplus a_2 \oplus \cdots \oplus a_n \oplus x) is minimized. Here, (\oplus) denotes the bitwise XOR operation.
Recall that for two non-negative integers (x) and (y), the XOR is computed in binary: for each bit, if the bits differ, the result is 1; if they are the same, the result is 0. For example, (0 \oplus 0 = 0), (1 \oplus 0 = 1), (0 \oplus 1 = 1), and (1 \oplus 1 = 0).
You need to output two numbers: the chosen (x) and the minimized value (a_1 \oplus a_2 \oplus \cdots \oplus a_n \oplus x).
inputFormat
The input consists of two lines. The first line contains a single integer (n) ((1 \leq n \leq 10^5)), representing the number of integers. The second line contains (n) non-negative integers (a_1, a_2, \ldots, a_n) separated by spaces. Each integer fits in a 32-bit unsigned integer.
outputFormat
Output two non-negative integers separated by a space. The first integer is the chosen (x) and the second integer is (a_1 \oplus a_2 \oplus \cdots \oplus a_n \oplus x).
sample
3
1 2 3
3 0