#include <bits/stdc++.h>
using namespace std;
bool check(long long mid, vector<pair<long long, long long>> &hold,
           long long n) {
  long long siz = 0;
  for (long long i = 0; i < hold.size(); i++) {
    if (hold[i].first > mid) break;
    siz++;
  }
  if (siz < n) return 0;
  unordered_map<long long, long long> ma, ma1;
  for (long long i = siz - 1; i > -1; i--) {
    if (ma[hold[i].first] > 0) continue;
    if (ma1[hold[i].second] != 0) continue;
    ma[hold[i].first] = 1;
    ma1[hold[i].second] = 1;
    if (ma1.size() == n) break;
  }
  if (ma1.size() == n) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  vector<pair<long long, long long>> hold;
  for (long long i = 0; i < n; i++) {
    long long num = arr[i];
    while (num > 0) {
      hold.push_back(make_pair(num, i));
      num >>= 1;
    }
  }
  sort(hold.begin(), hold.end());
  long long maxi = *max_element(arr, arr + n);
  long long start = 0;
  long long end = hold.size() - 1;
  long long mid;
  while (end - start > 1) {
    mid = start + ((end - start) >> 1);
    bool temp = check(hold[mid].first, hold, n);
    if (temp)
      end = mid;
    else
      start = mid + 1;
  }
  long long ansi = -1;
  bool temp = check(hold[start].first, hold, n);
  if (temp)
    ansi = start;
  else
    ansi = end;
  ansi = hold[ansi].first;
  long long siz = 0;
  for (long long i = 0; i < hold.size(); i++) {
    if (hold[i].first > ansi) break;
    siz++;
  }
  unordered_map<long long, long long> ma, ma1;
  for (long long i = siz - 1; i > -1; i--) {
    if (ma[hold[i].first] > 0) continue;
    if (ma1[hold[i].second] != 0) continue;
    ma[hold[i].first] = 1;
    ma1[hold[i].second] = hold[i].first;
    if (ma1.size() == n) break;
  }
  for (long long i = 0; i < n; i++) cout << ma1[i] << " ";
  return 0;
}
