#include <bits/stdc++.h>
using namespace std;
int res[1002];
int main() {
  int a[1002];
  memset(res, false, sizeof(res));
  int n, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    if (a[i + 1] == 1 || i == n - 1) {
      ++cnt;
      res[cnt] = a[i];
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= 1000; ++i) {
    if (res[i]) cout << res[i] << ' ';
  }
  return 0;
}
