#include <bits/stdc++.h>
using namespace std;
map<long long, vector<int> > mp;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  mp.clear();
  vector<pair<int, long long> > v;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    mp[x].push_back(i);
  }
  for (auto e : mp) {
    long long x = e.first;
    vector<int> foo = e.second;
    sort(foo.begin(), foo.end());
    for (int i = 1; i < ((int)(foo.size())); i += 2)
      mp[x * 2LL].push_back(foo[i]);
    if (((int)(foo.size())) & 1) v.push_back({foo.back(), x});
  }
  sort(v.begin(), v.end());
  cout << ((int)(v.size())) << '\n';
  for (auto e : v) cout << e.second << " ";
  return 0;
}
