#include <bits/stdc++.h>
using namespace std;
bool dp[1 << 22];
int parent[1 << 22];
int a[1000010];
int compatible(int x) {
  if (parent[x] == -1) return x;
  return compatible(parent[x]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < n; ++i) {
    dp[a[i]] = 1;
    parent[a[i]] = -1;
  }
  int N = 1 << 22;
  for (int mask = 0; mask < N; ++mask)
    if (dp[mask]) {
      for (int i = 0; i < 22; ++i)
        if (!((mask >> i) & 1) && !dp[mask | (1 << i)]) {
          dp[mask | (1 << i)] = 1;
          parent[mask | (1 << i)] = mask;
        }
    }
  for (int i = 0; i < n; ++i) {
    if (i) cout << ' ';
    int x = ~a[i] & ((1 << 22) - 1);
    if (!dp[x])
      cout << -1;
    else
      cout << compatible(x);
  }
  cout << endl;
  return 0;
}
