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