CF1834A.Unit Array

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

Unit Array

Given an array aa of length nn, which elements are equal to 1-1 and 11. Let's call the array aa good if the following conditions are held at the same time:

  • a1+a2++an0a_1 + a_2 + \ldots + a_n \ge 0;
  • a1a2an=1a_1 \cdot a_2 \cdot \ldots \cdot a_n = 1.

In one operation, you can select an arbitrary element of the array aia_i and change its value to the opposite. In other words, if ai=1a_i = -1, you can assign the value to ai:=1a_i := 1, and if ai=1a_i = 1, then assign the value to ai:=1a_i := -1.

Determine the minimum number of operations you need to perform to make the array aa good. It can be shown that this is always possible.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t5001 \le t \le 500) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1001 \le n \le 100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (ai=±1a_i = \pm 1) — the elements of the array aa.

Output

For each test case, output a single integer — the minimum number of operations that need to be done to make the aa array good.

Note

In the first test case, we can assign the value a1:=1a_1 := 1. Then $a_1 + a_2 + a_3 + a_4 = 1 + (-1) + 1 + (-1) = 0 \ge 0$ and $a_1 \cdot a_2 \cdot a_3 \cdot a_4 = 1 \cdot (-1) \cdot 1 \cdot (-1) = 1$. Thus, we performed 11 operation.

In the second test case, we can assign a1:=1a_1 := 1. Then $a_1 + a_2 + a_3 + a_4 + a_5 = 1 + (-1) + (-1) + 1 + 1 = 1 \ge 0$ and $a_1 \cdot a_2 \cdot a_3 \cdot a_4 \cdot a_5 = 1 \cdot (-1) \cdot (-1) \cdot 1 \cdot 1 = 1$. Thus, we performed 11 operation.

In the third test case, $a_1 + a_2 + a_3 + a_4 = (-1) + 1 + (-1) + 1 = 0 \ge 0$ and $a_1 \cdot a_2 \cdot a_3 \cdot a_4 = (-1) \cdot 1 \cdot (-1) \cdot 1 = 1$. Thus, all conditions are already satisfied and no operations are needed.

In the fourth test case, we can assign the values a1:=1,a2:=1,a3:=1a_1 := 1, a_2 := 1, a_3 := 1. Then a1+a2+a3=1+1+1=30a_1 + a_2 + a_3 = 1 + 1 + 1 = 3 \ge 0 and a1a2a3=111=1a_1 \cdot a_2 \cdot a_3 = 1 \cdot 1 \cdot 1 = 1. Thus, we performed 33 operations.

Samples

7
4
-1 -1 1 -1
5
-1 -1 -1 1 1
4
-1 1 -1 1
3
-1 -1 -1
5
1 1 1 1 1
1
-1
2
-1 -1
1
1
0
3
0
1
2

在线编程 IDE

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