#include <bits/stdc++.h>
using namespace std;
int n;
int a[200001];
int t;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[t++];
    while (t > 1 && a[t - 2] == a[t - 1]) {
      t--;
      a[t - 1]++;
    }
  }
  cout << t << endl;
  for (int i = 0; i < t; i++) cout << a[i] << endl;
}
