#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int dp[(1 << 22) + 1];
int go(int id) {
  if (dp[id] != -1) return dp[id];
  int result = 0;
  int mult = 1;
  for (int i = 0; i < 22; i++) {
    if ((id >> i) % 2 == 1) result = max(result, go(id - mult));
    mult *= 2;
  }
  dp[id] = result;
  return result;
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  memset(dp, -1, sizeof(int) * ((1 << 22) + 1));
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[arr[i]] = arr[i];
  }
  int maxI = ((1 << 22) - 1);
  for (int i = 0; i < n; i++) {
    int v = go(arr[i] ^ maxI);
    if (v == 0)
      cout << "-1";
    else
      cout << v;
    if (i == n - 1)
      cout << '\n';
    else
      cout << " ";
  }
}
