#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int K = 23;
int n, a[N], f[(1 << K)], val[(1 << K)];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    f[a[i]]++;
    val[a[i]] = a[i];
  }
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < (1 << K); j++)
      if (j >> i & 1)
        f[j] += f[(j ^ (1 << i))], val[j] = max(val[j], val[j ^ (1 << i)]);
  }
  int foo = (1 << K) - 1;
  for (int i = 0; i < n; i++) {
    if (f[(a[i] ^ foo)])
      printf("%d ", val[(a[i] ^ foo)]);
    else
      printf("-1 ");
  }
  return 0;
}
