#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = 1e9;
inline long long pwr(long long base, long long n, long long m) {
  long long ans = 1;
  while (n > 0) {
    if (n % 2 == 1) ans = (ans * base) % m;
    base = (base * base) % m;
    n /= 2;
  }
  return ans;
}
const int N = 1e6 + 10;
int a[N], n, dp[1 << 22];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (int i = 0; i < 22; i++) {
    for (int mask = 0; mask < 1 << 22; mask++) {
      if ((mask & (1 << i))) dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
    }
  }
  for (int i = 0; i < n; i++) {
    int temp = a[i];
    a[i] = (((1 << 22) - 1) ^ a[i]);
    if (!dp[a[i]]) dp[a[i]] = -1;
    cout << dp[a[i]] << " ";
  }
  return 0;
}
