#include <bits/stdc++.h>
using namespace std;
long long n, x, kol = 0, pre = -1;
vector<long long> ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == 1) {
      kol++;
      ans.push_back(pre);
    }
    pre = x;
  }
  ans.push_back(pre);
  cout << kol << '\n';
  for (int i = 1; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
