#include <bits/stdc++.h>
using namespace std;
int x;
long long X;
long long ans[200001];
int n, i, a;
int main() {
  scanf("%d", &n);
  a = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    X = x;
    while (a >= 0)
      if (X == ans[a]) {
        X += 1;
        a--;
      } else
        break;
    ans[++a] = X;
  }
  cout << a << endl;
  for (i = 1; i <= a; i++) cout << ans[i] << " ";
}
