#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll a[150009];
map<ll, vector<int> > ma;
vector<ll> ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    ma[a[i]].push_back(i);
  }
  auto it = ma.begin();
  for (; it != ma.end(); ++it) {
    sort(it->second.begin(), it->second.end());
    for (int i = 1; i < it->second.size(); i += 2) {
      a[it->second[i - 1]] = 0;
      a[it->second[i]] = it->first + it->first;
      ma[it->first + it->first].push_back(it->second[i]);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (a[i]) ans.push_back(a[i]);
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%lld%c", ans[i], " \n"[i == ans.size() - 1]);
  }
  return 0;
}
