#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long &e : a) cin >> e;
  set<pair<long long, long long>> s;
  for (long long i = 0; i < n; i++) s.insert({a[i], i});
  long long bef = -1;
  for (auto it = s.begin(); it != s.end();) {
    if (bef == it->first) {
      it--;
      it = s.erase(it);
      s.insert({bef * 2, it->second});
      it = s.erase(it);
      bef = -1;
    } else
      bef = (it++)->first;
  }
  vector<pair<long long, long long>> ans(s.size());
  int ai = 0;
  for (auto it = s.begin(); it != s.end(); it++, ai++)
    ans[ai] = {it->second, it->first};
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (auto p : ans) cout << p.second << " ";
  cin >> n;
}
