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