#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, a[1005], cnt = 1;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i] <= a[i - 1]) {
      cnt++;
      v.push_back(a[i - 1]);
    }
  }
  v.push_back(a[n - 1]);
  cout << cnt << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
