#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b = 0;
  int m[1004];
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> m[i];
    if (m[i] == 1) b++;
  }
  cout << b << endl;
  for (int i = 0; i < a; i++) {
    if ((i == a - 1) || (m[i + 1] == 1)) cout << m[i] << " ";
  }
  return 0;
}
