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