#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, s, d, f, i, j, k, mm;
  string ss;
  cin >> a;
  vector<long long> vec;
  map<long long, long long> m;
  for (i = 0; i < a; i++) {
    cin >> s;
    vec.push_back(s);
  }
  for (i = 0; i < a; i++) {
    long long t = vec[i];
    while (m[t] != 0) {
      vec[m[t] - 1] = -1;
      m[t] = 0;
      t = t * 2;
      vec[i] = t;
    }
    m[t] = i + 1;
  }
  long long sum = 0;
  for (i = 0; i < a; i++)
    if (vec[i] != -1) sum++;
  cout << sum << endl;
  for (i = 0; i < a; i++)
    if (vec[i] != -1) cout << vec[i] << " ";
}
