#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, index = 0;
  cin >> n;
  int c[n], a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i] == 1) {
      c[index] = a[i - 1];
      index++;
    }
  }
  c[index] = a[n - 1];
  index++;
  cout << index << endl;
  for (int i = 0; i < index; i++) {
    cout << c[i] << ' ';
  }
  cout << endl;
  return 0;
}
