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