// Arup Guha
// 6/15/2023
// Solution to SIUCF CP Contest 2 Problem: Greedily Increasing
// https://open.kattis.com/problems/greedilyincreasing

using namespace std;
#include <bits/stdc++.h>

int main() {

    int n, tmp;
    cin >> n;
    int res = 0, cur = 0;
    vector<int> nums;

    // Go through each number.
    for (int i=0; i<n; i++) {
        cin >> tmp;

        // We beat the old one, add 1 and update max.
        if (tmp > cur) {
            res++;
            nums.push_back(tmp);
            cur = tmp;
        }
    }

    // Ta da!
    cout << res << endl;
    for (int i=0; i<nums.size(); i++)
        cout << nums[i] << " ";
    cout << endl;

    return 0;
}
