#include <bits/stdc++.h>
using namespace std;
const int N = 32 - __builtin_clz(int(4e6));
const int Mm = (1 << N) - 1;
int ans[Mm + 1];
void solve() {
  int n;
  cin >> n;
  int a[n];
  memset(ans, -1, sizeof(ans));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans[Mm ^ a[i]] = a[i];
  }
  for (int m = Mm; ~m; --m) {
    if (~ans[m]) {
      for (int i = 0; i < N; ++i) {
        ans[m & (~(1 << i) & Mm)] = ans[m];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[a[i]] << " \n"[i + 1 == n];
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cout.precision(12);
  solve();
}
