#include <bits/stdc++.h>
using namespace std;
int bs(vector<int>& a, int que) {
  auto it = lower_bound(a.begin(), a.end(), que);
  if (*it == que) {
    return it - a.begin();
  }
  return -1;
}
bool isprime(int x) {
  if (x == 2) return true;
  if (x < 2) return false;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  if (x == 0) return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  int a[10001];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> sol;
  sol.push_back(a[n]);
  for (int i = n; i >= 2; i--) {
    if (a[i] == 1) {
      sol.push_back(a[i - 1]);
    }
  }
  reverse(sol.begin(), sol.end());
  cout << sol.size() << endl;
  for (int i = 0; i <= sol.size() - 1; i++) {
    cout << sol[i] << " ";
  }
  return 0;
}
