#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int n;
  cin >> n;
  int a[n];
  cin >> a[0];
  int ans1 = 1;
  int ans2 = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1 && i != n - 1) {
      ans1++;
      v.push_back(ans2);
      ans2 = 1;
    } else if (a[i] != 1 && i != n - 1) {
      ans2++;
    } else {
      if (a[i] != 1) {
        v.push_back(ans2 + 1);
      } else {
        ans1 = ans1 + 1;
        v.push_back(ans2);
        v.push_back(1);
      }
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    cout << 1;
  } else {
    cout << ans1 << endl;
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  }
}
