#include <bits/stdc++.h>
using namespace std;
struct node {
  int index;
  long long val;
  bool operator<(const node &a) const {
    if (val > a.val)
      return true;
    else if (val == a.val && index > a.index)
      return true;
    return false;
  }
};
long long ar[150010];
int main() {
  int n, k = 0;
  scanf("%d", &n);
  priority_queue<node> q;
  for (int x = 0; x < n; x++) {
    scanf("%lld", &ar[x]);
    node temp;
    temp.val = ar[x];
    temp.index = x;
    q.push(temp);
  }
  while (!q.empty()) {
    node top = q.top();
    q.pop();
    if (!q.empty() && q.top().val == top.val) {
      k++;
      node top2 = q.top();
      q.pop();
      node temp;
      temp.index = top2.index;
      temp.val = 2 * top2.val;
      ar[top.index] = -1;
      ar[top2.index] = temp.val;
      q.push(temp);
    }
  }
  printf("%d\n", n - k);
  int c = 0;
  for (int x = 0; x < n; x++) {
    if (ar[x] != -1) {
      if (c == 0)
        printf("%lld", ar[x]);
      else
        printf(" %lld", ar[x]);
      c++;
    }
  }
  printf("\n");
  return 0;
}
