#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    qu;
vector<pair<long long, int> > re;
bool cmp(pair<long long, int> a, pair<long long, int> b) {
  return a.second < b.second;
}
int main() {
  int n;
  cin >> n;
  long long x;
  pair<long long, int> now, next;
  for (int i = 0; i < n; i++) {
    cin >> x;
    qu.push(pair<long long, int>(x, i));
  }
  while (!qu.empty()) {
    now = qu.top();
    qu.pop();
    if (!qu.empty()) {
      next = qu.top();
      if (now.first == next.first) {
        qu.pop();
        next.first *= 2;
        qu.push(next);
        continue;
      }
    }
    re.push_back(now);
  }
  sort(re.begin(), re.end(), cmp);
  cout << re.size() << endl;
  vector<pair<long long, int> >::iterator it = re.begin();
  for (; it != re.end(); it++) cout << it->first << ' ';
}
