#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  cin >> n;
  int arr[n];
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) c++;
    if (i && arr[i] == 1) vec.push_back(arr[i - 1]);
  }
  vec.push_back(arr[n - 1]);
  cout << c << endl;
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  return 0;
}
