#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int steps[n];
  int ans = 0;
  list<int> res;
  for (int i = 0; i < n; i++) {
    cin >> steps[i];
    if (i > 0) {
      if (steps[i] == 1) {
        res.push_back(steps[i - 1]);
        ans++;
      }
    }
  }
  res.push_back(steps[n - 1]);
  ans++;
  cout << ans << endl;
  int val;
  list<int>::iterator it;
  for (it = res.begin(); it != res.end(); ++it) {
    cout << *it << " ";
  }
  putchar('\n');
}
