#include <bits/stdc++.h>
using namespace std;
long long a[200200], b[200200];
set<pair<long long, long long> > s;
set<pair<long long, long long> >::iterator it, it2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i], s.insert({a[i], i});
  for (it = s.begin(); it != s.end();) {
    it2 = it;
    it2++;
    if (it2 == s.end()) break;
    if ((*it).first == (*it2).first) {
      s.insert({(*it).first * 2, (*it2).second});
      s.erase(it2);
      it2 = it;
      it++;
      s.erase(it2);
    } else
      it++;
  }
  for (auto x : s) {
    b[x.second] = x.first;
  }
  cout << s.size() << endl;
  for (i = 0; i < n; i++) {
    if (b[i]) cout << b[i] << " ";
  }
}
