#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ch = getchar(), f = 1, ans = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    ans = (((ans << 2) + ans) << 1) + (ch ^ '0');
  return f ? ans : -ans;
}
queue<int> q;
int main() {
  int n = read();
  int ans = 0, cnt = 0;
  int s = 0, t = 0;
  for (int i = 1; i <= n; ++i) {
    t = read();
    if (t != s + 1)
      q.push(cnt), cnt = 1, ++ans;
    else
      ++cnt;
    s = t;
  }
  q.push(cnt);
  cout << ++ans << endl;
  while (!q.empty()) {
    cout << q.front() << ' ';
    q.pop();
  }
  return 0;
}
