#include <bits/stdc++.h>
using namespace std;
int num[1000010], dp[4200000];
int main() {
  int n, i, j;
  memset(dp, -1, sizeof dp);
  scanf(" %d", &n);
  for (i = 1; i <= n; i++) {
    scanf(" %d", &num[i]);
    dp[num[i]] = num[i];
  }
  for (i = 0; i < (1 << 22); i++) {
    for (j = 0; j < 22; j++) dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i]);
  }
  for (i = 1; i <= n; i++) printf("%d ", dp[(1 << 22) - 1 - num[i]]);
  return 0;
}
