#P7378. Coins

    ID: 6234 远端评测题 3500ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2023“钉耙编程”中国大学生算法设计超级联赛(9)

Coins

Problem Description

There are $n$ people playing a game, where $i-$th person has $a_i$ coins. In each round, they randomly choose two players. Then the first one should give one coin to the second. If someone leaves no coin after that, he leaves the game and the rest players continue the game until a player owns all the coins. Foreverlasting wants to know the expected number of rounds.

Input

The first line contains integer $t\ (1 \leq t \leq 10^2)$ --- the number of test cases.

For each of the next $t$ test cases, the format is:

The first line contains an integer $n\ (2\leq n\leq 10^5)$, representing the number of people.

The next line contains $n$ integers $a_i\ (1\leq a_i\leq 10^6)$, representing the number of coins that each person has.

(请不要使用 scanf 进行读入)

Output

For each case, output the expected number of rounds. The answer is guaranteed to be an integer.

1 3 1 1 1
3