#C11486. Unique Number Finder

    ID: 40807 Type: Default 1000ms 256MiB

Unique Number Finder

Unique Number Finder

You are given a non-empty list of integers in which every element appears exactly twice except for one unique element that appears only once. Your task is to identify and output this unique element.

Hint: A linear time and constant space solution is possible using the bitwise XOR operation. Using the identity a \oplus a = 0 and a \oplus 0 = a, XOR-ing all the numbers together will cancel out the duplicate numbers, leaving the unique element.

Problem Details:

  • The input consists of an integer n (representing the number of elements) followed by a list of n space-separated integers.
  • Each integer, except one, appears exactly twice in the list.
  • It is guaranteed that n is odd.

inputFormat

The first line of input is an integer n (1 ≤ n ≤ 105), representing the number of elements in the list. The second line contains n space-separated integers. It is guaranteed that n is odd and every element except one appears exactly twice.

outputFormat

Output a single integer, the unique number that appears exactly once in the input list.

## sample
3
2 2 1
1