#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int>> q;
vector<pair<long long, int>> ans;
map<long long, int> cnt;
bool cmp(pair<long long, int> a, pair<long long, int> b) {
  return a.second < b.second;
}
int main() {
  int nsize = 0;
  scanf("%d", &nsize);
  int i = 0;
  while (i < nsize) {
    long long number = 0;
    scanf("%lld", &number);
    q.push(make_pair(-number, -i));
    cnt[number]++;
    i++;
  }
  while (!q.empty()) {
    pair<long long, int> cur = q.top();
    q.pop();
    if (cnt[-cur.first] <= 1) {
      ans.push_back(make_pair(-cur.first, -cur.second));
    } else {
      pair<long long, int> cur2 = q.top();
      q.pop();
      cnt[-cur.first] -= 2;
      cnt[-cur.first * 2]++;
      q.push(make_pair(cur.first * 2, cur2.second));
    }
  }
  sort(ans.begin(), ans.end(), cmp);
  printf("%d\n", ans.size());
  i = 0;
  while (i < ans.size()) {
    printf("%lld ", ans[i].first);
    i++;
  }
  printf("\n");
  return 0;
}
