#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  int s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) s++;
  }
  int b[s];
  int k = 0;
  for (int j = 1; j < n; j++) {
    if (a[j] == 1) b[k++] = a[j - 1];
  }
  b[s - 1] = a[n - 1];
  printf("%d\n", s);
  for (int j = 0; j < s; j++) printf("%d ", b[j]);
}
