#include <bits/stdc++.h>
using namespace std;
struct Nodes {
  int val, id;
} p[1000010];
int ans[1000010];
int pos[1000010 * 5], mark[1000010 * 5];
bool cmp(Nodes p1, Nodes p2) { return p1.val < p2.val; }
int dfs(int now) {
  if (mark[now] != 0) return mark[now];
  mark[now] = -1;
  int j;
  for (j = 0; (1 << j) <= now; j++) {
    if ((1 << j) & now) {
      mark[now] = dfs(now - (1 << j));
      if (mark[now] != -1) return mark[now];
    }
  }
  return mark[now];
}
int main() {
  int i, j, k;
  int n, m;
  while (scanf("%d", &n) != EOF) {
    int maxx = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &p[i].val);
      p[i].id = i;
      ans[i] = -1;
      maxx = max(maxx, p[i].val);
    }
    for (i = 0; i <= maxx; i++) {
      mark[i] = 0;
    }
    k = 0;
    while ((1 << k) <= maxx) {
      k++;
    }
    m = (1 << k) - 1;
    for (i = 0; i <= m; i++) {
      mark[i] = 0;
    }
    sort(p + 1, p + n + 1, cmp);
    for (i = 1; i <= n; i++) {
      mark[p[i].val] = i;
    }
    mark[0] = -1;
    for (i = n; i >= 1; i--) {
      if (ans[p[i].id] != -1) continue;
      if (i < n && p[i].val == p[i + 1].val) {
        ans[p[i].id] = ans[p[i + 1].id];
        continue;
      }
      k = dfs(m - p[i].val);
      if (k != -1) {
        ans[p[i].id] = p[k].val;
        ans[p[k].id] = p[i].val;
      }
    }
    for (i = 1; i < n; i++) {
      printf("%d ", ans[i]);
    }
    printf("%d\n", ans[n]);
  }
  return 0;
}
