#include <bits/stdc++.h>
int main() {
  int n, num, pn;
  std::cin >> n;
  std::vector<int> vi, vir;
  while (n--) {
    std::cin >> num;
    vi.push_back(num);
  }
  for (size_t i = 0; i < vi.size(); i++) {
    if (vi[i] == 1 && i != 0) {
      vir.push_back(vi[i - 1]);
    }
  }
  vir.push_back(vi[vi.size() - 1]);
  std::cout << vir.size() << std::endl;
  bool fst = true;
  for (size_t i = 0; i < vir.size(); i++) {
    std::cout << (fst ? "" : " ") << vir[i];
    fst = false;
  }
  return 0;
}
