#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005, INF = 1 << 29;
int n, a[MAXN], b[MAXN], *tail = b, t;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  a[0] = INF;
  a[n + 1] = 0;
  for (int i = 1; i <= n + 1; ++i) {
    if (a[i] <= a[i - 1]) {
      ++t;
      *tail++ = a[i - 1];
    }
  }
  printf("%d\n", t - 1);
  for (int *iter = b + 1; iter != tail; ++iter) printf("%d ", *iter);
  printf("\n");
  return 0;
}
