## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Different Subarrays Rearrange CodeChef Solution | CodeChef Problem Solution 2022

You are given an array $A$ of $N$ integers ${A}_{1},{A}_{2},\dots ,{A}_{N}$. Determine if there are two permutations $B$ and $C$ of this array, for which the following condition is satisfied:

• There doesn't exist a pair of integers $\left(i,j\right)$ such that $1\le i\le j\le N$ and $\left(i,j\right)\ne \left(1,N\right)$, for which the subarray $B\left[i:j\right]$ is a permutation of subarray $C\left[i:j\right]$.

If there exist such permutations, find any of them.

As a reminder, $B\left[i:j\right]$ refers to the subarray $\left[{B}_{i},{B}_{i+1},\dots ,{B}_{j}\right]$

### Input Format

• The first line of the input contains a single integer $T$, the number of test cases. The description of the test cases follows.

• The first line of each test case contains a single integer $N$ — the number of integers.
• The second line of each test case contains $N$ space-separated integers ${A}_{1},{A}_{2},\dots ,{A}_{N}$.

### Output Format

For each test case, if there are no such permutations $B$ and $C$, output NO.

Otherwise, on the first line output YES. In the next line, output $N$ integers ${B}_{1},{B}_{2},\dots ,{B}_{N}$. In the next line, output $N$ integers ${C}_{1},{C}_{2},\dots ,{C}_{N}$.

You may print each character of YES/NO in either uppercase or lowercase (for example, the strings YESyeSYeS, and yEs will all be treated as identical).

### Constraints

• $1\le T\le 100$
• $3\le N\le 1000$
• $0\le {A}_{i}\le {10}^{9}$
• The sum of $N$ over all test cases doesn't exceed $2000$.

### Sample Input 1

3
3
1 1 2
4
19 39 19 84
6
1 2 3 1 2 3


### Sample Output 1

NO
YES
19 19 39 84
39 84 19 19
YES
1 1 2 2 3 3
2 3 3 1 1 2 
Join Now for Solution:- 