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