CF2157A Dungeon Equilibrium

Description

[HyperSmawk - Hype](https://soundcloud.com/hypersmawk/hype) ⠀ An array is called balanced if every integer $ x $ that occurs at least once, occurs exactly $ x $ times in the array. For example, $ [1, 4, 2, 4, 4, 4, 2] $ is balanced, but $ [2] $ and $ [2, 2, 2] $ are not. You are given an array $ a $ of $ n $ elements, $ [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 Format

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 500 $ ). The description of the test cases follows. The first line of each test case contains an integer $ n $ ( $ 1 \leq n \leq 100 $ ) — the size of the array $ a $ . The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \leq a_i \leq n $ ) — the elements of the array $ a $ . Note that there are no constraints on the sum of $ n $ over all test cases.

Output Format

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.

Explanation/Hint

In the first test case, the given array is already balanced. In the second test case, we can delete one occurrence of $ 1 $ and one occurrence of $ 3 $ to get the array $ [1, 2, 2] $ which is balanced.