#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Node {
  long long val;
  int pos;
};
map<long long, vector<int> > m;
map<long long, vector<int> >::iterator it;
vector<Node> v;
bool cmp(Node x, Node y) { return x.pos < y.pos; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    m[x].push_back(i);
  }
  for (it = m.begin(); it != m.end(); it++) {
    if ((it->second).size() == 1) {
      Node t;
      t.pos = (it->second)[0];
      t.val = it->first;
      v.push_back(t);
      continue;
    }
    sort((it->second).begin(), (it->second).end());
    for (int i = 1; i < it->second.size(); i += 2) {
      m[it->first * 2].push_back((it->second)[i]);
    }
    if ((it->second.size()) & 1) {
      Node t;
      t.pos = (it->second)[it->second.size() - 1];
      t.val = it->first;
      v.push_back(t);
    }
  }
  sort(v.begin(), v.end(), cmp);
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++) {
    printf("%lld", v[i].val);
    if (i != v.size() - 1)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
