#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, sum = 1, sum2 = 2, t = 0, k = 0;
  cin >> n;
  int a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    if (a[i] == 1) t++;
    if (a[i + 1] == 1 || i == n - 1) {
      b[k] = a[i];
      k++;
    }
  }
  cout << t << "\n";
  for (i = 0; i < k; i++) {
    cout << b[i] << " ";
  }
}
