#include <bits/stdc++.h>
using namespace std;
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1;
const ll INF = 1e18;
ld tic, tac;
void solve() {
  int n, count = 0;
  cin >> n;
  int i, a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) count++;
  }
  cout << count << '\n';
  for (i = 1; i < n; i++) {
    if (a[i] == 1) {
      cout << a[i - 1] << "  ";
    }
  }
  cout << a[n - 1] << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
