#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long int a[150001];
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  unordered_map<long long int, int> dir;
  for (int i = 0; i < n; i++) {
    unordered_map<long long int, int>::iterator it = dir.find(a[i]);
    while (it != dir.end()) {
      a[i] *= 2;
      a[it->second] = -1;
      dir.erase(it);
      it = dir.find(a[i]);
    }
    dir.insert(make_pair(a[i], i));
  }
  int cnt = 0;
  long long int ans[150001];
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) continue;
    ans[cnt++] = a[i];
  }
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++) printf("%lld ", ans[i]);
  printf("\n");
}
