CF1678A.Tokitsukaze and All Zero Sequence

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

Tokitsukaze and All Zero Sequence

Tokitsukaze has a sequence aa of length nn. For each operation, she selects two numbers aia_i and aja_j (iji \ne j; 1i,jn1 \leq i,j \leq n).

  • If ai=aja_i = a_j, change one of them to 00.
  • Otherwise change both of them to min(ai,aj)\min(a_i, a_j).

Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to 00. It can be proved that the answer always exists.

Input

The first line contains a single positive integer tt (1t10001 \leq t \leq 1000) — the number of test cases.

For each test case, the first line contains a single integer nn (2n1002 \leq n \leq 100) — the length of the sequence aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1000 \leq a_i \leq 100) — the sequence aa.

Output

For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to 00.

Note

In the first test case, one of the possible ways to change all numbers in the sequence to 00:

In the 11-st operation, a1<a2a_1 \lt a_2, after the operation, a2=a1=1a_2 = a_1 = 1. Now the sequence aa is [1,1,3][1,1,3].

In the 22-nd operation, a1=a2=1a_1 = a_2 = 1, after the operation, a1=0a_1 = 0. Now the sequence aa is [0,1,3][0,1,3].

In the 33-rd operation, a1<a2a_1 \lt a_2, after the operation, a2=0a_2 = 0. Now the sequence aa is [0,0,3][0,0,3].

In the 44-th operation, a2<a3a_2 \lt a_3, after the operation, a3=0a_3 = 0. Now the sequence aa is [0,0,0][0,0,0].

So the minimum number of operations is 44.

Samples

3
3
1 2 3
3
1 2 2
3
1 2 0
4
3
2

在线编程 IDE

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