#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long int mod = 1e9 + 7;
const long long int maxn = 5 * 100001;
long long int power(long long int x, long long int n) {
  long long int res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}
long long int dp[1 << 22 + 1] = {0}, x[1 << 22 + 1] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    memset(dp, 0, sizeof(dp));
    for (long long int i = 0; i < n; i++)
      cin >> a[i], dp[a[i]]++, x[a[i]] = a[i];
    for (long long int i = 0; i < 22; i++) {
      for (long long int mask = 0; mask < (1 << 22); mask++) {
        if ((mask >> i) & 1) {
          dp[mask] += dp[mask ^ (1 << i)];
          if (x[mask] == 0) x[mask] = x[mask ^ (1 << i)];
        }
      }
    }
    for (long long int i = 0; i < n; i++)
      if (dp[((1 << 22) - 1) - a[i]]) {
        cout << x[((1 << 22) - 1) - a[i]] << " ";
      } else {
        cout << "-1 ";
      }
  }
}
