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