#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAX = 4000010;
const long long MOD = (int)1e9 + 7;
const int INF = 1e9;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-8;
vector<int> ind[(1 << 22) + 1];
int res[(1 << 22) + 1];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  memset(res, -1, sizeof(res));
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < (int)n; i++) {
    cin >> v[i];
    ind[v[i]].push_back(i);
  }
  int m20 = 0;
  for (int i = 0; i < 22; i++) {
    m20 ^= (1 << i);
  }
  for (int i = 0; i < (1 << 22); i++) {
    res[i] = (ind[i].size() ? i : -1);
  }
  for (int i = 0; i < 22; ++i) {
    for (int mask = 0; mask < (1 << 22); mask++) {
      if (mask & (1 << i)) res[mask] = max(res[mask], res[mask ^ (1 << i)]);
    }
  }
  for (int i = 0; i < (int)n; i++) {
    int m = v[i];
    int notm = ~m & (m20);
    cout << res[notm] << " ";
  }
  cout << '\n';
  return 0;
}
