#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (register int i = (0); i < (n); i++) cin >> a[i];
  set<pair<long long int, int>> S;
  set<pair<long long int, int>> U;
  stack<pair<long long int, int>> stk;
  for (register int i = (0); i < (n); i++) {
    S.insert({a[i], i});
  }
  auto it = S.begin();
  pair<long long int, int> p;
  while (it != S.end()) {
    p = *it;
    if (stk.empty()) {
      stk.push(p);
    } else if (stk.top().first == p.first) {
      int index = p.second;
      long long int val = 2 * p.first;
      stk.pop();
      S.insert({val, index});
    } else {
      U.insert(stk.top());
      stk.pop();
      stk.push(p);
    }
    it = S.erase(it);
  }
  if (not stk.empty()) U.insert(stk.top());
  vector<long long int> _res(n);
  for (auto p : U) {
    _res[p.second] = p.first;
  }
  vector<long long int> res;
  for (register int i = (0); i < (n); i++) {
    if (_res[i] > 0) res.push_back(_res[i]);
  }
  cout << res.size() << "\n";
  for (auto u : res) cout << u << " ";
  return 0;
}
