#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> pos;
bool f[150001];
void solve() {
  int n;
  cin >> n;
  set<long long int> s;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int i = 0;
  while (i < n) {
    if (s.count(a[i]) == 0) {
      s.insert(a[i]);
      f[i] = true;
      pos[a[i]] = i;
      i++;
    } else {
      f[pos[a[i]]] = false;
      s.erase(a[i]);
      a[i] *= 2;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (f[i]) ans++;
  cout << ans << endl;
  for (int i = 0; i < n; i++)
    if (f[i]) cout << a[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) solve();
  return 0;
}
