#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const int N = 1e6 + 100;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
const long long int hashh = 311;
long long int a[N];
map<long long int, set<long long int> > m;
long long int pos[N];
int main() {
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  set<long long int> s;
  for (long long int i = 0; i < n; i++)
    s.insert(a[i]), pos[i] = a[i], m[a[i]].insert(i);
  while (!s.empty()) {
    long long int x = *(s.begin());
    s.erase(x);
    while (m[x].size() > 1) {
      long long int y = *(m[x].begin());
      m[x].erase(y);
      long long int z = *(m[x].begin());
      m[x].erase(z);
      pos[y] = -1;
      pos[z] *= (long long int)2;
      m[(long long int)2 * x].insert(z);
      s.insert((long long int)2 * x);
    }
  }
  vector<long long int> v;
  v.clear();
  for (long long int i = 0; i < n; i++)
    if (pos[i] != -1) v.push_back(pos[i]);
  cout << v.size() << "\n";
  for (long long int i : v) cout << i << " ";
}
