#include <bits/stdc++.h>
using namespace std;
int a[1 << 20], b[1 << 22];
int d = (1 << 22) - 1, p;
void dfs(int k, int *b) {
  if (k == 1) return;
  k /= 2;
  dfs(k, b);
  dfs(k, b + k);
  for (int i = 0; i < k; ++i) b[i + k] = max(b[i + k], b[i]);
}
int main() {
  memset(b, -1, sizeof(b));
  int n, i;
  cin >> n;
  for (i = 0; i < n; ++i) {
    scanf("%d", &p);
    a[i] = p;
    b[p] = p;
  }
  dfs(1 << 22, b);
  for (i = 0; i < n; ++i) a[i] = b[d ^ a[i]];
  printf("%d", a[0]);
  for (i = 1; i < n; ++i) printf(" %d", a[i]);
  printf("\n");
  return 0;
}
