#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, c = 0;
  vector<int> a, b;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    a.push_back(t);
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) {
      c++;
    }
    if (a[i + 1] == 1) {
      b.push_back(a[i]);
    } else if (i == n - 1)
      b.push_back(a[i]);
  }
  cout << c << endl;
  for (int i = 0; i < b.size(); ++i) {
    cout << b[i] << " ";
  }
}
