#include <bits/stdc++.h>
using namespace std;
int a[1000000], c, d, n, b[100000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) c++;
    if (a[i] == 1 && i != 0) {
      b[d] = a[i - 1];
      d++;
    }
  }
  b[d] = a[n - 1];
  cout << c << endl;
  for (int i = 0; i < d + 1; i++) cout << b[i] << " ";
  return 0;
}
