문제
Farmer John has cows in a line . The 'th cow from the front of line is labeled an integer (). Multiple cows may be labeled the same integer.
FJ will construct another line in the following manner: Initially, is empty. While is nonempty, remove the cow at the front of and potentially add that cow to the back of .
FJ wants to construct line such that the sequence of labels in from front to back is lexicographically greatest (see the footnote).
Before FJ constructs line , he can perform the following operation at most once:
Choose a cow in line and move it anywhere before its current position.
Given that FJ optimally performs the aforementioned operation at most once, output the lexicographically greatest label sequence of he can achieve.
Each input will consist of () independent test cases.
입력
The first line contains .
The first line of each test case contains .
The second line of each test case contains space-separated integers .
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output the lexicographically greatest on a new line.
예제 입력 1
3
5
4 3 2 1 3
6
5 1 2 6 3 4
6
4 1 3 2 1 1
예제 출력 1
4 3 3 2 1
6 5 4
4 3 2 1 1
점수
Inputs 2-4: Inputs 5-8: Inputs 9-18: No additional constraints
코드를 제출하려면 로그인이 필요합니다.
로그인