#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> aa;
  vector<int> bb;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int inp;
    cin >> inp;
    aa.push_back(inp);
  }
  for (int i = 0; i < n - 1; i++) {
    if (aa[i] >= aa[i + 1]) {
      bb.push_back(aa[i]);
    }
    if (n - 1 == i + 1) {
      bb.push_back(aa[n - 1]);
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    cout << 1 << endl;
  } else {
    cout << bb.size() << endl;
    for (int i = 0; i < bb.size(); i++) {
      cout << bb[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
