#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n;
int a[N];
vector<int> res;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  a[n] = 1;
  for (int i = 0; i < n; i++)
    if (a[i + 1] == 1) res.push_back(a[i]);
  printf("%lu\n", res.size());
  for (int i = 0; i < res.size(); i++) printf("%d ", res[i]);
  return 0;
}
