have a change: a cluster a=[a1,a2,… ,an] of unmistakable whole numbers from 1 to n. The length of the change n is odd. You need to sort the change in expanding request. In one stage, you can pick any prefix of the change with an odd length and opposite it. Officially, if a=[a1,a2,… ,an], you can pick any odd number p among 1 and n, comprehensive, and set a to [ap,ap−1,… ,a1,ap+1,ap+2,… ,an]. Figure out how to sort
Python
You have a change: a cluster a=[a1,a2,… ,an] of unmistakable whole numbers from 1 to n. The length of the change n is odd.
You need to sort the change in expanding request. In one stage, you can pick any prefix of the change with an odd length and opposite it. Officially, if a=[a1,a2,… ,an], you can pick any odd number p among 1 and n, comprehensive, and set a to [ap,ap−1,… ,a1,ap+1,ap+2,… ,an].
Figure out how to sort a utilizing close to 5n2 inversions of the above kind, or establish that such a way doesn't exist. The quantity of inversions doesn't need to be limited.
Information : Each test contains numerous experiments. The primary line contains the quantity of experiments t (1≤t≤100). Depiction of the experiments follows. The principal line of each experiment contains a solitary whole number n (3≤n≤2021; n is odd) — the length of the change.
The subsequent line contains n particular whole numbers a1,a2,… ,an (1≤
It is ensured that the amount of n over all experiments doesn't surpass 2021.
Yield :For each experiment, in case it's difficult to sort the given change in all things considered 5n2 inversions, print a solitary whole number −1.
In any case, print a number m (0≤m≤5n2), indicating the quantity of inversions in your arrangement of steps, trailed by m whole numbers pi (1≤pi≤n; pi is odd), signifying the lengths of the prefixes of a to be turned around, in sequential request. Note that m doesn't need to be limited. In case there are different replies, print any
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images