#include <bits/stdc++.h>
using namespace std;
inline void upmax(int &x, int b) {
  if (b > x) x = b;
}
inline void upmin(int &x, int b) {
  if (b < x) x = b;
}
inline void read(int &x) {
  x = 0;
  char c = getchar();
  for (; c < '0' || '9' < c; c = getchar())
    ;
  for (; '0' <= c && c <= '9'; c = getchar()) x = 10 * x + c - '0';
}
const int M = 4194303;
int n;
int f[4500005];
int a[2000005];
int main() {
  for (int i = 0; i < M + 1; ++i) f[i] = -1;
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= n; ++i) f[a[i] ^ M] = a[i];
  for (int i = M; i >= 0; --i)
    if (f[i] == -1)
      for (int j = 0; j < 22; ++j)
        if ((i & (1 << j)) == 0)
          if (f[i | (1 << j)] != -1) {
            f[i] = f[i | (1 << j)];
            break;
          }
  for (int i = 1; i <= n; ++i) printf("%d ", f[a[i]]);
  printf("\n");
  return 0;
}
