#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, i, A[1005], B[1005], k = 0;
  cin >> n;
  for (long long(i) = 0; (i) < (n); (i) = (i + 1)) {
    cin >> A[i];
  }
  for (long long(i) = 0; (i) < (n - 1); (i) = (i + 1)) {
    if (A[i + 1] <= A[i]) {
      B[k++] = A[i];
    }
  }
  B[k++] = A[n - 1];
  cout << k << endl;
  for (long long(i) = 0; (i) < (k); (i) = (i + 1)) {
    cout << B[i] << " ";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
