#include <bits/stdc++.h>
using namespace std;
int N = 600005;
vector<int> bit;
void update(int x, int val) {
  for (; x < N; x += x & (-x)) {
    bit[x] += val;
  }
}
int query(int x) {
  int res = 0;
  for (; x > 0; x -= x & (-x)) {
    res += bit[x];
  }
  return res;
}
int main() {
  int LG = 22;
  int N = (1 << LG);
  int n, k, q;
  cin >> n;
  vector<int> v(n), dp(N, -1);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    dp[v[i]] = v[i];
  }
  for (int i = 0; i < N; ++i) {
    if (dp[i] == -1) continue;
    for (int j = 0; j < LG; ++j) {
      if (((1 << j) & i) == 0) {
        dp[i + (1 << j)] = dp[i];
      }
    }
  }
  for (auto p : v) {
    cout << dp[N - 1 - p] << " ";
  }
  cout << endl;
  return 0;
}
