#include<bits/stdc++.h>
using namespace std;
stack<int>s;int n,temp,k{0};
int main(){
cin>>n;
for(int i=n;i>=1;){
cin>>temp;++k;
if (k<=n) {
s.push(temp);
}
if (s.empty()) {
break;
}
if (s.top()==i) {
cout<<s.top()<<' ';s.pop();i--;
}
if (k>n&&s.top()!=i) {
cout<<s.top()<<' ';s.pop();
}
}
return 0;
}

京公网安备 11010502036488号