#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], c[1 << 22], ans[1 << 22];
int main() {
  memset(c, -1, sizeof(c));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    c[a[i]] = a[i];
  }
  for (int i = 0; i < 1 << 22; i++)
    if (c[i] == -1) {
      for (int j = 0; j < 22; j++)
        if (i & 1 << j && c[i ^ 1 << j] != -1) {
          c[i] = c[i ^ 1 << j];
          break;
        }
    }
  for (int i = 0; i < n; i++) printf("%d ", c[a[i] ^ ((1 << 22) - 1)]);
}
