#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 23) - 1;
int n, a[N], bits = 22, mem[N];
int dp(int mask) {
  int &ret = mem[mask];
  if (ret != -1) {
    return ret;
  }
  ret = -2;
  for (int i = 0; i < bits; i++) {
    if (mask & (1 << i)) {
      ret = max(ret, dp(mask - (1 << i)));
    }
  }
  return ret;
}
int get(int x) {
  int mask = (((1 << 22) - 1) - x);
  int ret = dp(mask);
  if (ret == -2) {
    return -1;
  }
  return ret;
}
int main() {
  memset(mem, -1, sizeof mem);
  scanf("%d", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mem[a[i]] = a[i];
  }
  for (int i = 0; i < (1 << bits); i += 1024) {
    dp(i);
  }
  for (long long i = 1; i <= n; i++) {
    int ans = get(a[i]);
    printf("%d ", ans);
  }
}
