#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ";
  err(++it, args...);
}
long long int x[1000007], y[1000007], z[1000007], n;
string s, S;
vector<long long int> v;
bitset<1000007> B;
map<long long int, vector<long long int> > mp;
int main() {
  {
    long long int a = 0, b = 0, c = 0, d, e, f, g, i, j, k, l, m, p, q, r, u, w,
                  t, tc = 1, in, loc, val, sz, lo, hi, mid, mn = 2134567891,
                  mx = 0, sum = 0, ans = 0;
    for (t = 1; t <= tc; t++) {
      cin >> n;
      for (i = 0; i < n; i++) {
        cin >> a;
        v.push_back(a);
        mp[a].push_back(i);
      }
      for (auto x : mp) {
        sort(x.second.begin(), x.second.end());
        l = x.second.size();
        k = 0;
        while (l - k > 1) {
          a = x.second[k];
          b = x.second[k + 1];
          v[a] = -1;
          v[b] *= 2;
          k += 2;
          mp[v[b]].push_back(b);
          c++;
        }
      }
      cout << n - c << endl;
      for (i = 0; i < n; i++)
        if (v[i] != -1) cout << v[i] << " ";
      printf("\n");
    }
  }
  return 0;
}
