#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> ss;
  int n, a[1001], g = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    g++;
    if (a[i] == 1) {
      ss.push_back(g);
      g = 0;
    }
  }
  g++;
  ss.push_back(g);
  cout << ss.size() << endl;
  for (int i = 0; i < ss.size(); i++) {
    cout << ss[i] << " ";
  }
  return 0;
}
