#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int n, f[1 << 22];
int a[1000010];
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; ++i) f[a[i]] = a[i];
  for (int i = 0; i < 22; ++i) {
    for (int mask = (1 << 22) - 1; mask >= 0; --mask)
      if ((mask >> i & 1) && f[mask] == -1) f[mask] = f[mask ^ (1 << i)];
  }
  for (int i = 1; i <= n; ++i) cout << f[((1 << 22) - 1) ^ a[i]] << " ";
}
