#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[1001];
  for (int i = 0; i < n; i++) cin >> a[i];
  int count1 = 1, count2 = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1] + 1)
      continue;
    else
      count1++;
  }
  cout << count1 << endl;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i + 1] - 1)
      count2++;
    else {
      cout << count2 << " ";
      count2 = 1;
    }
  }
}
