#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long c = 1;
  vector<long long> ans;
  long long i = 1;
  if (n == 1) {
    cout << 1 << endl;
    cout << 1 << endl;
    return 0;
  }
  while (i < n) {
    if (a[i] != 1) {
      c++;
    } else {
      ans.push_back(c);
      c = 1;
    }
    i++;
  }
  ans.push_back(c);
  cout << ans.size() << endl;
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
