#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 1e9;
const int B = 22;
int a[maxn];
int f[(1 << B)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < (1 << B); i++) f[i] = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[a[i]] = a[i];
  }
  for (int b = B - 1; b >= 0; b--) {
    for (int msk = (1 << B) - 1; msk >= 0; msk--) {
      if (msk & (1 << b)) f[msk] = max(f[msk], f[msk ^ (1 << b)]);
    }
  }
  for (int i = 1; i <= n; i++) {
    int msk = 0;
    for (int b = 0; b < B; b++) {
      if (a[i] & (1 << b)) continue;
      msk |= (1 << b);
    }
    cout << f[msk] << " ";
    if (f[msk] == -1) continue;
    assert((a[i] & f[msk]) == 0);
  }
  cout << '\n';
  return 0;
}
