#include <bits/stdc++.h>
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = 1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (auto i : v) {
    if (!first) os << ", ";
    os << i;
    first = false;
  }
  return os << "]";
}
const long long N = 2 * 1e5 + 10;
long long n;
std::map<long long, long long> freq;
std::map<long long, set<long long> > v;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  set<long long> s;
  std::vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; ++i) {
    v[a[i]].insert(i);
    freq[a[i]]++;
  }
  for (auto i : freq) {
    if (i.second >= 2) {
      s.insert(i.first);
    }
  }
  while ((long long)(s.size())) {
    long long one = *s.begin();
    std::set<long long>& vec = v[one];
    assert((long long)(vec.size()) >= 2);
    long long first = *vec.begin();
    vec.erase(vec.begin());
    long long second = *vec.begin();
    vec.erase(vec.begin());
    a[first] = -inf;
    a[second] = 2 * one;
    freq[one] -= 2;
    freq[2 * one]++;
    set<long long>& vec2 = v[2 * one];
    vec2.insert(second);
    if (freq[one] < 2) {
      s.erase(s.find(one));
    }
    if (freq[2 * one] >= 2) {
      s.insert(2 * one);
    }
  }
  long long c = 0;
  for (long long i = 0; i < n; ++i) {
    if (a[i] == -inf) continue;
    c++;
  }
  cout << c << '\n';
  for (long long i = 0; i < n; ++i) {
    if (a[i] == -inf) continue;
    cout << a[i] << ' ';
  }
  return 0;
}
