#include <bits/stdc++.h>
const int MAXN = 150000 + 7;
using namespace std;
typedef struct par {
  long long value;
  int pos;
  friend bool operator<(struct par a, struct par b) {
    return (a.value > b.value || (a.value == b.value && a.pos > b.pos));
  }
} par;
priority_queue<par> pq;
int n;
long long a[MAXN];
bool check[MAXN];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u;
    par temp;
    cin >> a[i];
    temp.value = a[i];
    temp.pos = i;
    pq.push(temp);
  }
  memset(check, true, sizeof(check));
  while (!pq.empty()) {
    par u, v;
    u = pq.top();
    pq.pop();
    if (pq.empty()) break;
    v = pq.top();
    pq.pop();
    if (u.value != v.value) {
      pq.push(v);
    } else {
      check[u.pos] = false;
      v.value *= 2;
      a[v.pos] = v.value;
      pq.push(v);
    }
  }
  int count_ = 0;
  for (int i = 1; i <= n; i++) {
    if (check[i]) count_++;
  }
  cout << count_ << endl;
  for (int i = 1; i <= n; i++) {
    if (check[i]) cout << a[i] << " ";
  }
  return 0;
}
