#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int curr, nums;
int max = 0;
cin >> nums;
queue<int> q;
while(nums--){
cin >> curr;
if(max < curr){
max = curr;
q.push(curr);
}
}
cout << q.size() << endl;
while(q.size()){
cout << q.front() << " " ;
q.pop();
}
return 0;
}