#include <bits/stdc++.h>
using namespace std;
const int MAX = (1 << 22) - 1;
const int MAXN = (int)1e6 + 100;
bool F[MAX + 100];
int val[MAX + 100];
int arr[MAXN + 100];
int n;
int main() {
  ostringstream os;
  for (int i = 0; i <= MAX; i++) {
    F[i] = 0;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    F[arr[i]] = 1;
    val[arr[i]] = arr[i];
  }
  for (int i = 0; i < 22; i++) {
    for (int msk = 0; msk < MAX; msk++) {
      if (msk & (1 << i)) {
        if (F[msk ^ (1 << i)]) {
          F[msk] = 1;
          val[msk] = val[msk ^ (1 << i)];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int cmpl = ~arr[i];
    cmpl &= MAX;
    int ans = -1;
    if (F[cmpl]) {
      ans = val[cmpl];
    }
    printf("%d ", ans);
  }
  return 0;
}
