#include <bits/stdc++.h>
using namespace std;
long long arr[150000];
int n;
int tree[4 * 150000];
void build(int p, int l, int r) {
  if (l == r) {
    tree[p] = l;
    return;
  }
  build(p << 1, l, (l + r) >> 1);
  build(p << 1 | 1, ((l + r) >> 1) + 1, r);
  tree[p] = (arr[tree[p << 1]] <= arr[tree[p << 1 | 1]]) ? tree[p << 1]
                                                         : tree[p << 1 | 1];
}
void update(int p, int l, int r, int ind, long long val) {
  if (l == r) {
    arr[l] = val;
    return;
  }
  int m = (l + r) >> 1;
  if (ind <= m) {
    update(p << 1, l, m, ind, val);
  } else {
    update(p << 1 | 1, m + 1, r, ind, val);
  }
  tree[p] = (arr[tree[p << 1]] <= arr[tree[p << 1 | 1]]) ? tree[p << 1]
                                                         : tree[p << 1 | 1];
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  bool ans[n];
  long long tarr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    ans[i] = false;
    tarr[i] = arr[i];
  }
  build(1, 0, n - 1);
  int a, b;
  int count = 0;
  while (1) {
    a = tree[1];
    long long x = arr[a];
    long long val = 2e17 + 9;
    update(1, 0, n - 1, a, val);
    b = tree[1];
    long long y = arr[b];
    update(1, 0, n - 1, b, val);
    if (x == val || y == val) {
      break;
    }
    if (x == y) {
      update(1, 0, n - 1, b, 2 * y);
      tarr[b] = 2 * y;
      ans[a] = true;
    } else {
      update(1, 0, n - 1, b, y);
    }
  }
  vector<long long> out;
  for (int i = 0; i < n; i++) {
    if (ans[i]) continue;
    out.push_back(tarr[i]);
  }
  cout << out.size() << endl;
  for (long long te : out) {
    cout << te << " ";
  }
  cout << endl;
  return 0;
}
