#include <bits/stdc++.h>
const long long int mod = 1000000000 + 7;
const long long int INF = 9000000000000000000;
using namespace std;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
long long int gcd(long long int a, long long int b) {
  return (a == 0 ? b : gcd(b % a, a));
}
long long int lcm(long long int a, long long int b) {
  return (a * b / (gcd(a, b)));
}
long long int add(long long int a, long long int b, long long int c = 0) {
  return ((a % mod + b % mod) % mod + c % mod) % mod;
}
long long int mul(long long int a, long long int b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long int sub(long long int a, long long int b) {
  return (a % mod - b % mod + mod) % mod;
}
void print(vector<long long int>& ans) {
  for (auto x : ans) cout << x << " ";
  cout << endl;
}
void print(long long int a) { cout << a << endl; }
long long int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long int n, w, h, d, k, m, mx, timer, realans, cc, start, queries,
    startindex;
void solve() {
  cin >> n;
  vector<long long int> arr(n + 1);
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  long long int mask = (1 << 22) - 1;
  vector<long long int> dp(mask + 5, -1);
  for (long long int i = 1; i <= n; i++) {
    dp[arr[i]] = arr[i];
  }
  long long int T = 22;
  for (long long int j = 0; j < (1 << T); j++) {
    for (long long int i = 0; i < T; i++) {
      if (dp[j] != -1 || (j & (1 << i)) == 0) {
        continue;
      }
      dp[j] = dp[j ^ (1 << i)];
    }
  }
  for (long long int i = 1; i <= n; i++) {
    long long int num = ((~arr[i]) & mask);
    cout << dp[num] << " ";
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int tests = 1;
  while (tests--) {
    solve();
  }
  return 0;
}
