#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  list<int> a;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a.push_back(x);
  }
  for (auto t = a.begin(); t != a.end(); t++) {
    auto s = t;
    s--;
    if (t == a.begin()) continue;
    while (true) {
      if (*t == *s) {
        *t = *t + 1;
        t = a.erase(s);
        if (t == a.begin()) break;
        s = t, s--;
      } else
        break;
    }
  }
  printf("%d\n", a.size());
  for (auto t : a) printf("%d ", t);
  return 0;
}
