#K36702. Find the Unique Number Appearing Once

    ID: 25813 Type: Default 1000ms 256MiB

Find the Unique Number Appearing Once

Find the Unique Number Appearing Once

You are given a list of n integers, where every number appears exactly three times except for one number which appears only once. Your task is to find and print that unique number.

In this problem, let \(a_1, a_2, \dots, a_n\) denote the input numbers. With the guarantee that every element except one appears exactly three times, you are to identify the element \(x\) such that:

\[ \text{count}(x)=1 \quad \text{and} \quad \text{count}(y)=3 \text{ for every } y \neq x. \]

The intended solution uses bitwise manipulation to achieve a linear time complexity and constant space complexity.

inputFormat

The input consists of two lines:

  1. The first line contains an integer n representing the number of elements in the array.
  2. The second line contains n space-separated integers. It is guaranteed that every integer appears exactly three times except for one integer that appears only once.

outputFormat

Output a single integer: the unique number which appears only once in the input array.

## sample
4
2 2 3 2
3

</p>