#include <bits/stdc++.h>
using namespace std;
const long long N = 200010;
void solve() {
  long long n, m, i, j, k;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  map<long long, set<long long> > v;
  vector<long long> vis(n);
  map<long long, long long> fr;
  set<pair<long long, long long> > s;
  for (i = 0; i < n; i++) {
    v[a[i]].insert(i);
    fr[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    if (fr[a[i]] > 1 && s.find({a[i], fr[a[i]]}) == s.end())
      s.insert({a[i], fr[a[i]]});
  }
  set<pair<long long, long long> >::iterator itr;
  set<long long>::iterator itr1;
  while (s.size() > 0) {
    itr = s.begin();
    pair<long long, long long> p = *itr;
    s.erase(itr);
    long long x = p.first;
    itr1 = v[x].begin();
    long long i1 = *itr1;
    v[x].erase(itr1);
    itr1 = v[x].begin();
    long long i2 = *itr1;
    v[x].erase(itr1);
    fr[x] -= 2;
    vis[i1] = 1;
    if (s.find({2 * x, fr[2 * x]}) != s.end())
      s.erase(s.find({2 * x, fr[2 * x]}));
    fr[2 * x]++;
    a[i2] *= 2;
    v[2 * x].insert(i2);
    if (v[x].size() > 1) {
      s.insert({x, fr[x]});
    }
    if (v[2 * x].size() > 1) {
      s.insert({2 * x, fr[2 * x]});
    }
  }
  vector<long long> ans(n);
  j = 0;
  for (i = 0; i < n; i++) {
    if (!vis[i]) {
      ans[j] = a[i];
      j++;
    }
  }
  cout << j << "\n";
  for (i = 0; i < j; i++) cout << ans[i] << " ";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j;
  long long q = 1;
  while (q--) solve();
}
