#include <bits/stdc++.h>
using namespace std;
void Solve() {
  string s;
  cin >> s;
  long long n;
  cin >> n;
  long long p = s.size();
  long long check[p];
  char ans[p];
  memset(check, 1, sizeof(check));
  memset(ans, 0, sizeof(ans));
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      if (i - n >= 0) {
        check[i - n] = 0;
      } else if (i + n < p) {
        check[i + n] = 1;
      }
    }
  }
  for (long long i = 0; i < s.size(); i++) {
    if (i - n >= 0 and check[i - n] == '1') {
      ans[i] = '1';
    } else if (i + n < n and check[i + n] == '1') {
      ans[i + n] = '1';
    } else {
      ans[i] = '0';
    }
  }
  bool flag = false;
  for (long long i = 0; i < p; i++) {
    if (ans[i] != check[i]) {
      flag = true;
    }
  }
  if (flag) {
    cout << "-1" << endl;
  } else {
    for (long long i = 0; i < p; i++) {
      cout << check[i];
    }
    cout << endl;
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> m(n + 1);
  vector<long long> v;
  vector<long long> v1;
  for (long long i = 0; i < n; i++) {
    cin >> m[i];
  }
  m.push_back(0);
  for (long long i = 0; i < m.size(); i++) {
    if (m[i + 1] > m[i]) {
      v.push_back(m[i]);
    } else {
      v1.push_back(m[i]);
    }
  }
  long long c = 0;
  for (auto i = v1.begin(); i != v1.end(); i++) {
    if (*i != 0) {
      c += 1;
    }
  }
  cout << c << endl;
  for (auto i = v1.begin(); i != v1.end(); i++) {
    if (*i != 0) {
      cout << *i << " ";
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, k = 1;
  solve();
}
