CF2049A.MEX Destruction

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

MEX Destruction

Evirir the dragon snuck into a wizard's castle and found a mysterious contraption, and their playful instincts caused them to play with (destroy) it...

Evirir the dragon found an array a1,a2,,ana_1, a_2, \ldots, a_n of nn non-negative integers.

In one operation, they can choose a non-empty subarray^{\text{∗}} bb of aa and replace it with the integer mex(b)\operatorname{mex}(b)^{\text{†}}. They want to use this operation any number of times to make aa only contain zeros. It can be proven that this is always possible under the problem constraints.

What is the minimum number of operations needed?

^{\text{∗}}An array cc is a subarray of an array dd if cc can be obtained from dd by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

^{\text{†}}The minimum excluded (MEX) of a collection of integers f1,f2,,fkf_1, f_2, \ldots, f_k is defined as the smallest non-negative integer xx which does not occur in the collection ff.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t2001 \le t \le 200). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n501 \le n \le 50), the length of aa.

The second line of each test case contains nn space-separated integers, a1,a2,,ana_1, a_2, \ldots, a_n (0ai1000 \le a_i \le 100).

It is guaranteed that the sum of nn over all test cases does not exceed 500500.

Output

For each test case, output a single integer on a line, the minimum number of operations needed to make aa contain only zeros.

Note

In the first test case, Evirir can choose the subarray b=[1,2,3]b = [1, 2, 3] and replace it with mex(1,2,3)=0\operatorname{mex}(1, 2, 3) = 0, changing aa from [0,1,2,3][0, \underline{1, 2, 3}] to [0,0][0, 0] (where the chosen subarray is underlined). Therefore, the answer is 11.

In the second test case, aa already contains only 00s, so no operation is needed.

In the third test case, Evirir can change aa as follows: $[1, \underline{0, 1, 0, 1}] \to [\underline{1, 2}] \to [0]$. Here, mex(0,1,0,1)=2\operatorname{mex}(0, 1, 0, 1) = 2 and mex(1,2)=0\operatorname{mex}(1, 2) = 0.

In the fourth test case, Evirir can choose bb to be the entire array aa, changing aa from [3,1,4,1,5][\underline{3, 1, 4, 1, 5}] to [0][0].

Samples

10
4
0 1 2 3
6
0 0 0 0 0 0
5
1 0 1 0 1
5
3 1 4 1 5
4
3 2 1 0
7
9 100 0 89 12 2 3
4
0 3 9 0
7
0 7 0 2 0 7 0
1
0
2
0 1
1
0
2
1
1
2
1
2
0
1

在线编程 IDE

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