#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long val[200005];
  map<long long int, set<int> > my;
  set<long long int> s;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
    my[val[i]].insert(i);
    if (my[val[i]].size() > 1) s.insert(val[i]);
  }
  while (!s.empty()) {
    auto it = s.begin();
    long long int value = *it;
    my[value].erase(my[value].begin());
    int fi = *(my[value].begin());
    my[value].erase(my[value].begin());
    if (my[value].size() < 2) s.erase(it);
    value *= 2;
    my[value].insert(fi);
    if (my[value].size() == 2) s.insert(value);
  }
  int m = 0;
  long long int num[200005] = {0};
  for (auto it = my.begin(); it != my.end(); it++) {
    if ((it->second).size() == 1) {
      num[*((it->second).begin())] = it->first;
      m++;
    }
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) {
    if (num[i]) printf("%lld ", num[i]);
  }
  return 0;
}
