#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) cin >> x;
  int cnt = 1;
  vector<int> cs;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i + 1] == 1) {
      cnt += 1;
      cs.push_back(a[i]);
    }
  }
  cs.push_back(a.back());
  cout << cnt << endl;
  for (auto x : cs) cout << x << " ";
}
