CF1615A.Closing The Gap

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Closing The Gap

There are nn block towers in a row, where tower ii has a height of aia_i. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:

  • Choose two indices ii and jj (1i,jn1 \leq i, j \leq n; iji \neq j), and move a block from tower ii to tower jj. This essentially decreases aia_i by 11 and increases aja_j by 11.

You think the ugliness of the buildings is the height difference between the tallest and shortest buildings. Formally, the ugliness is defined as max(a)min(a)\max(a)-\min(a).

What's the minimum possible ugliness you can achieve, after any number of days?

Input

The first line contains one integer tt (1t10001 \leq t \leq 1000) — the number of test cases. Then tt cases follow.

The first line of each test case contains one integer nn (2n1002 \leq n \leq 100) — the number of buildings.

The second line of each test case contains nn space separated integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1071 \leq a_i \leq 10^7) — the heights of the buildings.

Output

For each test case, output a single integer — the minimum possible ugliness of the buildings.

Note

In the first test case, the ugliness is already 00.

In the second test case, you should do one operation, with i=1i = 1 and j=3j = 3. The new heights will now be [2,2,2,2][2, 2, 2, 2], with an ugliness of 00.

In the third test case, you may do three operations:

  1. with i=3i = 3 and j=1j = 1. The new array will now be [2,2,2,1,5][2, 2, 2, 1, 5],
  2. with i=5i = 5 and j=4j = 4. The new array will now be [2,2,2,2,4][2, 2, 2, 2, 4],
  3. with i=5i = 5 and j=3j = 3. The new array will now be [2,2,3,2,3][2, 2, 3, 2, 3].

The resulting ugliness is 11. It can be proven that this is the minimum possible ugliness for this test.

Samples

3
3
10 10 10
4
3 2 1 2
5
1 2 3 1 5
0
0
1

在线编程 IDE

建议全屏模式获得最佳体验