CF2130A.Submission is All You Need

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

Submission is All You Need

For a multiset TT consisting of non-negative integers, we define:

  • sum(T)\text{sum}(T) is the sum of all elements in TT. For example, if T={0,1,1,3}T = \{0,1, 1, 3\}, then sum(T)=0+1+1+3=5\text{sum}(T)= 0+1+1+3=5.
  • mex(T)\text{mex}(T) is the smallest non-negative integer not in TT. For example, if T={0,1,1,3}T = \{0,1, 1, 3\}, then mex(T)=2\text{mex}(T) = 2 because 22 is the smallest non-negative integer not present in TT.

You are given a multiset SS of size nn consisting of non-negative integers. At first, your score is 00. You can perform the following operations any number of times in any order (possibly zero):

  • Select a subset SubseteqSS' ubseteq S (i.e., SS' contains some of the elements currently in SS), add sum(S)\text{sum}(S') to your score, and then remove SS' from SS.
  • Select a subset SubseteqSS' ubseteq S, add mex(S)\text{mex}(S') to your score, and then remove SS' from SS.

Find the maximum possible score that can be obtained.

Input

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

The first line of each test case contains a single integer nn (1n501 \le n \le 50).

The second line of each test case contains nn integers S1,S2,,SnS_1, S_2, \ldots, S_n (0Si500 \le S_i \le 50).

Output

For each test case, print a single integer — the maximum possible score that can be obtained.

Note

In the first test case, a possible optimal strategy is as follows:

  • Select S={0,1}S'=\{0,1\}, add mex(S)=mex({0,1})=2\text{mex}(S')=\text{mex}(\{0,1\})=2 to your score, and then remove SS' from SS. Currently, your score is 22 and S={1}S=\{1\}.
  • Select S={1}S'=\{1\}, add sum(S)=sum({1})=1\text{sum}(S')=\text{sum}(\{1\})=1 to your score, and then remove SS' from SS. Currently, your score is 33 and S=S=\varnothing.

After that, you cannot do any further operations. It can be proven that 33 is the maximum possible score that can be obtained.

Samples

2
3
0 1 1
3
1 2 3
3
6

在线编程 IDE

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