Codeforces Round 112 (Div. 2)
E
Compatible Numbers
Codeforces
2200
原题
← D→
翻译中…

Two 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*}$.

翻译中…

样例

Input #1
2
90 36
Output #1
36 90
InputCopy OutputCopy
Input #2
4
3 6 3 6
Output #2
-1 -1 -1 -1
InputCopy OutputCopy
Input #3
5
10 6 9 8 2
Output #3
-1 8 2 2 8
InputCopy OutputCopy
题目信息
题号
165E
时间限制
4 s
内存限制
256 MB
标签
位运算
暴力
DFS 及类似
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。