#include <bits/stdc++.h>
using namespace std;
long long a, n;
set<pair<long long, long long> > st, ans;
set<pair<long long, long long> >::iterator t, t1, t2;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    st.insert({a, i});
  }
  for (t = st.begin(); t != st.end();) {
    t1 = ++t;
    t--;
    if (t->first == t1->first) {
      st.insert({2 * t->first, t1->second});
      t2 = ++t1;
      t1--;
      st.erase(t);
      st.erase(t1);
      t = t2;
    } else {
      ans.insert({t->second, t->first});
      t = t1;
    }
  }
  cout << ans.size() << endl;
  for (auto t : ans) cout << t.second << " ";
}
