Array

아직 제출이 없습니다시간 제한5초메모리 제한256 MB

문제

Chiaki has an array of integers a_1,a_2,,a_na\_1,a\_2,\dots, a\_n. Chaiki can replace an element a_xa\_x to another integer yy. Let the resulting array be b_1,b_2,,b_nb\_1,b\_2,\dots,b\_n, Chiaki would like to know the minimum value of a_xy+_k=1nkc_k|a\_x-y| + \sum\limits\_{k=1}^{n} k \cdot c\_k, where c_kc\_k is the number of distinct integers in b_1,b_2,,b_kb\_1,b\_2,\dots,b\_k.

입력

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains an integer nn (1n1061 \le n \le 10^6) -- the length of the array.

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \dots, a\_n (1a_i1091 \le a\_i \le 10^9).

It is guaranteed that the sum of nn in all test cases will not exceed 10610^6.

출력

For each test case, output an integer denoting the answer.