#include "bits/stdc++.h"
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> A;
for (int i = 0; i < n; ++i)
{
int x;
scanf("%d", &x);
A.push_back(x);
}
vector<int> R;
int mx = 0;
for (int i = n-1; i >=0; --i)
{
if (A[i] > mx)
{
mx = A[i];
R.push_back(A[i]);
}
}
reverse(R.begin(), R.end());
cout << R.size() << endl;
for (int i = 0; i < R.size(); ++i)
cout << R[i] << ' ';
cout << endl;
}