#include <bits/stdc++.h>
using namespace std;
const int mx = 1 << 22;
int n, a[mx + 1];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  memset(a, -1, sizeof a);
  cin >> n;
  vector<int> v(n);
  for (auto &i : v) cin >> i, a[i] = i;
  for (int i = 1; i <= mx; ++i)
    for (int j = 0; j < 22; ++j)
      if (i >> j & 1) a[i] = max(a[i], a[i ^ 1 << j]);
  for (auto i : v) cout << a[((1 << 22) - 1) ^ i] << " ";
  return 0;
}
