#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int inf = 0x3f3f3f3f;
struct NODE {
  long long sum, pos;
} edge[maxn];
bool cmp(NODE a, NODE b) { return a.pos < b.pos; }
struct Node {
  long long sum, pos;
  bool operator<(const Node &a) const {
    if (a.sum == sum) return a.pos < pos;
    return a.sum < sum;
  }
} node;
priority_queue<Node> q;
long long num, n;
int main() {
  cin >> n;
  Node x, y;
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i++) {
    cin >> num;
    x.pos = i;
    x.sum = num;
    q.push(x);
  }
  long long tot = 0;
  while (!q.empty()) {
    if (q.size() == 1) {
      x = q.top();
      q.pop();
      edge[tot].sum = x.sum;
      edge[tot++].pos = x.pos;
      break;
    }
    x = q.top();
    q.pop();
    y = q.top();
    q.pop();
    if (x.sum == y.sum) {
      x.sum *= 2;
      x.pos = max(x.pos, y.pos);
      q.push(x);
    } else {
      edge[tot].sum = x.sum;
      edge[tot++].pos = x.pos;
      q.push(y);
    }
  }
  sort(edge, edge + tot, cmp);
  cout << tot << "\n";
  for (int i = 0; i < tot; i++) {
    cout << edge[i].sum;
    if (i != tot - 1) cout << " ";
  }
  cout << "\n";
  return 0;
}
