#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  std::vector<long long> v(n);
  multiset<pair<long long, long long> > m;
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
    m.insert({v[i], i});
  }
  multiset<pair<long long, long long> > ans;
  while (m.size() > 1) {
    auto it1 = m.begin();
    auto it2 = it1;
    ++it2;
    if (it2 == m.end()) break;
    if (it1->first != it2->first) {
      ans.insert(*it1);
      m.erase(it1);
    } else {
      m.insert({it2->first * 2, it2->second});
      m.erase(it1);
      m.erase(it2);
    }
  }
  std::vector<long long> fnl(n, -1);
  for (auto it : m) {
    fnl[it.second] = it.first;
  }
  for (auto it : ans) {
    fnl[it.second] = it.first;
  }
  cout << ans.size() + m.size() << endl;
  for (long long i = 0; i < n; ++i) {
    if (fnl[i] != -1) cout << fnl[i] << " ";
  }
  cout << endl;
  return 0;
}
