#include <bits/stdc++.h>
using namespace std;
long long x[150010];
map<long long, int> a;
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> x[i];
  for (long long i = 1; i <= n; i++) {
    if (x[i] == 0) continue;
    if (a[x[i]] == 0)
      a[x[i]] = i;
    else if (a[x[i]] != 0) {
      x[a[x[i]]] = 0;
      a[x[i]] = 0;
      x[i] *= 2;
      i--;
    }
  }
  long long s = 0;
  for (long long i = 1; i <= n; i++) {
    if (x[i] != 0) s++;
  }
  cout << s << endl;
  for (long long i = 1; i <= n; i++) {
    if (x[i] != 0) cout << x[i] << " ";
  }
  return 0;
}
