#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
  out << p.first << ' ' << p.second;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
const long double pi = 2 * asin(1);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n;
  bool f;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    do {
      f = 1;
      if (m.find(x) != m.end()) {
        m.erase(x);
        x *= 2;
        f = 0;
      } else
        m[x] = i;
    } while (!f);
  }
  vector<pair<long long, long long> > V;
  for (auto x : m) V.push_back({x.second, x.first});
  sort(V.begin(), V.end());
  cout << V.size() << '\n';
  for (auto x : V) cout << x.second << ' ';
  return 0;
}
