#include <bits/stdc++.h>
using namespace std;
const int N = (1LL << 22) + 1;
int n;
int a[N], ans[N][2];
bool vis[N][2], present[N];
int dfs(int k, int cur) {
  if (vis[k][cur]) return ans[k][cur];
  vis[k][cur] = 1;
  if (cur == 1) return ans[k][cur] = dfs(k, 0);
  for (int i = 0; i < 22; i++) {
    if ((k & (1LL << i)) == 0)
      ans[k][cur] = max(ans[k][cur], dfs(k | (1 << i), cur));
  }
  if (present[((1 << 22) - 1) ^ k])
    ans[k][cur] = max(ans[k][cur], ((1 << 22) - 1) ^ k);
  return ans[k][cur];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(ans, -1, sizeof(ans));
  cin >> n;
  for (int i = 0; i < (1 << 22); i++) {
    vis[i][1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    vis[a[i]][1] = 0;
    present[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    cout << dfs(a[i], 1) << " ";
  }
  return 0;
}
