#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x;
  int count1 = 0;
  int count2 = 1;
  vector<int> v;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      count1++;
    }
  }
  cout << count1 << endl;
  if (count1 == n) {
    for (int i = 0; i < n; i++) {
      cout << "1"
           << " ";
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i + 1] == 1 || i == n - 1) {
        cout << count2 << " ";
        count2 = 1;
      } else {
        count2++;
      }
    }
  }
  cout << endl;
}
