#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
  int n;
  cin >> n;
  int sum = 0;
  a[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      sum++;
    }
  }
  cout << sum << endl;
  int k = 1;
  int res = 0;
  if (n == 1)
    cout << a[1] << endl;
  else {
    for (int i = 2; i <= n; i++) {
      if (a[i] == 1) {
        cout << a[i - 1] << " ";
      }
      if (i == n) cout << a[n] << endl;
    }
  }
  return 0;
}
