#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n];
  vector<int> vc;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] == 1) {
      vc.push_back(i);
    }
  }
  cout << vc.size();
  cout << endl;
  for (int i = 1; i < vc.size(); i++) {
    cout << vc[i] - vc[i - 1] << ' ';
  }
  cout << n - vc[vc.size() - 1];
}
