#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int a[1000010];
long long int F[(1 << 22) + 10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    F[a[i]] = a[i];
  }
  for (long long int i = 0; i < 22; ++i) {
    for (long long int mask = 0; mask < (1 << 22); ++mask) {
      if (mask & (1 << i)) F[mask] = max(F[mask], F[mask ^ (1 << i)]);
    }
  }
  for (long long int i = 0; i < n; ++i) {
    long long int op = (~a[i]) & ((1 << 22) - 1);
    if (F[op])
      cout << F[op];
    else
      cout << -1;
    cout << ' ';
  }
  cout << endl;
}
