Three Integers

All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
You are given three integers A, B and C. You may perform the following operation an arbitrary number of times: choose one of the numbers A, B, C and either add 1 to it or subtract 1 from it.
Find the minimum number of operations required to make the sequence A, B, C an arithmetic progression, i.e. a sequence which satisfies B  A = C  B.
Input
 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
 The first and only line of each test case contains three spaceseparated integers A, B and C.
Output
For each test case, print a single line containing one integer — the minimum required number of operations.
Constraints
 1 ≤ T ≤ 10,000
 10^{9} ≤ A, B, C ≤ 10^{9}
Subtasks
Subtask #1 (35 points): 10^{2} ≤ A, B, C ≤ 10^{2}
Subtask #2 (65 points): original constraints
Example
Input: 5 5 0 5 5 7 6 10 100 20 1 1 1 51 23 10 Output: 0 7 105 2 8
Explanation
Example case 1: No operations are needed because 0(5) = 50.
Example case 2: We can obtain an arithmetic progression in seven operations by adding 1 to A = 5 and subtracting 1 six times from B = 7.
Example case 3: We should add 1 to B 105 times.
Author:  mgch 
Tester:  lg5293 
Tags  adhoc, easy, ltime58, maths, mgch 
Date Added:  27032018 
Time Limit:  0.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 