Let's call two numbers similar if their binary representations contain the same number of digits equal to 1. For example:
You are given an array of n integers a1, a2, ..., an. You may choose a non-negative integer x, and then get another array of n integers b1, b2, ..., bn, where bi=ai⊕x (⊕ denotes bitwise XOR).
Is it possible to obtain an array b where all numbers are similar to each other?
The first line contains one integer n (2≤n≤100).
The second line contains n integers a1, a2, ..., an (0≤ai≤230−1).
If it is impossible to choose x so that all elements in the resulting array are similar to each other, print one integer −1.
Otherwise, print any non-negative integer not exceeding 230−1 that can be used as x so that all elements in the resulting array are similar.
2 7 2
1
4 3 17 6 0
5
3 1 2 3
-1
3 43 12 12
1073709057
Name |
---|