#include <bits/stdc++.h>
using namespace std;
long long int ans[150100];
int main() {
  int n;
  map<long long int, set<long long int> > mp;
  set<long long int> st;
  scanf("%d", &n);
  for (long long int i = 0, x; i < n; ++i) {
    scanf("%I64d", &x);
    mp[x].insert(i);
  }
  for (auto it = mp.begin(); it != mp.end(); ++it)
    if (it->second.size() > 1) st.insert(it->first);
  while (!st.empty()) {
    long long int mn = *st.begin();
    set<long long int> &idx = mp[mn];
    idx.erase(idx.begin());
    mp[2 * mn].insert(*idx.begin());
    idx.erase(idx.begin());
    if (idx.size() < 2) st.erase(mn);
    if (mp[2 * mn].size() == 2) st.insert(2 * mn);
  }
  for (auto it = mp.begin(); it != mp.end(); ++it)
    for (int idx : it->second) ans[idx] = it->first;
  int q = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i]) ans[q++] = ans[i];
  }
  printf("%d\n%I64d", q, ans[0]);
  for (int i = 1; i < q; ++i) printf(" %I64d", ans[i]);
  printf("\n");
  return 0;
}
