#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   struct item {     int key, prior;     item *left, *right;     item() {}     item(int key, int prior) : key(key), prior(prior), left(NULL), right(NULL) {}   };   typedef item* pitem;   void split(pitem temp, int key, pitem& left, pitem& right) {     if (!temp)       left = right = NULL;     else if (key < temp->key)       split(temp->left, key, left, temp->left), right = temp;     else       split(temp->right, key, temp->right, right), left = temp;   }   void insert(pitem& temp, pitem it) {     if (!temp)       temp = it;     else if (it->prior > temp->prior)       split(temp, it->key, it->left, it->right), temp = it;     else       insert(it->key < temp->key ? temp->left : temp->right, it);   }   void merge(pitem& temp, pitem left, pitem right) {     if (!left || !right)       temp = left ? left : right;     else if (left->prior > right->prior)       merge(left->right, left->right, right), temp = left;     else       merge(right->left, left, right->left), temp = right;   }   void erase(pitem& temp, int key) {     if (temp->key == key)       merge(temp, temp->left, temp->right);     else       erase(key < temp->key ? temp->left : temp->right, key);   }   pitem unite(pitem left, pitem right) {     if (!left || !right) return left ? left : right;     if (left->prior < right->prior) swap(left, right);     pitem lt, rt;     split(right, left->key, lt, rt);     left->left = unite(left->left, lt);     left->right = unite(left->right, rt);     return left;   }   int getMin(pitem temp) {     while (temp->left) temp = temp->left;     return temp->key;   }   pitem eraseMin(pitem temp) {     int minn = getMin(temp);     erase(temp, minn);     return temp;   }   void dfs(pitem temp) {     ans.push_back(temp->key);     if (temp->left) dfs(temp->left);     if (temp->right) dfs(temp->right);   }   long long mass[200000];   vector<int> mass1[200000];   unordered_map<int, bool> prefs;   int n;   bool f(long long m, bool fin) {     if (fin) {       for (int i = 0; i < n; i++) {         int now = 0;         int last = -1;         for (int u = mass1[i].size() - 1; u > -1; u--) {           now *= 2;           now += mass1[i][u];           if (prefs[now] == 0 && now <= m) last = now;         }         cout << last <<    ;         prefs[last] = 1;       }       return 0;     } else       for (int i = 0; i < n; i++) {         int now = 0;         int last = -1;         for (int u = mass1[i].size() - 1; u > -1; u--) {           now *= 2;           now += mass1[i][u];           if (now > m) break;           if (prefs[now] == 0) last = now;         }         if (last == -1)           return 0;         else           prefs[last] = 1;       }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> mass[i];     sort(mass, mass + n);     reverse(mass, mass + n);     for (int i = 0; i < n; i++) {       long long a = mass[i];       while (a) {         mass1[i].push_back(a % 2);         a /= 2;       }     }     long long l = 1, r = 1e9;     for (int b = 0; b < 30; b++) {       prefs.clear();       long long mid = (l + r) / 2;       if (f(mid, 0))         r = mid;       else         l = mid;     }     prefs.clear();     f(r, 1);     return 0;   }