Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

E. Compatible Numbers

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputTwo integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* & *b* = 0. For example, numbers 90 (1011010_{2}) and 36 (100100_{2}) are compatible, as 1011010_{2} & 100100_{2} = 0_{2}, and numbers 3 (11_{2}) and 6 (110_{2}) are not compatible, as 11_{2} & 110_{2} = 10_{2}.

You are given an array of integers *a*_{1}, *a*_{2}, ..., *a*_{n}. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.

Input

The first line contains an integer *n* (1 ≤ *n* ≤ 10^{6}) — the number of elements in the given array. The second line contains *n* space-separated integers *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 4·10^{6}) — the elements of the given array. The numbers in the array can coincide.

Output

Print *n* integers *ans*_{i}. If *a*_{i} isn't compatible with any other element of the given array *a*_{1}, *a*_{2}, ..., *a*_{n}, then *ans*_{i} should be equal to -1. Otherwise *ans*_{i} is any such number, that *a*_{i} & *ans*_{i} = 0, and also *ans*_{i} occurs in the array *a*_{1}, *a*_{2}, ..., *a*_{n}.

Examples

Input

2

90 36

Output

36 90

Input

4

3 6 3 6

Output

-1 -1 -1 -1

Input

5

10 6 9 8 2

Output

-1 8 2 2 8

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/20/2020 07:57:01 (e1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|