#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n;
long long a;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q, Q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    pair<long long, long long> p(a, i);
    q.push(p);
  }
  while (!q.empty()) {
    pair<long long, long long> p = q.top();
    q.pop();
    if (q.empty()) {
      swap(p.first, p.second);
      Q.push(p);
      break;
    }
    pair<long long, long long> pp = q.top();
    q.pop();
    if (pp.first != p.first) {
      q.push(pp);
      swap(p.first, p.second);
      Q.push(p);
    } else {
      pp.first *= 2;
      q.push(pp);
    }
  }
  printf("%d\n", Q.size());
  pair<long long, long long> p = Q.top();
  Q.pop();
  printf("%lld", p.second);
  while (!Q.empty()) {
    p = Q.top();
    Q.pop();
    printf(" %lld", p.second);
  }
  cout << endl;
  return 0;
}
