#include <bits/stdc++.h>
using namespace std;
int n, x, i;
map<long long, deque<long long> > mp;
vector<pair<long long, long long> > v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (i < n) cin >> x, mp[x].push_back(i++);
  for (auto it : mp) {
    sort(mp[it.first].begin(), mp[it.first].end());
    while (mp[it.first].size() >= 2) {
      mp[it.first].pop_front();
      mp[it.first * 2].push_back(mp[it.first][0]);
      mp[it.first].pop_front();
    }
    if (mp[it.first].size()) v.push_back({mp[it.first][0], it.first});
  }
  sort(v.begin(), v.end());
  cout << v.size() << '\n';
  for (auto it : v) cout << it.second << ' ';
  return 0;
}
