#include <bits/stdc++.h>
using namespace std;
const int LOG = 22;
const int Mask = (1 << 22) - 1;
int f[1 << LOG];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  memset(f, -1, sizeof(f));
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    cin >> a[i];
    f[a[i]] = a[i];
  }
  for (int(m) = 0; (m) < (int)(1 << LOG); ++(m)) {
    if (!~f[m]) {
      for (int i = m; i > 0; i &= i - 1) {
        if (~f[m ^ (i & -i)]) {
          f[m] = f[m ^ (i & -i)];
          break;
        }
      }
    }
  }
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    cout << (f[Mask ^ a[i]]) << ' ';
  }
  cout << '\n';
}
