#C3529. Find the Single Occurrence
Find the Single Occurrence
Find the Single Occurrence
You are given a list of integers in which every element appears exactly twice except for one element that appears only once. Your task is to find and output the element that appears only once.
The problem can be solved efficiently using the bitwise XOR operator, denoted as \(\oplus\). The essential property which makes our solution work is that for any integer \(x\), \(x \oplus x = 0\) and \(x \oplus 0 = x\). Applying XOR cumulatively over the list will cancel out the numbers that appear in pairs, leaving the unique number.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) \((2k+1)\) representing the total number of integers.
- The second line contains \(n\) space-separated integers. It is guaranteed that every integer except one appears exactly twice.
outputFormat
Output the integer that appears only once on standard output (stdout).
## sample5
2 3 2 3 4
4