#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double eps = 10e-7;
const int sz = 300;
const double pi = 3.14159265359;
int n;
long long elem;
vector<long long> a;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &elem);
    a.push_back(elem);
    while (a.size() > 1 && a.back() == a[a.size() - 2]) {
      a.pop_back();
      a.back() += 1;
    }
  }
  printf("%d\n", a.size());
  for (int i = 0; i < a.size(); ++i) printf("%lld ", a[i]);
  return 0;
}
