#include <bits/stdc++.h>
using namespace std;
int length(int p) {
  int count = 0;
  while (p) {
    p = p >> 1;
    count++;
  }
  return count;
}
int main() {
  int n, i, j, maxi = INT_MIN, mbit;
  scanf(" %d", &n);
  vector<int> arr(1000000, 0);
  vector<int> dp(1 << 22, -1);
  for (i = 0; i < n; i++) {
    scanf(" %d", &arr[i]);
    dp[arr[i]] = arr[i];
    if (arr[i] > maxi) maxi = arr[i];
  }
  mbit = length(maxi);
  for (i = 0; i < mbit; i++) {
    for (j = 0; j < (1 << mbit); j++) {
      if (j & (1 << i)) {
        if (dp[j] == -1) {
          dp[j] = dp[j ^ (1 << i) & ((1 << mbit) - 1)];
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    int x = arr[i] ^ ((int)pow(2, mbit) - 1);
    printf("%d ", dp[x]);
  }
}
