#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  vector<int> v;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = n - 1; i >= 0;) {
    v.push_back(a[i]);
    i = i - a[i];
  }
  printf("%d\n", v.size());
  for (int i = v.size() - 1; i >= 0; i--) printf("%d ", v[i]);
  return 0;
}
