CF1605A.M. Deviation

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

M. Deviation

A number a2a_2 is said to be the arithmetic mean of two numbers a1a_1 and a3a_3, if the following condition holds: a1+a3=2a2a_1 + a_3 = 2\cdot a_2.

We define an arithmetic mean deviation of three numbers a1a_1, a2a_2 and a3a_3 as follows: d(a1,a2,a3)=a1+a32a2d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|.

Arithmetic means a lot to Jeevan. He has three numbers a1a_1, a2a_2 and a3a_3 and he wants to minimize the arithmetic mean deviation d(a1,a2,a3)d(a_1, a_2, a_3). To do so, he can perform the following operation any number of times (possibly zero):

  • Choose i,ji, j from {1,2,3}\{1, 2, 3\} such that iji \ne j and increment aia_i by 11 and decrement aja_j by 11

Help Jeevan find out the minimum value of d(a1,a2,a3)d(a_1, a_2, a_3) that can be obtained after applying the operation any number of times.

Input

The first line contains a single integer tt (1t5000)(1 \le t \le 5000)  — the number of test cases.

The first and only line of each test case contains three integers a1a_1, a2a_2 and a3a_3 (1a1,a2,a3108)(1 \le a_1, a_2, a_3 \le 10^{8}).

Output

For each test case, output the minimum value of d(a1,a2,a3)d(a_1, a_2, a_3) that can be obtained after applying the operation any number of times.

Note

Note that after applying a few operations, the values of a1a_1, a2a_2 and a3a_3 may become negative.

In the first test case, 44 is already the Arithmetic Mean of 33 and 55.

d(3,4,5)=3+524=0d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0

In the second test case, we can apply the following operation:

(2,2,6)(2, 2, 6) \xrightarrow[\text{incrementa_2}]{\text{decrementa_1}} (1,3,6)(1, 3, 6)

d(1,3,6)=1+623=1d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1

It can be proven that answer can not be improved any further.

In the third test case, we can apply the following operations:

(1,6,5)(1, 6, 5) \xrightarrow[\text{incrementa_3}]{\text{decrementa_2}} (1,5,6)(1, 5, 6) \xrightarrow[\text{incrementa_1}]{\text{decrementa_2}} (2,4,6)(2, 4, 6)

d(2,4,6)=2+624=0d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0

Samples

3
3 4 5
2 2 6
1 6 5
0
1
0

在线编程 IDE

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