#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
map<long long, set<long long> > mp;
set<long long> s;
vector<pair<long long, long long> > ans;
int N;
long long num;
int main(void) {
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num;
    mp[num].insert(i);
    if (mp[num].size() > 1) s.insert(num);
  }
  while (!s.empty()) {
    set<long long>::iterator it = s.begin();
    mp[(*it)].erase(mp[(*it)].begin());
    mp[(*it) << 1].insert((*mp[(*it)].begin()));
    mp[(*it)].erase(mp[(*it)].begin());
    if (mp[(*it) << 1].size() > 1) s.insert((*it) << 1);
    if (mp[(*it)].size() < 2) s.erase((*it));
  }
  for (map<long long, set<long long> >::iterator it = mp.begin();
       it != mp.end(); it++) {
    if ((*it).second.size() > 0) {
      ans.push_back(make_pair(*(*it).second.begin(), (*it).first));
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (vector<pair<long long, long long> >::iterator it = ans.begin();
       it != ans.end(); it++)
    cout << (*it).second << " ";
  cout << endl;
  return 0;
}
