#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[1000], c = 0, j = 0, b[1000];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++)
    if (a[i + 1] != a[i] + 1) {
      c++;
      b[j++] = a[i];
    }
  c++;
  b[j] = a[n - 1];
  cout << c << "\n";
  for (int i = 0; i < c; i++) cout << b[i] << " ";
}
