#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000, Log = 22, maxs = 1 << Log;
int n, a[maxn + 5], f[maxs];
inline char readc() {
  static char buf[100000], *l = buf, *r = buf;
  if (l == r) r = (l = buf) + fread(buf, 1, 100000, stdin);
  if (l == r)
    return EOF;
  else
    return *l++;
}
inline int readi(int &x) {
  int tot = 0, f = 1;
  char ch = readc(), lst = '+';
  while (!isdigit(ch)) {
    if (ch == EOF) return EOF;
    lst = ch;
    ch = readc();
  }
  if (lst == '-') f = -f;
  while (isdigit(ch)) tot = tot * 10 + ch - 48, ch = readc();
  return x = tot * f, ((ch) == 10 || (ch) == 13 || (ch) == EOF);
}
int main() {
  readi(n);
  memset(f, 255, sizeof(f));
  for (int i = 1; i <= n; i++) readi(a[i]), f[a[i] ^ (maxs - 1)] = a[i];
  for (int i = 0; i < Log; i++)
    for (int s = 0; s < maxs; s++)
      if (!(s & (1 << i)))
        if (~f[s | (1 << i)]) f[s] = f[s | (1 << i)];
  for (int i = 1; i <= n; i++)
    if (i == 1)
      printf("%d", f[a[i]]);
    else
      printf(" %d", f[a[i]]);
  return putchar('\n'), 0;
}
