#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, s = 0, i, k = 0;
  cin >> n;
  if (n != 1) {
    int A[n];
    cin >> a;
    for (i = 1; i < n; i++) {
      if (a == 1) s++;
      cin >> b;
      if (a >= b) {
        A[k] = a;
        k++;
      }
      a = b;
    }
    if (b == 1) s++;
    cout << s << endl;
    for (k = 0; k < s - 1; k++) cout << A[k] << " ";
    cout << b;
  } else
    cout << n << endl << n;
  return 0;
}
