Symmetry Shuffle
You are given an array of integers a1,a2,…,an. Your task is to make the array symmetrical with the minimum number of operations.
Definition of a Symmetric Array: An array b1,b2,…,bn is considered symmetrical if bi=bn−i+1 for all 1≤i≤n.
Operations Allowed: Before performing any operations, you may shuffle the elements of the array in any order you like. Then, you can perform the following operation any number of times:
- Choose an index 1≤i≤n and increment the value of ai by 1, i.e., set ai=ai+1.
Objective: Determine the minimum number of operations required to make the array symmetrical.
It's guaranteed that you can always make an array symmetrical.
Input Format:
- The first line of the input contains a single integer t (1≤t≤104) — the number of test cases.
- The first line of each test case contains a single integer n (1≤n≤105) — the number of elements in the array. The sum of n over all sets of input data does not exceed 105.
- The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.
Output Format: For each test case, output the minimum number of operations required to make the array symmetrical.
Examples
Input
3
4
1 3 3 1
5
2 3 3 2 1
3
1 2 3
Output
0
0
1
-
An array of 4 elements: 1 3 3 1.
-
An array of 5 elements: 2 2 1 3 3.
-
move 1 to the middle to get 2 1 3 and add 1 to 2 to get 3 1 3
Input
4
4
7 1 5 3
7
1 8 2 16 8 16 31
5
11 2 15 7 10
13
2 1 1 3 3 11 12 22 45 777 777 1500 74
Output
4
1
6
48
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.