#include <bits/stdc++.h>
using namespace std;
const int lim = 1e6;
std::vector<int> adj[lim];
std::map<long long, int> in;
bool ok[lim];
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  std::vector<long long> ar(n);
  set<long long> vec;
  set<long long>::iterator it;
  int k = 1;
  for (int i = 0; i < n; i++) {
    long long num;
    cin >> num;
    ar[i] = num;
    vec.insert(num);
    if (in[num] == 0) {
      in[num] = k++;
    }
    adj[in[num]].push_back(i);
  }
  int ct = 0;
  while (!vec.empty()) {
    it = vec.begin();
    int num = in[*it];
    vec.erase(*it);
    sort(adj[num].begin(), adj[num].end());
    int lent = adj[num].size();
    for (int j = 0; j < lent - 1; j += 2) {
      ok[adj[num][j]] = true;
      ++ct;
      ar[adj[num][j + 1]] *= 2;
      long long val = ar[adj[num][j + 1]];
      if (in[val] == 0) {
        in[val] = k++;
        vec.insert(val);
      }
      adj[in[val]].push_back(adj[num][j + 1]);
    }
  }
  cout << n - ct << '\n';
  for (int i = 0; i < n; i++) {
    if (!ok[i]) cout << ar[i] << " ";
  }
  cout << '\n';
  return 0;
}
