CF2157A.Dungeon Equilibrium

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

Dungeon Equilibrium

HyperSmawk - Hype

An array is called balanced if every integer xx that occurs at least once, occurs exactly xx times in the array. For example, [1,4,2,4,4,4,2][1, 4, 2, 4, 4, 4, 2] is balanced, but [2][2] and [2,2,2][2, 2, 2] are not.

You are given an array aa of nn elements, [a1,a2,,an][a_1, a_2, \ldots, a_n]. The array may not be balanced currently, and you can delete some elements to make it balanced. What is the minimum number of elements you need to delete to make the array balanced?

Input

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

The first line of each test case contains an integer nn (1n1001 \leq n \leq 100) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ain0 \leq a_i \leq n) — the elements of the array aa.

Note that there are no constraints on the sum of nn over all test cases.

Output

For each test case, output a single line containing an integer: the minimum number of elements you should remove from the array to make it balanced.

Note

In the first test case, the given array is already balanced.

In the second test case, we can delete one occurrence of 11 and one occurrence of 33 to get the array [1,2,2][1, 2, 2] which is balanced.

Samples

4
3
1 2 2
5
1 1 2 2 3
10
1 2 3 2 4 4 4 4 5 2
1
0
0
2
3
1

在线编程 IDE

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