#C10849. Find the Number with an Odd Occurrence

    ID: 40099 Type: Default 1000ms 256MiB

Find the Number with an Odd Occurrence

Find the Number with an Odd Occurrence

You are given a list of integers in which all numbers except one appear an even number of times. Your task is to identify and output the number that occurs an odd number of times.

It is guaranteed that exactly one integer in the input will have an odd count.

Mathematically, if we denote the list by \(a_1, a_2, \ldots, a_n\), then there exists one \(x\) such that \[ \text{count}(x) \equiv 1 \pmod 2, \] while for every other element \(y\) in the list, we have \[ \text{count}(y) \equiv 0 \pmod 2. \]

This can be solved efficiently using the XOR operation.

inputFormat

The first line contains a single integer \(n\) which represents the number of elements in the array. The second line contains \(n\) space-separated integers.

Constraints:

  • \(1 \leq n \leq 10^5\)
  • Each integer is within the range \([-10^9, 10^9]\).

outputFormat

Output a single integer --- the number that appears an odd number of times.

## sample
7
1 2 3 1 2 3 2
2

</p>