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