#include <bits/stdc++.h>
using namespace std;
long long int n, m, i, j, c, d, x = 1, cnt = 0, snt = 0;
float f, flo, fload = 0;
string s, g, name;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  ;
  int arr[1001];
  cin >> n;
  for (i = 1; i <= n; i++) cin >> arr[i];
  arr[n + 1] = 0;
  for (i = 1; i <= n; i++) {
    if (arr[i + 1] <= arr[i]) v.push_back(arr[i]);
  }
  cout << v.size() << endl;
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
}
