#include <bits/stdc++.h>
using namespace std;
const long long mx = (1 << 22);
long long f[mx], ans[mx];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(ans, -1, sizeof(ans));
  for (long long i = 0; i < n; i++) {
    f[a[i]]++;
    ans[a[i]] = a[i];
  }
  for (long long j = 0; j < 22; j++)
    for (long long i = 0; i < mx; i++)
      if (i & (1 << j)) {
        f[i] += f[i ^ (1 << j)];
        if (f[i ^ (1 << j)]) ans[i] = ans[i ^ (1 << j)];
      }
  for (long long i = 0; i < n; i++) {
    long long p = (mx - 1) & (~a[i]);
    cout << ans[p] << " ";
  }
  cout << '\n';
}
