#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, n, t = 1, k = 0, cnt = 0, mini = LLONG_MAX, maxi = LLONG_MIN,
                     ans = 0;
  long long m;
  map<pair<long long, long long>, long long> mm;
  cin >> n;
  vector<pair<long long, long long> > v;
  for (i = 0; i < n; i++) {
    cin >> j;
    mm[make_pair(j, i)] = 1;
  }
  auto it = mm.begin();
  while (it != mm.end()) {
    auto jt = it;
    auto u = (*jt).first.first;
    jt++;
    if (jt == mm.end()) {
      it++;
      continue;
    }
    auto v = (*jt).first.first;
    if (u != v) {
      it++;
    } else {
      mm[make_pair((*it).first.first, (*it).first.second)] = 0;
      mm[make_pair((*jt).first.first, (*jt).first.second)] = 0;
      mm[{(*jt).first.first * 2, (*jt).first.second}] = 1;
      it++, it++;
    }
  }
  for (auto kt : mm) {
    if (kt.second == 1) {
      v.push_back({kt.first.second, kt.first.first});
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << '\n';
  for (auto it : v) {
    cout << it.second << " ";
  }
  return 0;
}
