#include <bits/stdc++.h>
const int maxm = 1000005, maxn = 22, maxk = 1 << maxn;
int n;
int a[maxm];
struct poly {
  int len;
  int s[maxk];
} A;
inline int max(int a, int b) { return a > b ? a : b; }
int getlen(int x) {
  int res = 1;
  for (; res < x; res <<= 1)
    ;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < maxk; i++) A.s[i] = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    A.s[a[i]] = a[i];
  }
  for (int len = 2, now = 1; len <= maxk; len <<= 1, now <<= 1)
    for (int i = 0; i < maxk; i += len)
      for (int j = 0; j < now; j++)
        A.s[i + j + now] = max(A.s[i + j + now], A.s[i + j]);
  for (int i = 1; i <= n; i++)
    printf("%d%c", A.s[((1 << 22) - 1) ^ a[i]], i == n ? '\n' : ' ');
  return 0;
}
