#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10, mod = 1e9 + 7, inf = 2e9, lg = 22,
                maskm = (1 << lg) - 1, maxm = (1 << lg) + 7;
long long a[maxn], dp[maxm];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (int i = 1; i < maxm; i++) {
    for (int j = i; j && dp[i] == 0; j -= (j & -j)) {
      dp[i] = dp[i ^ (j & -j)];
    }
  }
  for (int i = 0; i < n; i++) {
    long long tmp = maskm ^ a[i];
    if (dp[tmp] == 0)
      cout << -1 << " ";
    else
      cout << dp[tmp] << " ";
  }
}
