#include <bits/stdc++.h>
using namespace std;
int ans[1005];
int main() {
  int n, x, t, cnt;
  cin >> n;
  t = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) {
      ans[t++] = cnt;
      cnt = 0;
    }
    cnt++;
  }
  ans[t] = cnt;
  cout << t << endl;
  for (int i = 1; i <= t; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
