#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long INF = 1e18;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long fastexp(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result *= x;
    x *= x;
    n = n / 2;
  }
  return result;
}
long long modularExp(long long x, long long n, long long mod) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return (result) % mod;
}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
bool mycomp(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
void solve() {
  long long n;
  cin >> n;
  long long bits = 22;
  long long maxn = (1 << bits);
  vector<long long> v(n);
  long long i, j;
  for (i = 0; i < n; i++) cin >> v[i];
  vector<long long> dp(1 << bits, -1);
  for (i = 0; i < n; i++) dp[v[i]] = v[i];
  for (j = 0; j < bits; j++)
    for (i = 0; i < (1 << bits); i++)
      if (~dp[i]) dp[i | (1 << j)] = dp[i];
  for (i = 0; i < n; i++) {
    cout << dp[~v[i] & (maxn - 1)] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
