#include <bits/stdc++.h>
using namespace std;
int n, i, sum, a[1001];
int main() {
  cin >> n;
  while (cin >> a[++i])
    if (a[i] == 1) sum++;
  cout << sum << endl;
  for (int i = 1; i < n; i++)
    if (a[i + 1] == 1) cout << a[i] << " ";
  cout << a[n] << endl;
  return 0;
}
