#include <bits/stdc++.h>
using namespace std;
int n, k, ans, a[1010];
void interesting(int f, int last) {
  if (f > n) return;
  scanf("%d", &k);
  if (last >= k) a[++ans] = last;
  if (f == n) a[++ans] = k;
  interesting(f + 1, k);
}
int main() {
  scanf("%d", &n);
  interesting(1, 0);
  printf("%d\n", ans);
  for (int i = 1; i <= ans; i++) printf("%d ", a[i]);
  return 0;
}
