#K54737. Find the Unique Element

    ID: 29820 Type: Default 1000ms 256MiB

Find the Unique Element

Find the Unique Element

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

The problem can be solved efficiently using the bitwise XOR operation. Recall that the XOR operation (\(\oplus\)) has the following properties:

  • \(a \oplus a = 0\)
  • \(a \oplus 0 = a\)
  • The XOR operation is both associative and commutative.

Using the above properties, if you XOR all the elements in the list, the duplicates will cancel out and the result will be the unique number. For example, given the list [1, 2, 3, 2, 1], the unique element is 3 because:

[ 1 \oplus 2 \oplus 3 \oplus 2 \oplus 1 = (1 \oplus 1) \oplus (2 \oplus 2) \oplus 3 = 0 \oplus 0 \oplus 3 = 3 ]

Read the input from standard input and output the result to standard output.

inputFormat

The first line contains an integer \(n\) representing the total number of elements in the list. The second line contains \(n\) space-separated integers.

It is guaranteed that every element appears exactly twice except one element which appears exactly once.

outputFormat

Output a single integer which is the unique element from the list.

## sample
1
1
1