#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E5;
map<long long, int> mp;
vector<long long> ans;
long long n, cnt;
bool can[MAXN];
int main() {
  while (scanf("%d", &n) != EOF) {
    mp.clear();
    ans.clear();
    cnt = 0;
    memset(can, true, sizeof(can));
    for (int i = 1; i <= n; ++i) {
      long long num;
      scanf("%I64d", &num);
      ans.push_back(num);
      while (mp[num] != NULL) {
        ans[i - 1] *= 2;
        can[mp[num] - 1] = false;
        mp[num] = NULL;
        num *= 2;
        ++cnt;
      }
      mp[num] = i;
    }
    printf("%d\n", n - cnt);
    for (int i = 0; i < ans.size(); ++i) {
      if (can[i]) {
        printf("%I64d ", ans[i]);
      }
    }
  }
  return 0;
}
