#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
long long int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ones = 0, prev = -1, x;
  vector<long long int> res;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x == 1) {
      ++ones;
      res.push_back(prev);
    }
    prev = x;
  }
  res.push_back(x);
  cout << ones << endl;
  for (int i = 1; i < res.size(); ++i) cout << res[i] << " ";
  cout << endl;
  return 0;
}
