CF1956B.Nene and the Card Game

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

Nene and the Card Game

You and Nene are playing a card game. The deck with 2n2n cards is used to play this game. Each card has an integer from 11 to nn on it, and each of integers 11 through nn appears exactly on 22 cards. Additionally, there is a table where cards are placed during the game (initially, the table is empty).

In the beginning of the game, these 2n2n cards are distributed between you and Nene so that each player receives nn cards.

After it, you and Nene alternatively take 2n2n turns, i.e. each person takes nn turns, starting with you. On each turn:

  • The player whose turn is it selects one of the cards in his hand. Let xx be the number on it.
  • The player whose turn is it receives 11 point if there is already a card with the integer xx on the table (otherwise, he receives no points). After it, he places the selected card with the integer xx on the table.

Note that turns are made publicly: each player can see all the cards on the table at each moment.

Nene is very smart so she always selects cards optimally in order to maximize her score in the end of the game (after 2n2n rounds). If she has several optimal moves, she selects the move that minimizes your score in the end of the game.

More formally, Nene always takes turns optimally in order to maximize her score in the end of the game in the first place and to minimize your score in the end of the game in the second place.

Assuming that the cards are already distributed and cards in your hand have integers a1,a2,,ana_1, a_2, \ldots, a_n written on them, what is the maximum number of points you can get by taking your turns optimally?

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of test cases follows.

The first line contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of cards you and Nene receive in the beginning of the game.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ain1 \le a_i \le n) — the integers on the cards in your hand. It is guaranteed that each integer from 11 through nn appears in the sequence a1,a2,,ana_1, a_2, \ldots, a_n at most 22 times.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output one integer: the maximum number of points you can get.

Note

In the first test case, the integers written on your cards are 11, 11, 22 and 33. The integers written on Nene's cards are 22, 33, 44 and 44. The game may proceed as follows:

  1. You select one of the cards with an integer 11 written on it and place it on the table.
  2. Nene selects one of the cards with an integer 44 written on it and places it on the table.
  3. You select the card with an integer 11 written on it, receive 11 point, and place the selected card on the table.
  4. Nene selects the card with an integer 44 written on it, receive 11 point, and places the selected card on the table.
  5. You select the card with an integer 22 written on it and place it on the table.
  6. Nene selects the card with an integer 22 written on it, receive 11 point, and places the selected card on the table.
  7. You select the card with an integer 33 written on it and place it on the table.
  8. Nene selects the card with an integer 33 written on it, receive 11 point, and places the selected card on the table.

At the end of the game, you scored 11 point, and Nene scored 33. It can be shown that you cannot score more than 11 point if Nene plays optimally, so the answer is 11.

In the second test case, if both players play optimally, you score 22 points and Nene scores 66 points.

Samples

5
4
1 1 2 3
8
7 4 1 2 8 8 5 5
8
7 1 4 5 3 4 2 6
3
1 2 3
1
1
1
2
1
0
0

在线编程 IDE

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