#K44272. Find the Unique Element

    ID: 27495 Type: Default 1000ms 256MiB

Find the Unique Element

Find the Unique Element

Given a list of integers in which every element appears exactly twice except for one unique element, your task is to identify and print this unique element. The problem can be solved efficiently using the XOR operation. Recall that for any integers (a) and (b), the XOR operation satisfies (a \oplus a = 0) and (a \oplus 0 = a). Thus, performing XOR on all elements results in the unique number.

Example: For the input list [4, 1, 2, 1, 2], the unique element is 4.

inputFormat

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

  • The first line contains a single integer (n) representing the number of elements in the list.
  • The second line contains (n) space-separated integers where every integer appears exactly twice except one unique integer that appears once.

outputFormat

Output the unique element (the integer that appears only once) to standard output (stdout).## sample

5
4 1 2 1 2
4