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