You are given an array of nn integers a1,a2,...,ana1,a2,...,an. We define that a sequence p1,p2,...,pk(k∈[1,n])p1,p2,...,pk(k∈[1,n]) is beautiful if and only if these conditions are met:
∙∙1≤p1<p2<⋯<pk≤n.1≤p1<p2<⋯<pk≤n.
∙∙ There exists t(t∈[1,k])t(t∈[1,k]) satisfying ap1<ap2<⋯<aptap1<ap2<⋯<apt and apt>apt+1>⋯>apkapt>apt+1>⋯>apk.
You need to find all the longest beautiful sequences, and output the lexicographically smallest one and the lexicographically largest one in them.
Check the examples below for better understanding.
Input
There are multiple test cases.
Each case starts with a line containing a positive integer n(n≤3×105)n(n≤3×105).
The second line contains nn integers a1,a2,...,an(1≤ai≤109)a1,a2,...,an(1≤ai≤109).
It is guaranteed that the sum of NNs in all test cases is no larger than 106106.
Output
For each test case, output two lines, the first of which depicts the lexicographically smallest one in longest beautiful sequences and the second of which depicts the lexicographically largest one in longest beautiful sequences.