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