#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int bits = 0, maxi = *max_element(A.begin(), A.end());
  while ((1 << bits) < maxi) bits++;
  vector<int> z(1 << bits, -1);
  for (int i = 0; i < N; i++) z[A[i]] = A[i];
  for (int bit = 0; bit < bits; bit++) {
    for (int mask = 0; mask < (1 << bits); mask++)
      if (mask & (1 << bit) && z[mask] == -1) z[mask] = z[mask ^ (1 << bit)];
  }
  for (int i = 0; i < N; i++) cout << z[~A[i] & ((1 << bits) - 1)] << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  while (T--) solve();
  return 0;
}
