#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void checkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void checkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
unordered_map<long long, pair<long long, long long> > mymap;
void add(long long x, long long ind) {
  mymap[x].second = ind;
  if (mymap[x].first == 1) {
    mymap[x].first = 0;
    add(2 * x, ind);
  } else
    ++mymap[x].first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (auto &i : arr) cin >> i;
  for (int i = 0; i < n; ++i) add(arr[i], i);
  vector<pair<long long, long long> > newvec;
  for (auto i : mymap)
    if (i.second.first == 1) {
      newvec.push_back(make_pair(i.second.second, i.first));
    }
  sort(newvec.begin(), newvec.end());
  cout << newvec.size() << '\n';
  for (auto i : newvec) cout << i.second << ' ';
  return 0;
}
