#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << (23);
int f[maxn];
int a[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  memset(f, -1, sizeof f);
  for (int i = 0; i < n; ++i) {
    int &b = a[i];
    cin >> b;
    f[b] = b;
  }
  for (int i = 0; i < 22; ++i) {
    for (int mask = 0; mask < maxn; mask++) {
      if (mask & (1 << i)) {
        f[mask] = max(f[mask], f[mask ^ (1 << i)]);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    int cms = 0;
    int &v = a[i];
    for (int j = 0; j < 22; ++j) {
      if (v & (1 << j)) {
        continue;
      } else {
        cms |= (1 << j);
      }
    }
    cout << f[cms] << ' ';
  }
}
