#include <bits/stdc++.h>
using namespace std;
int main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  map<long long int, set<long long int> > m;
  set<long long int> s;
  for (int i = 0; i < n; i++) {
    m[a[i]].insert(i);
    if (!m[a[i]].empty() && m[a[i]].size() >= 2) s.insert(a[i]);
  }
  set<long long int>::iterator st, at;
  map<long long int, set<long long int> >::iterator mt;
  while (!s.empty()) {
    st = s.begin();
    long long int el, nel, fi, se;
    el = *st;
    at = m[el].begin();
    fi = *at;
    at++;
    se = *at;
    nel = 2 * el;
    m[el].erase(fi);
    m[el].erase(se);
    a[fi] = -1;
    a[se] = nel;
    if (m[el].size() < 2) {
      s.erase(el);
    }
    m[nel].insert(se);
    if (m[nel].size() >= 2) {
      s.insert(nel);
    }
  }
  int resSize = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != -1) resSize++;
  cout << resSize << endl;
  for (int i = 0; i < n; i++)
    if (a[i] != -1) cout << a[i] << " ";
  cout << endl;
  return 0;
}
