#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int> >,
               greater<pair<long long int, long long int> > >
    heap;
pair<long long int, long long int> tp, tmp;
vector<pair<long long int, long long int> > v;
map<long long int, int> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (!mp[a])
      mp[a] = 1;
    else
      mp[a]++;
    tmp.first = a;
    tmp.second = i;
    heap.push(tmp);
  }
  while (!heap.empty()) {
    tp = heap.top();
    if (mp[tp.first] > 1) {
      heap.pop();
      tmp.first = 2 * tp.first;
      mp[tmp.first]++;
      mp[tp.first] -= 2;
      tmp.second = heap.top().second;
      heap.push(tmp);
      heap.pop();
    } else {
      tmp.first = tp.second;
      tmp.second = tp.first;
      v.push_back(tmp);
      heap.pop();
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << endl;
  for (i = 0; i < v.size(); i++) cout << v[i].second << " ";
  return 0;
}
