#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int arr[n + 1];
  for (long long i = 0; i < (n); ++i) cin >> arr[i];
  arr[n] = 0X3f3f3f3f;
  vector<int> ans;
  int cnt = 1;
  for (long long i = 0; i < (n); ++i)
    if (arr[i] == arr[i + 1] - 1)
      ++cnt;
    else {
      ans.push_back(cnt);
      cnt = 1;
    }
  cout << ans.size() << '\n';
  for (int x : ans) cout << x << " ";
  cout << '\n';
  return 0;
}
