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