#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > Gr(1e5 + 5);
vector<bool> Vis(1e5 + 5, 0);
stack<int> Sk;
map<int, bool> Map;
bool flag = 1;
void Topo(int S) {
  if (!flag) return;
  Vis[S] = 1;
  Map[S] = 1;
  for (auto i = Gr[S].begin(); i != Gr[S].end(); i++) {
    if (Map[*i]) {
      flag = 0;
      return;
    }
    if (!Vis[*i]) Topo(*i);
  }
  Map.erase(S);
  Sk.push(S);
}
int main() {
  long long N;
  cin >> N;
  map<long long, int> Map;
  vector<long long> V(N, 0);
  vector<bool> A(N, 1);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
    while (Map[V[i]] != 0) {
      A[Map[V[i]] - 1] = 0;
      Map[V[i]] = 0;
      V[i] *= 2;
    }
    Map[V[i]] = i + 1;
  }
  int Count = 0;
  for (int i = 0; i < N; i++) {
    if (A[i]) Count++;
  }
  cout << Count << endl;
  for (int i = 0; i < N; i++) {
    if (A[i]) cout << V[i] << " ";
  }
}
