#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
char __buf[1 << 20], *__p1, *__p2;
int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
const int maxn = 5e6 + 10;
int n, f[maxn], mx, a[maxn], pw[100];
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) mx = max(mx, a[i] = read()), f[a[i]] = a[i];
  int c;
  pw[0] = 1;
  for (c = 1; (pw[c] = pw[c - 1] << 1) <= mx; c++)
    ;
  for (int i = 0; i < pw[c]; i++) {
    for (int j = 0; j < c; j++)
      if (i >> j & 1 && f[i ^ pw[j]]) {
        f[i] = f[i ^ pw[j]];
        break;
      }
  }
  for (int i = 1, x; i <= n; i++) {
    x = (pw[c] - 1) ^ a[i];
    if (!f[x])
      cout << -1 << ' ';
    else
      cout << f[x] << ' ';
  }
  return 0;
}
