#include <bits/stdc++.h>
using namespace std;
vector<long long> taille;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long temp;
  long long nbEscaliers = 0;
  long long prec = 0;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    if (temp == 1 && prec) {
      taille.push_back(prec);
      nbEscaliers++;
    }
    if (i == n - 1) {
      taille.push_back(temp);
      nbEscaliers++;
    }
    prec = temp;
  }
  cout << nbEscaliers << '\n';
  for (auto i : taille) cout << i << ' ';
}
