#include <bits/stdc++.h>
using namespace std;
void read(int &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
void read(long long &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
void readvec(vector<int> &a, int n) {
  for (int i = 0; i < n; i++) read(a[i]);
}
void readvec(vector<long long> &a, long long n) {
  for (int i = 0; i < n; i++) read(a[i]);
}
const int MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const long double PI = 3.1415926535897932384626433832795;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  read(n);
  vector<long long> v(n);
  map<long long, set<long long>> mp;
  for (int i = 0; i < n; i++) {
    read(v[i]);
    mp[v[i]].insert(i);
  }
  for (auto it : mp) {
    set<long long> s = it.second;
    while (1) {
      if (s.size() <= 1) {
        break;
      }
      v[*s.begin()] = 0;
      s.erase(s.begin());
      v[*s.begin()] *= 2;
      mp[2 * it.first].insert(*s.begin());
      s.erase(s.begin());
    }
  }
  int sz = 0;
  for (int i = 0; i < n; i++) {
    if (v[i]) {
      sz++;
    }
  }
  cout << sz << "\n";
  for (int i = 0; i < n; i++) {
    if (v[i]) {
      cout << v[i] << " ";
    }
  }
}
int32_t main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
