Problems > The Lonely Number

The Lonely Number

Difficulty: 1200 3000 ms 128 MB

bitwise

Every value appears exactly twice, except one that appears once. Find it — ideally without extra memory.

Input: the first line has N (odd); the second line has N positive integers.

Output: the value that appears once.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ ai ≤ 106

Sample Tests

Input 1
5
2 3 5 3 2
Output 1
5
Input 2
1
42
Output 2
42

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.