Codeforces Round 960 (Div. 2) |
---|
Finished |
We define the $$$\operatorname{MAD}$$$ (Maximum Appearing Duplicate) in an array as the largest number that appears at least twice in the array. Specifically, if there is no number that appears at least twice, the $$$\operatorname{MAD}$$$ value is $$$0$$$.
For example, $$$\operatorname{MAD}([1, 2, 1]) = 1$$$, $$$\operatorname{MAD}([2, 2, 3, 3]) = 3$$$, $$$\operatorname{MAD}([1, 2, 3, 4]) = 0$$$.
You are given an array $$$a$$$ of size $$$n$$$. Initially, a variable $$$sum$$$ is set to $$$0$$$.
The following process will be executed in a sequential loop until all numbers in $$$a$$$ become $$$0$$$:
Find the value of $$$sum$$$ after the process.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.
For each test case, output the value of $$$sum$$$ in a new line.
41132 2 342 1 1 244 4 4 4
1 13 9 40
In the first test case, $$$a=[1]$$$ initially.
In the first loop:
After the first loop, $$$a=[0]$$$ and the process ends. The value of $$$sum$$$ after the process is $$$1$$$.
In the second test case, $$$a=[2,2,3]$$$ initially.
After the first loop, $$$a=[0,2,2]$$$ and $$$sum=7$$$.
After the second loop, $$$a=[0,0,2]$$$ and $$$sum=11$$$.
After the third loop, $$$a=[0,0,0]$$$ and $$$sum=13$$$. Then the process ends.
The value of $$$sum$$$ after the process is $$$13$$$.
Name |
---|