#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1(n);
  for (int i = 0; i < n; i++) {
    cin >> v1[i];
  }
  vector<int> storage;
  int stairways = 1;
  for (int i = 0; i < n - 1; i++) {
    if (v1[i] > v1[i + 1] || v1[i] == 1 && v1[i + 1] == 1) {
      storage.push_back(v1[i]);
      stairways++;
    }
  }
  int stored = accumulate(storage.begin(), storage.end(), 0);
  int rem = n - stored;
  storage.push_back(rem);
  cout << stairways << endl;
  for (auto &x : storage) cout << x << " ";
}
