#include <bits/stdc++.h>
using namespace std;
int binarySearch(long long arr[], int l, int r, int x) {
  if (r >= l) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
vector<long long> divisor(long long n) {
  vector<long long> v;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
  }
  return v;
}
bool cmp(string a, string b) { return a.size() < b.size(); }
int main() {
  int n;
  cin >> n;
  vector<int> v(n), a(n);
  int p = -1;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n - 1; i++) {
    if (v[i + 1] <= v[i]) a[++p] = v[i];
  }
  a[++p] = v[n - 1];
  cout << p + 1 << "\n";
  for (int i = 0; i <= p; i++) cout << a[i] << " ";
}
