#include <bits/stdc++.h>
using namespace std;
const long long MX = (1 << 22) + 5;
long long f[MX], ans[MX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long a[n];
  memset(ans, -1, sizeof(ans));
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
    ans[a[i]] = a[i];
  }
  for (long long i = 0; i < 22; i++) {
    for (long long j = 0; j < (1 << 22); j++) {
      if ((j >> i) & 1) {
        f[j] += f[j ^ (1 << i)];
        ans[j] = max(ans[j], ans[j ^ (1 << i)]);
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << ans[((1 << 22) - 1) ^ a[i]] << " ";
  }
  cout << '\n';
}
