#include <bits/stdc++.h>
void read(int &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
void read(long long &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
using namespace std;
int n, k;
bool tag[150010];
long long a[150010];
struct node {
  long long val;
  int num;
  node() {}
  node(long long a, int b) { val = a, num = b; }
  bool operator<(const node &a) const {
    return val > a.val || (val == a.val && num > a.num);
  }
};
priority_queue<node> pq;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]), pq.push(node(a[i], i));
  int k = 0;
  while (!pq.empty()) {
    node tmp = pq.top();
    pq.pop();
    node tmp2;
    if (pq.empty()) tag[tmp.num] = 1, k++;
    while (!pq.empty()) {
      tmp2 = pq.top();
      pq.pop();
      if (tmp2.val != tmp.val) {
        k++;
        tag[tmp.num] = 1;
        tmp = tmp2;
        if (pq.empty()) {
          k++;
          tag[tmp2.num] = 1;
          break;
        }
      } else {
        node tmp3 = node(tmp.val * 2, tmp2.num);
        a[tmp3.num] = tmp3.val;
        pq.push(tmp3);
        break;
      }
    }
  }
  printf("%d\n", k);
  for (int i = 1; i <= n; i++)
    if (tag[i]) printf("%lld ", a[i]);
  puts("");
  return 0;
}
