#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j = 1, k = 0;
  cin >> n;
  long long int A[n], B[1000];
  for (i = 0; i < n; i++) cin >> A[i];
  if (n == 1)
    cout << 1 << endl << 1;
  else {
    for (i = 1; i < n; i++) {
      if (A[i] == 1) {
        B[k] = j;
        k++;
        j = 0;
      }
      j++;
      if (i == n - 1) B[k] = j;
    }
    cout << k + 1 << endl;
    for (i = 0; i < k + 1; i++) cout << B[i] << " ";
  }
}
