#include <bits/stdc++.h>
using namespace std;
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  set<pair<long long, long long>> po;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    po.insert(make_pair(a[i], i));
  }
  pair<long long, long long> x, y;
  while (po.size() >= 1) {
    x = *po.begin();
    po.erase(po.begin());
    if (po.size() == 0) {
      v[x.second] = x.first;
      break;
    }
    y = *po.begin();
    po.erase(po.begin());
    if (x.first == y.first) {
      po.insert({2 * (x.first), y.second});
      v[x.second] = -1;
    } else {
      v[x.second] = x.first;
      po.insert(y);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] != -1) ans++;
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    if (v[i] != -1) cout << v[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
