#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<pair<long long, int> > s;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    s.insert({x, i});
  }
  vector<pair<long long, int> > tmp;
  auto ans = [&]() {
    cout << tmp.size() << endl;
    sort(tmp.begin(), tmp.end(),
         [&](pair<long long, int> l, pair<long long, int> r) -> bool {
           return l.second < r.second;
         });
    for (auto x : tmp) cout << x.first << " ";
  };
  for (;;) {
    if (s.size() == 1) {
      tmp.push_back(*s.begin());
      break;
    }
    auto beg = s.begin();
    pair<long long, int> fi = *beg;
    beg++;
    pair<long long, int> se = *beg;
    if (fi.first == se.first) {
      s.erase(s.begin());
      s.erase(s.begin());
      se.first *= 2;
      s.insert(se);
    } else {
      s.erase(s.begin());
      tmp.push_back(fi);
    }
  }
  ans();
  return 0;
}
