#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, t;
  vector<long long> v, stair;
  cin >> t;
  while (t--) {
    cin >> n;
    v.push_back(n);
  }
  for (i = 0; i + 1 < v.size(); i++) {
    if (v[i + 1] <= v[i]) {
      stair.push_back(v[i]);
    }
  }
  stair.push_back(v[i]);
  cout << stair.size() << endl;
  for (i = 0; i < stair.size(); i++) {
    cout << stair[i] << " ";
  }
  return 0;
}
