A multiset is a collection of elements similar to a set, where elements can repeat multiple times. For example, the following is a multiset: .
Given a multiset defined on non-negative integers, and a target non-negative integer value such that does not belong to , your goal is to insert into by using the following 3-step operation, repeatedly:
- Choose a (possibly empty) subset of . Here, is a set of distinct numbers that appear in .
- Erase elements of from . (Remove only one copy of each element.)
- Insert into , where is the smallest non-negative integer that does not belong to . The name mex stands for "minimum excluded" value.
Your goal is to find the minimum number of operations to perform so that becomes part of . Since the size of may be large, it will be given in the form of a list of size , where represents the number of times that the number appears in . (Recall that is the integer we are trying to insert into .)
Input Specification
The first line contains a single integer — the number of test cases. Each two of the following lines describe a test case:
The first line of each test case contains a single integer , representing the integer to be inserted into .
The second line of each test case contains integers , representing the multiset as mentioned above.
Output Specification
For each test case, print a single line containing the minimum number of operations needed to satisfy the condition.
Sample Input
2
4
0 3 0 3
5
4 1 0 2 0
Sample Output
4
10
Explanation
In the first example, initially, and our goal is to have in . We can do the following:
- choose then becomes .
- choose then becomes .
- choose then becomes .
- choose then becomes .
Constraints
- Subtask 1 (5 points):
- Subtask 2 (17 points):
- Subtask 3 (7 points):
- Subtask 4 (9 points):
- Subtask 5 (20 points):
- Subtask 6 (9 points): and (for all )
- Subtask 7 (10 points): There exists a value for which and (for all ).
- Subtask 8 (23 points): No additional constraints
Comments