#include <bits/stdc++.h>
using namespace std;
int a[1000005], mask[1 << 22] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> a[i];
  for (int i = 0; i <= n - 1; i++) {
    mask[a[i]] = a[i];
  }
  for (int i = 0; i <= (1 << 22) - 1; i++) {
    for (int j = 0; j <= 22; j++) {
      if (i & (1 << j)) {
        if (mask[i - (1 << j)] > 0) {
          mask[i] = mask[i - (1 << j)];
        }
      }
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    if (mask[(1 << 22) - 1 - a[i]])
      cout << mask[(1 << 22) - 1 - a[i]];
    else
      cout << "-1";
    cout << " ";
  }
  return 0;
}
