#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
int ans[MAXN];
int main() {
  int n;
  int a, last;
  int num;
  while (scanf("%d", &n) != EOF) {
    last = 0;
    num = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      if (a <= last) {
        ans[num++] = last;
      }
      last = a;
    }
    ans[num++] = a;
    printf("%d\n", num);
    for (int i = 0; i < num; i++) {
      if (i != 0) printf(" ");
      printf("%d", ans[i]);
    }
    printf("\n");
  }
  return 0;
}
