#include <bits/stdc++.h>
using namespace std;
long long p[150000];
bool ok[150000];
map<long long, set<long long> > ma;
map<long long, set<long long> >::iterator it;
set<long long>::iterator is;
int main() {
  int n, i, h, k = 0;
  bool flag = false;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", p + i);
    ma[p[i]].insert(i);
  }
  for (it = ma.begin(); it != ma.end(); it++) {
    h = 0;
    for (is = it->second.begin(), h = 0; is != it->second.end(); is++, h++) {
      if (h & 1) {
        ma[it->first << 1].insert(*is);
      }
    }
    if (it->second.size() & 1) {
      h = *it->second.rbegin();
      ok[h] = true;
      p[h] = it->first;
      k++;
    }
  }
  printf("%d\n", k);
  for (i = 0; i < n; i++) {
    if (ok[i]) {
      if (flag) printf(" ");
      printf("%lld", p[i]);
      flag = true;
    }
  }
  return 0;
}
