#include <bits/stdc++.h>
using namespace std;
const int N = 5e6;
int idx[N], a[N];
string binary(int x) {
  string s = "";
  for (int k = 0; k < 4; k++) {
    s += x % 2 + '0';
    x /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  int n;
  cin >> n;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    q.push(a[i]);
    idx[a[i]] = i;
  }
  while ((int)q.size()) {
    int x = q.front();
    q.pop();
    for (int k = 0; k < 22; k++) {
      if ((x >> k) & 1) {
        continue;
      }
      int t = x | (1 << k);
      if (!idx[t]) {
        idx[t] = idx[x];
        q.push(t);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int flipped = 0;
    for (int k = 21; k >= 0; k--) {
      if ((a[i] >> k) & 1) {
        flipped *= 2;
      } else {
        flipped = 2 * flipped + 1;
      }
    }
    if (!idx[flipped]) {
      printf("-1 ");
    } else {
      printf("%d ", a[idx[flipped]]);
    }
  }
}
