#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; int max=n; int index=0; vector<long long> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); if (a[index]==max) { cout<<a[index]<<' '; a.pop_back(); max--; index--; } index++; } index--; for (int i=0; i<max; i++) { cout<<a[index]<<' '; a.pop_back(); index--; } }