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.
- 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 space-separated integers A, B and C.
For each test case, print a single line containing one integer — the minimum required number of operations.
- 1 ≤ T ≤ 10,000
- -109 ≤ A, B, C ≤ 109
Subtask #1 (35 points): -102 ≤ A, B, C ≤ 102
Subtask #2 (65 points): original constraints
Input: 5 -5 0 5 -5 7 6 -10 -100 20 1 -1 1 51 23 10 Output: 0 7 105 2 8
Example case 1: No operations are needed because 0-(-5) = 5-0.
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.
|Tags||ad-hoc, easy, ltime58, maths, mgch|
|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|
Fetching successful submissions
If you are still having problems, see a sample solution here.