#include <bits/stdc++.h>
using namespace std;
set<pair<long long int, long long int> > s;
set<pair<long long int, long long int> >::iterator it1, it2, it3;
vector<pair<long long int, long long int> > v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t, n, m, q, i, j, k, x, y, z;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    s.insert(make_pair(x, i));
  }
  it2 = s.begin();
  it1 = it2;
  it2++;
  while (it1 != s.end() && it2 != s.end()) {
    if ((*it1).first == (*it2).first) {
      x = (*it1).first;
      y = (*it2).second;
      s.insert(make_pair(2 * x, y));
      it3 = it2;
      it3++;
      s.erase(it1);
      s.erase(it2);
      it2 = it3;
    }
    it1 = it2;
    it2++;
  }
  it1 = s.begin();
  while (it1 != s.end()) {
    v.push_back(make_pair(it1->second, it1->first));
    it1++;
  }
  sort(v.begin(), v.end());
  cout << v.size() << "\n";
  for (i = 0; i < v.size(); i++) {
    cout << v[i].second << " ";
  }
}
