#include <bits/stdc++.h>   using std::pair;   using std::vector;   vector<int64_t> ReadInput(std::istream& in_stream = std::cin);   void WriteAnswer(size_t min, size_t max, std::ostream& out_stream = std::cout);   pair<size_t, size_t> GetRange(const vector<int64_t>& input);   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     auto input = ReadInput();     auto result = GetRange(input);     WriteAnswer(result.first, result.second);     return 0;   }   vector<int64_t> Power2();   pair<vector<size_t>, vector<size_t>> ChainsExtra(const vector<int64_t>& input);   template <class Integral, class Functional, class Check>   Integral BinSearch(Integral left, Integral right, Functional func, Check check);   pair<size_t, size_t> GetRange(const vector<int64_t>& input) {     auto chains_extra = ChainsExtra(input);     vector<size_t> chains = std::move(chains_extra.first);     vector<size_t> extra = std::move(chains_extra.second);     size_t sum_chains = 0, sum_extra = 0;     for (size_t i = chains.size(); i > 0;          --i, sum_chains += chains[i], sum_extra += extra[i]) {       if (sum_extra > sum_chains) {         return {1, 0};       }     }     if (sum_extra > sum_chains) {       return {1, 0};     }     size_t min = sum_chains, max = sum_chains;     for (size_t i = 0; i < chains.size(); ++i) {       if (min - chains[i] >= sum_extra + chains[i] * i) {         min -= chains[i];         sum_extra += chains[i] * i;       } else {         auto enouht = [min, &chains, sum_extra, sum_chains, i](size_t remove) {           return min - remove >= sum_extra + remove * i;         };         auto diff = [](size_t l, size_t r) { return r <= l + 1; };         min -= BinSearch(size_t(0), chains[i], enouht, diff);         break;       }     }     return {min, max};   }   template <class Integral, class Functional, class Check>   Integral BinSearch(Integral left, Integral right, Functional func, Check check);   pair<vector<size_t>, vector<size_t>> ChainsExtra(const vector<int64_t>& input) {     vector<int64_t> pow2 = Power2();     vector<size_t> count_pow2(pow2.size(), 0);     vector<size_t> extra(pow2.size(), 0);     auto diff = [](size_t l, size_t r) { return r <= l + 1; };     for (auto elem : input) {       size_t pos = BinSearch(           size_t(0), pow2.size(),           [&pow2, elem](size_t pos) { return pow2[pos] <= elem; }, diff);       if (elem == pow2[pos]) {         ++count_pow2[pos];       } else {         ++extra[pos + 1];       }     }     auto get_last = [&count_pow2]() {       for (int i = 0; i < count_pow2.size(); ++i) {         if (count_pow2[i] == 0) {           return i;         }       }       return static_cast<int>(count_pow2.size());     };     vector<size_t> chains(pow2.size(), 0);     while (get_last() != 0) {       auto pos = get_last();       auto chains_count =           *std::min_element(count_pow2.begin(), count_pow2.begin() + pos);       chains[pos] = chains_count;       std::for_each(count_pow2.begin(), count_pow2.begin() + pos,                     [chains_count](size_t& count) { count -= chains_count; });     }     for (size_t i = 0; i < pow2.size(); ++i) {       extra[i] += count_pow2[i];     }     return {chains, extra};   }   template <class Integral, class Functional, class Check>   Integral BinSearch(Integral left, Integral right, Functional func,                      Check check) {     auto dir = func(left);     while (!check(left, right)) {       Integral mid = (left + right) / 2;       if (func(mid) == dir) {         left = mid;       } else {         right = mid;       }     }     return left;   }   vector<int64_t> Power2() {     std::vector<int64_t> power2{1};     while (power2.back() < 1ll * 2000 * 1000 * 1000 * 1000) {       power2.push_back(power2.back() * 2);     }     return power2;   }   void WriteAnswer(size_t min, size_t max, std::ostream& out_stream) {     if (min > max) {       out_stream << -1;       return;     }     for (size_t i = min; i <= max; ++i) {       std::cout << i <<    ;     }   }   vector<int64_t> ReadInput(std::istream& in_stream) {     size_t input_size;     in_stream >> input_size;     vector<int64_t> input(input_size);     for (auto& elem : input) {       in_stream >> elem;     }     return input;   }