#K86052. Equal XOR Partition
Equal XOR Partition
Equal XOR Partition
You are given an array of n integers. Your task is to determine if it is possible to partition the array into exactly two non-empty parts such that the XOR of the numbers in the first part is equal to the XOR of the numbers in the second part.
In other words, if we denote the two parts as A and B, find if there exists an index i (1 ≤ i < n) such that:
$$\bigoplus_{j=1}^{i} a_j = \bigoplus_{j=i+1}^{n} a_j $$where \(\bigoplus\) denotes the bitwise XOR operation.
It is guaranteed that the input will have at least 2 elements.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer n (2 ≤ n ≤ 105), the number of elements in the array.
- The second line contains n space-separated integers representing the array elements. Each element is between 0 and 109, inclusive.
outputFormat
Output to standard output (stdout) a single line containing YES
if it is possible to partition the array as described; otherwise, output NO
.
4
1 2 3 0
YES
</p>