#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  unordered_map<long long int, set<long long int> > loc;
  set<long long int> s;
  for (long long int i = 0; i < n; i++) cin >> a[i], loc[a[i]].insert(i);
  for (auto x : loc) {
    if (x.second.size() > 1) s.insert(x.first);
  }
  while (!s.empty()) {
    long long int ele = *s.begin();
    loc[ele].erase(*(loc[ele].begin()));
    long long int ind = *(loc[ele].begin());
    loc[ele].erase(*(loc[ele].begin()));
    if (loc[ele].size() <= 1) s.erase(ele);
    loc[2 * ele].insert(ind);
    if (s.find(2 * ele) == s.end() and loc[2 * ele].size() > 1)
      s.insert(2 * ele);
  }
  vector<long long int> res(n, -1);
  long long int c = 0;
  for (auto x : loc) {
    for (long long int y : x.second) {
      res[y] = x.first;
      c++;
    }
  }
  cout << c << endl;
  for (long long int x : res) {
    if (x != -1) cout << x << ' ';
  }
  cout << endl;
}
