#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 23;
const int N = 22;
int dp[1 << 23];
int a[1 << 23];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  fill(dp, dp + maxN, -1);
  for (int i = 0; i < n; i++) cin >> a[i], dp[a[i]] = a[i];
  for (int i = 0; i < (1 << 22); i++) {
    if (dp[i] == -1)
      for (int j = 0; j < 22; j++)
        if (i & (1 << j)) dp[i] = max(dp[i], dp[i ^ (1 << j)]);
  }
  for (int i = 0; i < n; i++) cout << dp[a[i] ^ (maxN / 2 - 1)] << " ";
}
