#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
map<long long, priority_queue<long long, vector<long long>, greater<long long>>>
    m;
long long a[150004];
int32_t main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]].push(i);
    pq.push(a[i]);
  }
  while (pq.size()) {
    if (m[pq.top()].size() < 2) {
      pq.pop();
      continue;
    }
    a[m[pq.top()].top()] = 0;
    m[pq.top()].pop();
    a[m[pq.top()].top()] = 0;
    long long j = m[pq.top()].top();
    m[pq.top()].pop();
    m[pq.top() * 2].push(j);
    pq.push(pq.top() * 2);
    a[j] = pq.top() * 2;
  }
  long long sz = 0;
  for (long long i = 0; i < n; i++)
    if (a[i]) sz++;
  cout << sz << endl;
  for (long long i = 0; i < n; i++)
    if (a[i]) cout << a[i] << " ";
}
