#include <bits/stdc++.h>
using namespace std;
stack<long long> s;
long long n, x;
vector<long long> v;
inline long long read() {
  long long sum = 0, x = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') x = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; ++i) {
    x = read();
    while (!s.empty() && x == s.top()) {
      s.pop();
      ++x;
    }
    s.push(x);
  }
  write(s.size());
  putchar('\n');
  while (!s.empty()) {
    v.push_back(s.top());
    s.pop();
  }
  reverse(v.begin(), v.end());
  for (auto i : v) {
    write(i);
    putchar(' ');
  }
  return 0;
}
