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