#K58522. Find the Unpaired Element
Find the Unpaired Element
Find the Unpaired Element
Given a list of integers in which every element appears an even number of times except for one that appears an odd number of times, your task is to identify that unpaired element.
The solution should work by reading input from stdin
and writing the result to stdout
. In particular, the first line of input contains an integer n representing the number of elements, and the second line contains n space-separated integers.
You can use the property of the bitwise XOR operator: \(a \oplus a = 0\) and \(a \oplus 0 = a\). Thus, by XOR-ing all values, the paired elements cancel out, leaving the unpaired element as the result.
inputFormat
The input is given via stdin
:
- The first line contains a single integer n, the number of elements in the array.
- The second line contains n space-separated integers.
outputFormat
Print a single integer — the element that appears an odd number of times.
## sample1
5
5
</p>