All problems

Problem 479

Single Number III

Medium · 20 pts · Array, Bit Manipulation

Problem

Every element of the array appears exactly twice, except for two different elements that appear once each. Find those two elements and print them in increasing order. XOR-ing everything gives a ^ b, where a and b are the two singles; any set bit of that value differs between a and b, so splitting the numbers by that bit separates them into two groups, each containing one single.

Input

First line: N. Second line: N integers.

Output

Print the two single elements in increasing order, separated by a space.

Constraints

2 <= N <= 30000; -2147483648 <= A[i] <= 2147483647

Example input

6
1 2 1 3 2 5

Example output

3 5

Explanation

In 1 2 1 3 2 5, the values 1 and 2 appear twice, and 3 and 5 appear once. In increasing order the answer is 3 5.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Single Number II Next: Sum of All Subset XOR Totals