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
- 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
Input Specification
The first line contains a single integer
The first line of each test case contains a single integer
The second line of each test case contains
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,
- 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