#K92367. Find the Single Element

    ID: 38182 Type: Default 1000ms 256MiB

Find the Single Element

Find the Single Element

Given a list of integers where every element appears exactly twice except for one unique integer, your task is to find and output that unique element. The key observation is the inherent property of the bitwise XOR operation:

$$a\oplus a = 0 \quad \text{and} \quad a\oplus 0 = a$$

By performing XOR on all the numbers, all elements that appear twice will cancel out, leaving only the unique element. This approach runs in linear time with constant extra space.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains a single integer n, which denotes the number of integers in the list.
  • The second line contains n space-separated integers.

outputFormat

Output a single integer to stdout—the unique integer that appears only once in the list.

## sample
5
2 3 2 4 4
3

</p>