#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
map<long long, long long> m, mi;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  ;
  vector<bool> v(n);
  for (long long i = 0; i < n; i++) {
    m[a[i]]++;
    if (m[a[i]] == 1) {
      mi[a[i]] = i;
    } else {
      while (m[a[i]] == 2) {
        v[mi[a[i]]] = true;
        m[a[i]] = 0;
        a[i] = 2 * a[i];
        m[a[i]]++;
        if (m[a[i]] == 1) mi[a[i]] = i;
      }
    }
  }
  long long k = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i] == true) continue;
    k++;
  }
  cout << k << "\n";
  for (long long i = 0; i < n; i++) {
    if (v[i] == true) continue;
    cout << a[i] << " ";
  }
  return 0;
}
