#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n;
  cin >> n;
  map<int64_t, set<int64_t>> m;
  for (int64_t x = 0; x < n; ++x) {
    int64_t v;
    cin >> v;
    m[v].insert(x);
  }
  vector<pair<int64_t, int64_t>> v;
  for (auto x : m) {
    if (x.second.size() % 2) {
      v.push_back({*(--x.second.end()), x.first});
      x.second.erase(v.back().first);
    }
    for (auto it = x.second.begin(); it != x.second.end(); ++it) {
      m[2 * x.first].insert(*(++it));
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << endl;
  for (auto x : v) {
    cout << x.second << " ";
  }
  cout << endl;
  return 0;
}
