#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> ans(n);
  vector<long long> sos_dp(1 << 22, -1);
  for (long long i = 0; i < n; i++) sos_dp[a[i]] = i;
  for (long long i = 0; i < 22; i++) {
    for (long long ma = 0; ma < (1 << 22); ma++) {
      if (ma & (1 << i)) {
        if (sos_dp[ma] == -1) sos_dp[ma] = sos_dp[ma ^ (1 << i)];
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    long long num = a[i];
    long long mask = (1 << 22) - 1 - num;
    ans[i] = (sos_dp[mask] == -1 ? -1 : a[sos_dp[mask]]);
  }
  for (auto i : ans) cout << i << " ";
}
