#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k = 1 << 22;
  int n, p;
  cin >> n;
  vector<int> v(k, -1);
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v[a[i]] = a[i];
  }
  for (int i = 0; i < 22; i++)
    for (int mask = k - 1; mask >= 0; mask--) {
      if (mask & 1 << i) {
        p = mask ^ (1 << i);
        if (v[p] >= 0) v[mask] = v[p];
      }
    }
  for (int i = 0; i < n; i++) cout << v[k - 1 - a[i]] << " ";
  cout << endl;
}
