#include <bits/stdc++.h>   using namespace std;   const int ALL = (1 << 30) - 1;   int ans[(1 << 22) + 10];   int a[int(1e6) + 2];   int n;   void add(int x, int val) {     if (ans[x] != 0) return;     ans[x] = val;     for (int i = 0; i < 22; ++i) add(x & (ALL - (1 << i)), val);   }   void task() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = 0; j < 22; ++j)         if (!(a[i] & (1 << j))) x += 1 << j;       add(x, a[i]);     }     for (int i = 0; i < n; ++i) printf( %d  , ans[a[i]] ? ans[a[i]] : -1);   }   int main() {     task();     return 0;   }   