#include <bits/stdc++.h>
using namespace std;
int n, dp[(1 << 22)];
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    dp[arr[i]] = arr[i];
  }
  for (int i = 1; i < (1 << 22); i++) {
    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[arr[i] ^ ((1 << 22) - 1)] << " ";
  }
  cout << endl;
  return 0;
}
