#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double EPS = 1e-10;
const double pi = 3.14159265358979323846;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool good(string s) {
  int cnt = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] != s[i + 1]) cnt++;
  }
  return cnt <= 1;
}
int main() {
  fast();
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  map<long long, set<long long>> mp;
  for (int i = 0; i < n; i++) {
    mp[v[i]].insert(i);
  }
  for (auto& it : mp) {
    while (it.second.size() > 1) {
      it.second.erase(it.second.begin());
      mp[it.first * 2].insert(*it.second.begin());
      it.second.erase(it.second.begin());
    }
  }
  map<long long, long long> ans;
  for (auto& it : mp) {
    if (it.second.size() == 1) ans[*it.second.begin()] = it.first;
  }
  cout << ans.size() << "\n";
  ;
  for (auto i : ans) cout << i.second << " ";
}
