#C4909. Find the Unique Element

    ID: 48499 Type: Default 1000ms 256MiB

Find the Unique Element

Find the Unique Element

You are given an array of integers in which every element appears an even number of times except for one element that appears an odd number of times. Your task is to find and output this unique element.

The optimal solution makes use of the XOR operation. Recall that the XOR operator has the following properties:

\( a \oplus a = 0 \) and \( a \oplus 0 = a \). Thus, for a sequence where every number except one appears an even number of times, applying XOR over all numbers will cancel out the numbers with even frequency and leave the unique element.

Note: It is guaranteed that exactly one element appears an odd number of times.

inputFormat

The input is given on a single line. The first integer, \( n \), represents the number of elements in the array. This is followed by \( n \) space-separated integers, representing the elements of the array.

For example:

5 4 1 2 1 2

outputFormat

Output a single integer, which is the unique element that appears an odd number of times.

For the sample above, the output should be:

4
## sample
5 4 1 2 1 2
4