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