#include <bits/stdc++.h>
int main() {
  int n, i, j, c = 0, k = 1, p = 0;
  scanf("%d", &n);
  int arr[n], res[n];
  ;
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (i = 0; i < n; i++) {
    if (arr[i] == 1) {
      c += 1;
      for (j = i + 1; j < n; j++) {
        if (arr[j] != 1) {
          k += 1;
        } else {
          break;
        }
      }
      res[p] = k;
      k = 1;
      p += 1;
    }
  }
  printf("%d\n", c);
  for (i = 0; i < c; i++) {
    printf("%d ", res[i]);
  }
  return 0;
}
