#include <bits/stdc++.h>
using namespace std;
vector<int> G;
int y[50005], n;
int ans[50005];
set<pair<int, int> > Act;
set<pair<int, int> >::iterator it;
inline void fillact(int v) {
  Act.clear();
  for (int i = 0; i < n; ++i) {
    int x = y[i];
    while (x > v) x >>= 1;
    Act.insert(make_pair(x, i));
  }
}
bool Generate(int maxm, int sz) {
  if (sz == 0) return 1;
  it = Act.end();
  --it;
  while (!Act.empty() && it->first > maxm) {
    Act.insert(make_pair((it->first) / 2, it->second));
    Act.erase(it);
    it = Act.end();
    --it;
  }
  it = Act.end();
  --it;
  if (it->first > maxm || it->first == 0) return 0;
  pair<int, int> P = *it;
  ans[P.second] = P.first;
  Act.erase(it);
  return Generate(P.first - 1, sz - 1);
}
bool isvalid(int maxm, int sz) {
  while (1) {
    if (sz == 0) return 1;
    it = Act.end();
    --it;
    while (!Act.empty() && it->first > maxm) {
      Act.insert(make_pair((it->first) / 2, it->second));
      Act.erase(it);
      it = Act.end();
      --it;
    }
    it = Act.end();
    --it;
    if (it->first > maxm || it->first == 0) return 0;
    pair<int, int> P = *it;
    Act.erase(it);
    maxm = P.first - 1;
    sz -= 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &y[i]);
  for (int i = 0; i < n; ++i) {
    int a = y[i];
    while (a) {
      G.push_back(a);
      a = a / 2;
    }
  }
  sort(G.begin(), G.end());
  int val = 1000000007, mid, low = 0, high = G.size() - 1;
  while (low <= high) {
    mid = (low + high) / 2;
    fillact(G[mid]);
    if (isvalid(G[mid], n)) {
      val = min(val, G[mid]);
      high = mid - 1;
    } else
      low = mid + 1;
  }
  fillact(val);
  Generate(val, n);
  for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
  return 0;
}
