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