#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int shout[1001] = {};
  int counter = 0, step[1001] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> shout[i];
  }
  for (int i = 0; i < n; i++) {
    if (shout[i] == 1) {
      int temp = 1;
      while (shout[i + 1] != 1 && i + 1 < n) {
        temp++;
        i++;
      }
      step[counter] = temp;
      counter++;
    }
  }
  cout << counter << endl;
  for (int i = 0; i < counter; i++) {
    cout << step[i] << " ";
  }
  return 0;
}
