#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e5 + 10;
int n, m, T;
int a[MAXN];
int pos = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  a[0] = -1;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    while (a[pos] == x) x++, pos--;
    a[++pos] = x;
  }
  cout << pos << endl;
  for (int i = 1; i <= pos; i++) cout << a[i] << " ";
  return 0;
}
