#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 1000002;
const int VAL_MAX = 4194305;
const int BITS = 22;
int n;
int a[N_MAX];
int dp[VAL_MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (int i = 1; i < (1 << BITS); i <<= 1)
    for (int j = i; j < (1 << BITS); j = ((j + 1) | i))
      dp[j] = max(dp[j], dp[j ^ i]);
  for (int i = 1; i <= n; i++) cout << dp[((1 << BITS) - 1) ^ a[i]] << " ";
  cout << "\n";
  return 0;
}
