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

京公网安备 11010502036488号