CF BUDDY
← Problems·

1343D · Constant Palindrome Sum

1700 · brute force, data structures, greedy

Problem: You are given an array aa consisting of nn integers (it is guaranteed that nn is even, i.e. divisible by 22). All aia_i does not exceed some integer kk.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index ii from 11 to nn and replace aia_i with some integer in range [1;k][1; k]) to satisfy the following conditions:

  • after all replacements, all aia_i are positive integers not greater than kk;
  • for all ii from 11 to n2\frac{n}{2} the following equation is true: ai+ani+1=xa_i + a_{n - i + 1} = x, where xx should be the same for all n2\frac{n}{2} pairs of elements.

You have to answer tt independent test cases.

Input Format: The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and kk (2n2105,1k21052 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5) — the length of aa and the maximum possible value of some aia_i correspondingly. It is guratanteed that nn is even (i.e. divisible by 22). The second line of the test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1aik1 \le a_i \le k), where aia_i is the ii-th element of aa.

It is guaranteed that the sum of nn (as well as the sum of kk) over all test cases does not exceed 21052 \cdot 10^5 (n2105\sum n \le 2 \cdot 10^5, k2105\sum k \le 2 \cdot 10^5).

Output Format: For each test case, print the answer — the minimum number of elements you have to replace in aa to satisfy the conditions from the problem statement.

Sample Cases

Case 1

Input

4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4

Output

0
1
4
2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback