#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  std::vector<int> ans;
  int j = 1;
  int i = 1;
  while (i < n) {
    if (arr[i] == 1) {
      ans.push_back(j);
      j = 1;
    } else
      ++j;
    ++i;
  }
  ans.push_back(j);
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << " ";
  }
}
