#include <bits/stdc++.h>
using namespace std;
long long n, i, a[202020];
priority_queue<pair<long long, long long> > pq;
pair<long long, long long> u, nx;
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    pq.push(make_pair(-a[i], -i));
  }
  while (pq.size() > 1) {
    u = pq.top();
    pq.pop();
    if (a[-u.second] != -u.first) continue;
    nx = pq.top();
    if (u.first == nx.first) {
      a[-u.second] = 0;
      a[-nx.second] = -u.first * 2;
      pq.push(make_pair(-a[-nx.second], nx.second));
    }
  }
  for (i = 1; i <= n; i++)
    if (a[i] != 0) v.push_back(a[i]);
  cout << v.size() << "\n";
  for (i = 0; i < v.size(); i++)
    if (i + 1 < v.size())
      cout << v[i] << " ";
    else
      cout << v[i] << "\n";
}
