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