#include <bits/stdc++.h>
using namespace std;
int arr[1000001], dp[(1 << 22)], N;
int main() {
  scanf("%d", &N);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
    dp[arr[i]] = arr[i];
  }
  for (int i = 0; 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++) {
    int need = dp[((1 << 22) - 1) ^ arr[i]];
    printf("%d%c", need, i == N - 1 ? '\n' : ' ');
  }
  return 0;
}
