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