#include <bits/stdc++.h>
using namespace std;
long double PI = acosl(-1);
bool compare_int(int a, int b) { return (a > b); }
bool compare_string(string a, string b) { return a.size() < b.size(); }
bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second)
    return a.first < b.first;
  else
    return (a.second > b.second);
}
bool cmp(pair<string, int> x, pair<string, int> y) {
  return x.second < y.second;
}
int fx[9] = {0, 0, -1, 1, -1, -1, 1, 1};
int fy[9] = {-1, 1, 0, 0, -1, 1, -1, 1};
void NA() {
  cout << "NO" << endl;
  exit(0);
}
void YA() {
  cout << "YES" << endl;
  exit(0);
}
const int N = 5000006;
int idx[N], a[N], ans[N], n;
queue<int> q;
int check_bit(int mask, int k) { return ((mask >> k) & 1); }
int set_bit(int mask, int k) { return (mask | (1 << k)); }
void bfs() {
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 22; i++) {
      if (!check_bit(u, i)) {
        int x = set_bit(u, i);
        if (!idx[x]) {
          idx[x] = idx[u];
          q.push(x);
        }
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    idx[a[i]] = i;
    q.push(a[i]);
  }
  bfs();
  for (int i = 1; i <= n; i++) {
    int x = 0;
    for (int j = 21; j >= 0; j--) {
      if (check_bit(a[i], j))
        x *= 2;
      else
        x = 2 * x + 1;
    }
    if (idx[x] != 0)
      ans[i] = a[idx[x]];
    else
      ans[i] = -1;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
    i == n ? cout << endl : cout << ' ';
  }
}
