#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
long long mod = 1000000007LL;
long long mod2 = 998244353LL;
int n;
long long a[200005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  vector<long long> stk;
  stk.clear();
  for (int i = 1; i <= n; ++i) {
    int cur = a[i];
    while (!stk.empty() && stk.back() == cur) {
      stk.pop_back();
      cur++;
    }
    stk.push_back(cur);
  }
  printf("%d\n", (int)stk.size());
  for (int i = 0; i < stk.size(); ++i) {
    printf("%lld", stk[i]);
    if (i < stk.size() - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
