#include <bits/stdc++.h>
using namespace std;
int sett(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
template <typename T>
T bigmod(T x, T p) {
  if (p == 0) return 1;
  if (p & 1) {
    return x * bigmod(x, p - 1) % 1000000007;
  } else {
    T tmp = bigmod(x, p >> 1) % 1000000007;
    return tmp * tmp % 1000000007;
  }
}
template <typename T>
void print(const T& v) {
  cerr << v << ' ';
}
template <typename T1, typename... T2>
void print(const T1& first, const T2&... rest) {
  print(first);
  print(rest...);
}
const int inf = (1 << 30);
int a[2000123 + 4];
struct dat {
  long long val, id;
  dat(long long a, long long b) {
    val = a;
    id = b;
  };
  bool operator<(dat x) const { return val == x.val ? id < x.id : val < x.val; }
};
set<dat> st;
vector<dat> v;
bool compare(dat x, dat y) { return x.id < y.id; }
void func(dat x) { cout << x.val << " " << x.id << "\n"; }
void solve() {
  set<dat>::iterator it, it2, it3;
  while (1) {
    if (st.size() < 2) break;
    it = st.begin();
    it2 = st.begin();
    it2++;
    if (it->val != it2->val) {
      v.push_back(*it);
      st.erase(it);
    } else {
      dat x = dat(it->val + it2->val, it2->id);
      st.erase(it);
      it = st.begin();
      st.erase(it);
      st.insert(x);
    }
  }
  if (st.size() == 1) {
    v.push_back(*(st.begin()));
  }
  sort(v.begin(), v.end(), compare);
  cout << v.size() << "\n";
  for (int i = 0; i < v.size(); i++) cout << v[i].val << ' ';
}
int main() {
  long long cnt = 1, n, qr, k;
  scanf("%I64d", &n);
  for (int i = 1; i <= (int)n; i++) {
    scanf("%I64d", &k);
    st.insert(dat(k, (long long)i));
  }
  solve();
  return 0;
}
