#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int cnt = 0;
  int cnt2 = 1;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) {
      cnt++;
      v.push_back(cnt2);
      cnt2 = 1;
    } else
      cnt2++;
  }
  v.push_back(cnt2);
  cout << cnt << "\n";
  for (int i = 1; i < v.size(); i++) cout << v[i] << " ";
}
