#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> n[2];
vector<int> t;
vector<set<int>> ss;
void add(int a) {
  vector<int> d;
  for (int j = 0; (1 << j) <= a; j++) d.push_back(((1 << j) & a) ? 1 : 0);
  reverse(d.begin(), d.end());
  int c = 0;
  int num = 0;
  for (int i : d) {
    num *= 2;
    num += i;
    if (n[i][c] == 0) {
      n[i][c] = t.size();
      t.push_back(0);
      ss.push_back(set<int>());
      ss.back().insert(num);
      n[0].push_back(0);
      n[1].push_back(0);
    }
    c = n[i][c];
  }
  t[c] = 1;
}
void dp(int c) {
  if (c == 0) return;
  dp(n[0][c]);
  dp(n[1][c]);
  if (n[0][c] == 0 && n[1][c] == 0) return;
  auto &a = ss[n[0][c]];
  auto &b = ss[n[1][c]];
  t[c] += t[n[0][c]] + t[n[1][c]];
  if (a.size() > b.size()) swap(a, b);
  b.insert(*ss[c].begin());
  for (auto i = a.begin(); i != a.end(); i++) b.insert(*i);
  while (b.size() > t[c]) {
    auto i = b.end();
    i--;
    b.erase(i);
  }
  swap(ss[c], b);
  a.clear();
  b.clear();
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> N;
  t.push_back(0);
  n[0].push_back(0);
  n[1].push_back(0);
  ss.push_back(set<int>());
  for (int i = 0, j; i < N; i++) {
    cin >> j;
    add(j);
  }
  dp(1);
  int j = 0;
  for (int i : ss[1]) {
    cout << i << ' ';
    j++;
    if (j == N) break;
  }
  return 0;
}
