#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int mas[n];
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
  }
  for (int i = 0; i < n; i++) {
    if (mas[i] == 1) c++;
  }
  cout << c << endl;
  for (int i = 1; i < n; i++) {
    if (mas[i] == 1) cout << mas[i - 1] << " ";
  }
  cout << mas[n - 1];
}
