CF2149A.Be Positive

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Be Positive

Given an array aa of nn elements, where each element is equal to 1-1, 00, or 11. In one operation, you can choose an index ii and increase aia_i by 11 (that is, assign ai:=ai+1a_i := a_i + 1). Operations can be performed any number of times, choosing any indices.

The goal is to make the product of all elements in the array strictly positive with the minimum number of operations, that is, $a_1 \cdot a_2 \cdot a_3 \cdot \ldots \cdot a_n \gt 0$. Find the minimum number of operations.

It is guaranteed that this is always possible.

Input

Each test consists of several test cases.

The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains one integer nn (1n81 \le n \le 8) — the length of the array aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n, where 1ai1-1 \le a_i \le 1 — the elements of the array aa.

Output

For each test case, output one integer — the minimum number of operations required to make the product of the elements in the array strictly positive.

Note

In the first test case: from [1,0,1][-1, 0, 1], you can obtain [1,1,1][1, 1, 1] in 33 operations.

In the second test case: it is enough to perform 010 \to 1 (1 operation). In the resulting array a=[1,1,1,1]a=[-1,-1,1,1], the product of all elements is 11.

In the third test case: turning two zeros into ones (2 operations), and one 1-1 into 11 (another 2 operations), for a total of 44.

Samples

3
3
-1 0 1
4
-1 -1 0 1
5
-1 -1 -1 0 0
3
1
4

在线编程 IDE

建议全屏模式获得最佳体验