#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 7;
int N, a[maxN], f[(1LL << 22) + 7];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  memset(f, -1, sizeof f);
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    f[a[i]] = a[i];
  }
  for (int i = 0; i <= 22; i++)
    for (int mask = 0; mask < (1LL << 22); mask++)
      if (mask & (1LL << i)) f[mask] = max(f[mask], f[mask ^ (1LL << i)]);
  for (int i = 1; i <= N; i++) {
    cout << f[(1LL << 22) - 1 - a[i]] << " ";
  }
  return 0;
}
