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