#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const long long INF = 1e9 + 7;
long long n, a[N];
vector<long long> v;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 2; i <= n; i++)
    if (a[i] == 1) v.push_back(a[i - 1]);
  v.push_back(a[n]);
  cout << v.size() << endl;
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
