#include <bits/stdc++.h>
using namespace std;
map<long long, set<long long> > mp;
set<pair<long long, long long> > ss;
int main() {
  int n;
  long long a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    mp[a].insert(i);
  }
  while (mp.size()) {
    auto it = *mp.begin();
    mp.erase(mp.begin());
    while (it.second.size() >= 2) {
      it.second.erase(it.second.begin());
      mp[2 * it.first].insert(*it.second.begin());
      it.second.erase(it.second.begin());
    }
    if (it.second.size() == 1)
      ss.insert(make_pair(*it.second.begin(), it.first));
  }
  printf("%d\n", ss.size());
  for (set<pair<long long, long long> >::iterator it = ss.begin();
       it != ss.end(); it++)
    printf("%lld ", it->second);
  return 0;
}
