#include <bits/stdc++.h>
using namespace std;
const int M = 22;
int ans[(1 << M) - 1];
void initValue(int* arr, int n, int val) {
  for (int i = 0; i < n; i++) {
    arr[i] = val;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n;
  cin >> n;
  int* arr = new int[n];
  initValue(ans, (1 << M), -1);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    ans[arr[i]] = arr[i];
  }
  for (int mask = 0; mask < (1 << M); mask++) {
    if (ans[mask] != (-1)) continue;
    for (int i = 0; i < 22; i++) {
      if ((mask & (1 << i)) && ans[mask ^ (1 << i)] != (-1))
        ans[mask] = ans[mask ^ (1 << i)];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[arr[i] ^ ((1 << M) - 1)] << " ";
  }
  cout << endl;
  delete[] arr;
  return 0;
}
