#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
stack<long long> s;
int n;
long long Ans_[maxn], cnt = 0;
signed main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    int t;
    cin >> t;
    while (!s.empty() && t == s.top()) s.pop(), t++;
    s.push(t);
  }
  while (!s.empty()) Ans_[++cnt] = s.top(), s.pop();
  printf("%lld\n", cnt);
  for (register int i = cnt; i >= 1; --i) printf("%lld ", Ans_[i]);
  return 0;
}
