#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
map<long long, int> cnt;
bool vis[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long a[n];
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    while (1) {
      auto it = cnt.find(x);
      if (it == cnt.end()) {
        cnt[x] = i;
        break;
      } else {
        vis[cnt[x]] = true;
        cnt.erase(it);
        x *= 2LL;
      }
    }
    a[i] = x;
  }
  vector<long long> vec;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    vec.push_back(a[i]);
  }
  cout << vec.size() << endl;
  for (long long x : vec) cout << x << " ";
  cout << endl;
  return 0;
}
