#include <bits/stdc++.h>
using namespace std;
long long n, a, pertama, kedua, sum;
vector<pair<long long, int> > v;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    pq;
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second < b.second;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    pq.push(make_pair(a, i));
  }
  while (!pq.empty()) {
    pertama = pq.top().first;
    kedua = pq.top().second;
    pq.pop();
    if (pertama == pq.top().first) {
      pq.push(make_pair(2 * pertama, pq.top().second));
      pq.pop();
    } else {
      v.push_back(make_pair(pertama, kedua));
    }
    if (pq.empty()) v.push_back(make_pair(pertama, kedua));
  }
  sort(v.begin(), v.end(), cmp);
  sum = v.size();
  cout << sum << endl;
  for (int i = 0; i < sum; i++) {
    if (i != 0) cout << " ";
    cout << v[i].first;
  }
  cout << endl;
}
