#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000 + 1;
int n;
map<long long, set<int>> m;
priority_queue<long long, vector<long long>, greater<long long>> q;
void read_in() {
  scanf("%d", &n);
  long long tmp;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &tmp);
    m[tmp].insert(i + 1);
  }
  for (auto& i : m) {
    if (i.second.size() >= 2) q.push(i.first);
  }
};
void solve() {
  while (!q.empty()) {
    long long tmp = q.top();
    q.pop();
    m[tmp].erase(m[tmp].begin());
    int loc = *m[tmp].begin();
    m[tmp].erase(m[tmp].begin());
    if (m[tmp].size() >= 2) q.push(tmp);
    tmp += tmp;
    if (m[tmp].size() == 1) q.push(tmp);
    m[tmp].insert(loc);
  }
  int cnt = 0;
  long long res[maxn];
  for (int i = 1; i <= n; i++) res[i] = LLONG_MAX;
  for (auto& i : m) {
    cnt += i.second.size();
    for (auto& j : i.second) {
      res[j] = i.first;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (res[i] != LLONG_MAX) printf("%lld ", res[i]);
  printf("\n");
}
int main() {
  read_in();
  solve();
  return 0;
}
