#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<bool> vis(n);
  map<long long, vector<int> > m;
  set<long long> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]].push_back(i);
    s.insert(a[i]);
  }
  while (s.size() > 0) {
    long long v = *s.begin();
    if (m[v].size() > 1) {
      vector<int> t = m[v];
      sort(t.begin(), t.end());
      for (int i = 0; i < t.size() - 1; i += 2) {
        vis[t[i]] = true;
        n--;
        a[t[i + 1]] = 2 * v;
        m[2 * v].push_back(t[i + 1]);
      }
      s.insert(2 * v);
    }
    s.erase(s.begin());
  }
  cout << n << endl;
  for (int i = 0; i < a.size(); i++)
    if (!vis[i]) cout << a[i] << " ";
  cout << endl;
  return 0;
}
