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