#include <bits/stdc++.h>
using namespace std;
const int CCC = 1 << 22;
int d[CCC], A[CCC];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(d, -1, sizeof(d));
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
    d[(CCC - 1) ^ A[i]] = A[i];
  }
  for (int i = CCC - 1; i >= 0; --i)
    if (d[i] == -1) {
      for (int j = 0; j < 22; ++j)
        if (!(i & (1 << j)) && d[i ^ (1 << j)] != -1) {
          d[i] = d[i ^ (1 << j)];
          break;
        }
    }
  for (int i = 1; i <= n; ++i) cout << d[A[i]] << " ";
}
