#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  map<int, int> m;
  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      counter++;
    }
    m[counter] += 1;
  }
  cout << m.size() << endl;
  for (auto i = m.begin(); i != m.end(); i++) {
    cout << i->second << " ";
  }
}
