Kites
시간 제한2초메모리 제한256 MB
막대 길이들이 주어질 때, 네 개를 골라 같은 길이 두 쌍을 만들기 위해 필요한 +1 연산의 최솟값을 구한다.
문제
Busy Beaver has a collection of sticks with integer lengths and wants to make a kite. To do so, he needs to choose four different sticks from his collection with lengths , , , for some integers and (not necessarily distinct).
It might not be possible for Busy Beaver to make a kite using his current collection, but he is able to modify the sticks. In an operation, Busy Beaver can take a stick and extend its length by . Compute the minimum number of operations required to construct a kite of any size. It can be shown that it's always possible to make a kite after a finite number of operations.
입력
Each test contains multiple test cases. The first line of input contains a single integer , the number of test cases. The description of each test case follows.
The first line of each test case contains a single positive integer () --- the number of sticks in Busy Beaver's collection.
The second line contains space separated integers () --- the lengths of the sticks.
It is guaranteed that the sum of across all test cases is no more than .
출력
For each test case, output a single integer --- the minimum number of operations that Busy Beaver needs before he can make a kite.
힌트
In the first test case, there are four sticks, all of which are length except for one that is length . The optimal way to create a kite is to apply the operation times to the stick of length . We will then have four sticks of length , which we can use to make a kite.
In the second test case, there are five sticks. We do not need to apply any operations because we already have four sticks of lengths , , , , so the answer is .
In the third test case, it can be shown that the minimum number of operations needed is . One way to make a kite with operations would be to extend the sticks of length and so that our collection of sticks has lengths , , , , . The last four sticks can then form a kite.