CF2042B.Game with Colored Marbles

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

Game with Colored Marbles

Alice and Bob play a game. There are nn marbles, the ii-th of them has color cic_i. The players take turns; Alice goes first, then Bob, then Alice again, then Bob again, and so on.

During their turn, a player must take one of the remaining marbles and remove it from the game. If there are no marbles left (all nn marbles have been taken), the game ends.

Alice's score at the end of the game is calculated as follows:

  • she receives 11 point for every color xx such that she has taken at least one marble of that color;
  • additionally, she receives 11 point for every color xx such that she has taken all marbles of that color (of course, only colors present in the game are considered).

For example, suppose there are 55 marbles, their colors are [1,3,1,3,4][1, 3, 1, 3, 4], and the game goes as follows: Alice takes the 11-st marble, then Bob takes the 33-rd marble, then Alice takes the 55-th marble, then Bob takes the 22-nd marble, and finally, Alice takes the 44-th marble. Then, Alice receives 44 points: 33 points for having at least one marble for colors 11, 33 and 44, and 11 point for having all marbles of color 44. Note that this strategy is not necessarily optimal for both players.

Alice wants to maximize her score at the end of the game. Bob wants to minimize it. Both players play optimally (i. e. Alice chooses a strategy which allows her to get as many points as possible, and Bob chooses a strategy which minimizes the amount of points Alice can get).

Calculate Alice's score at the end of the game.

Input

The first line contains one integer tt (1t10001 \le t \le 1000) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer nn (1n10001 \le n \le 1000) — the number of marbles;
  • the second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1cin1 \le c_i \le n) — the colors of the marbles.

Additional constraint on the input: the sum of nn over all test cases does not exceed 10001000.

Output

For each test case, print one integer — Alice's score at the end of the game, assuming that both players play optimally.

Note

In the second test case of the example, the colors of all marbles are distinct, so, no matter how the players act, Alice receives 44 points for having all marbles of two colors, and no marbles of the third color.

In the third test case of the example, the colors of all marbles are the same, so, no matter how the players act, Alice receives 11 point for having at least one (but not all) marble of color 44.

Samples

3
5
1 3 1 3 4
3
1 2 3
4
4 4 4 4
4
4
1

在线编程 IDE

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