#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000001, max2 = 23;
long long n, a[maxn], mask[(1 << max2)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  memset(mask, -1, sizeof mask);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mask[a[i]] = a[i];
  }
  for (int i = 0; i < (1 << max2); i++) {
    if (mask[i] == -1) continue;
    for (int j = 0; j < max2; j++) {
      mask[i | (1 << j)] = mask[i];
    }
  }
  for (int i = 0; i < n; i++) {
    long long ans = mask[((~a[i]) & ((1 << 23) - 1))];
    cout << ans << " ";
  }
  cout << "\n";
}
