#include <bits/stdc++.h>
using namespace std;
int n, a[1000001], d[1 << 22], lim;
int len(int x) {
  int dem = 0;
  while (x) {
    x >>= 1;
    dem++;
  }
  return dem;
}
void nhap() {
  scanf("%d", &n);
  memset(d, -1, sizeof(d));
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    lim = max(lim, len(a[i]));
    d[a[i]] = a[i];
  }
}
int get_bit(int st, int i) { return ((st >> i) & 1); }
int rev(int st) {
  int kq = 0;
  for (int i = 0; i < lim; ++i)
    if (!get_bit(st, i)) kq |= (1 << i);
  return kq;
}
void process() {
  for (int i = 0; i < lim; ++i) {
    for (int st = 1; st < (1 << lim) - 1; ++st) {
      if (get_bit(st, i)) d[st] = max(d[st], d[st ^ (1 << i)]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << d[rev(a[i])] << " ";
  }
}
int main() {
  nhap();
  process();
  return 0;
}
