#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1.0L);
const long double EPS = static_cast<long double>(1e-9);
const long long N = 1e6 + 7;
long long n, a[N], del;
void input() {
  cin >> n;
  for (long long i = (1); i <= (n); i++) {
    cin >> a[i];
  }
}
void solve() {
  map<long long, long long> mp;
  for (long long i = (1); i <= (n); i++) {
    while (mp[a[i]]) {
      a[mp[a[i]]] = 0;
      mp[a[i]] = 0;
      a[i] *= 2;
      del++;
    }
    mp[a[i]] = i;
  }
}
void output() {
  cout << n - del << endl;
  for (long long i = (1); i <= (n); i++) {
    if (a[i]) cout << a[i] << ' ';
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  {
    input();
    solve();
    output();
  }
  return 0;
}
