#ds401. 笛卡尔树
笛卡尔树
Cartesian Tree
Problem Description
You are given a permutation of .
Find a permutation of such that for any interval (), the position of the minimum among equals the position of the minimum among .
Output the lexicographically smallest such .
Input Format
The first line contains an integer ().
The next line contains a permutation of length .
Output Format
One line with numbers , the lexicographically smallest permutation.
Sample Input
5
4 3 1 5 2
Sample Output
3 2 1 5 4