#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
long long a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 1;
  vector<long long> ans;
  for (int i = 0; i < n; i++) {
    if (a[i + 1] == 1) ans.push_back(a[i]);
  }
  cout << ans.size() << endl;
  for (auto u : ans) cout << u << ' ';
  return (0);
}
