#include <bits/stdc++.h>
using namespace std;
constexpr unsigned NMax = 10005;
constexpr short NrMin = -30001;
short x;
int n, a, b, c, sol = 1;
deque<short> maxime({NrMin, NrMin, NrMin});
int main()
{
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> x;
if(x > maxime.front()) {
maxime.pop_back();
maxime.push_front(x);
}
}
while(!maxime.empty()) {
cout << maxime.front() << ' ';
maxime.pop_front();
}
return 0;
}