#include <bits/stdc++.h>
using namespace std;
int n;
long long a[150005];
map<long long, int> ma;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    while (ma[a[i]] != 0) {
      a[ma[a[i]]] = 0;
      ma[a[i]] = 0;
      a[i] *= 2;
    }
    ma[a[i]] = i;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i]) cnt++;
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) {
    if (a[i]) cout << a[i] << ' ';
  }
  return 0;
}
