#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int c = 0;
  vector<int> v;
  int arr[n];
  arr[n] = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int j = 0; j < n; j++) {
    if (arr[j] >= arr[j + 1]) {
      c++;
      v.push_back(arr[j]);
    }
  }
  cout << c << endl;
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
}
