#include <bits/stdc++.h>
using namespace std;
int have[(1 << 22)], a[1000005], n, cur;
void f(int a, int b) {
  if (have[a] != -1) return;
  have[a] = b;
  for (int i = 0; i < 22; i++)
    if (!(a & (1 << i))) f(a | (1 << i), b);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << 22); i++) have[i] = -1;
  for (int i = 0; i < n; i++) scanf("%d", &cur), f(cur, cur), a[i] = cur;
  for (int i = 0; i < n; i++)
    printf("%d%c", have[a[i] ^ ((1 << 22) - 1)], (i + 1 < n)["\n "]);
  return 0;
}
