#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1000 + 10;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
  int n;
  int cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] == 1) printf("%d ", a[i]);
  }
  printf("%d\n", a[n - 1]);
}
