Kites

시간 제한2초메모리 제한256 MB

요약
막대 길이들이 주어질 때, 네 개를 골라 같은 길이 두 쌍을 만들기 위해 필요한 +1 연산의 최솟값을 구한다.
난이도

보통10점 중 6점

유형
정렬, 그리디, 완전 탐색, 배열
정답자
아직 제출이 없습니다

문제

Busy Beaver has a collection of NN sticks with integer lengths a_1,a_2,…,a_Na\_1, a\_2, \dots, a\_N and wants to make a kite. To do so, he needs to choose four different sticks from his collection with lengths aa, aa, bb, bb for some integers aa and bb (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 11. 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 TT (1≤T≤104)(1 \leq T \leq 10^4), the number of test cases. The description of each test case follows.

The first line of each test case contains a single positive integer NN (4≤N≤2⋅1054 \leq N \leq 2 \cdot 10^5) --- the number of sticks in Busy Beaver's collection.

The second line contains NN space separated integers a_1,a_2,…,a_Na\_1, a\_2, \dots, a\_N (1≤a_i≤1091 \leq a\_i \leq 10^9) --- the lengths of the sticks.

It is guaranteed that the sum of NN across all test cases is no more than 2⋅1052 \cdot 10^5.

출력

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 99 except for one that is length 11. The optimal way to create a kite is to apply the operation 88 times to the stick of length 11. We will then have four sticks of length 99, 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 99, 99, 2020, 2020, so the answer is 00.

In the third test case, it can be shown that the minimum number of operations needed is 22. One way to make a kite with 22 operations would be to extend the sticks of length 11 and 33 so that our collection of sticks has lengths 55, 44, 44, 22, 22. The last four sticks can then form a kite.

예제1

  1. 예제 1

    입력
    5
    4
    1 9 9 9
    5
    13 9 20 9 20
    5
    5 4 3 2 1
    7
    1 6 9 10 11 14 19
    10
    1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
    
    예상 출력
    8
    0
    2
    4
    909