#include <iostream>
#include <stack>
using namespace std;
int main() {
int n, num;
cin >> n;
int i = n;
stack<int> s;
while (n--) {
cin >> num;
s.push(num);
while (!s.empty() && s.top() == i) {
cout << s.top() << " ";
s.pop();
i--;
}
}
while (!s.empty()) {
cout << s.top() << " ";
s.pop();
i--;
}
return 0;
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号