#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 41;
const int mod = 1e9 + 7;
const long long INF = 2e18;
const int inf = 1e9;
int dp[(1 << 25)], a[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (int i = 0; i < 24; ++i) {
    for (int j = 0; j < (1 << 24); ++j) {
      if (!(j & (1 << i)) && dp[j]) {
        dp[j ^ (1 << i)] = dp[j];
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    int val = dp[a[i] ^ ((1 << 24) - 1)];
    if (!val) val -= 1;
    cout << val << " ";
  }
}
