#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k = 0, l, m = 0, n, o, p;
  cin >> n;
  vector<int> v;
  int a[n];
  int b[n];
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    if (a[i] == 1) k++;
  }
  cout << k << endl;
  for (i = 1; i <= n; i++) {
    m++;
    if (a[i + 1] == 1) {
      v.push_back(m);
      m = 0;
    }
  }
  for (i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << a[n];
}
