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