#include <bits/stdc++.h>
using namespace std;
int func(int *a, int k, int n) {
  int count = 0;
  for (int i = k; i < n; i++) {
    if (a[i + 1] == 1 || i == n - 1) {
      count++;
      return count;
      break;
    } else {
      count++;
    }
  }
}
int main() {
  int n;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      count++;
    }
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      int k = func(a, i, n);
      cout << k << " ";
    } else {
      continue;
    }
  }
}
