#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long i, j, k, n, m;
  cin >> n;
  long long a[150100];
  map<long long, long long> t;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    if (t[a[i]] > 0) {
      a[t[a[i]]] = -1;
      t[a[i]] = 0;
      a[i] *= 2;
      i--;
    } else
      t[a[i]] = i;
  }
  vector<long long> kq;
  for (i = 1; i <= n; i++) {
    if (a[i] != -1) kq.push_back(a[i]);
  }
  cout << kq.size() << endl;
  for (long long k = 0; k < kq.size(); k++) {
    long long x = kq[k];
    cout << x << " ";
  }
}
