#include <bits/stdc++.h>
using namespace std;
int arr[1000005], ans[5000005];
int main() {
  memset(ans, -1, sizeof(ans));
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]), ans[arr[i]] = arr[i];
  for (int S = 1; S <= (1 << 22) - 1; S++) {
    if (ans[S] == -1) continue;
    for (int i = 0; i <= 21; i++) {
      if ((((1 << i) & S) == 0) && (S | (1 << i)) < (1 << 22))
        ans[S | (1 << i)] = ans[S];
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[arr[i] ^ ((1 << 22) - 1)]);
  return 0;
}
