Three friends are going to meet each other. Initially, the first friend stays at the position $x = a$, the second friend stays at the position $x = b$ and the third friend stays at the position $x = c$ on the coordinate axis $Ox$.

In one minute each friend independently from other friends can change the position $x$ by $1$ to the left or by $1$ to the right (i.e. set $x := x - 1$ or $x := x + 1$) or even don't change it.

Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $a'$, $b'$ and $c'$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $|a' - b'| + |a' - c'| + |b' - c'|$, where $|x|$ is the absolute value of $x$.

Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.

You have to answer $q$ independent test cases.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of test cases.

The next $q$ lines describe test cases. The $i$-th test case is given as three integers $a, b$ and $c$ ($1 \le a, b, c \le 10^9$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.


-----Output-----

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.


-----Example-----
Input
8
3 3 4
10 20 30
5 5 5
2 4 3
1 1000000000 1000000000
1 1000000000 999999999
3 2 5
3 2 6

Output
0
36
0
0
1999999994
1999999994
2
4

Difficulty: EASY
Tags: Complete search

Sorting

Mathematics

Greedy algorithms
Skill types: Complete search

Sorting

Greedy algorithms

Starter code:

Solutions:
import math
nt = int(input())
while nt:
	nt -= 1
	s = 0
	li = list(map(int, input().strip().split()))
	if len(set(li)) == 3:
		li.sort()
		dif1 = li[0] - li[1]
		dif2 = li[1] - li[2]
		if dif1 < 0:
			dif1 = -dif1
		if dif2 < 0:
			dif2 = -dif2
		if dif1 > dif2:
			li[0] = li[0] + 1
			li[1] = li[1] - 1
			li[2] -= 1
		elif dif1 < dif2:
			li[1] += 1
			li[2] -= 1
			li[0] += 1
		elif li[1] == li[0] + 1 and li[2] == li[1] + 1:
			li[0] += 1
			li[2] -= 1
		elif li[1] == li[0] + 1:
			li[0] += 1
			li[2] -= 1
		elif li[2] == li[1] + 1:
			li[2] -= 1
			li[0] += 1
		else:
			li[0] += 1
			li[2] -= 1
		v1 = li[0] - li[1]
		if v1 < 0:
			v1 = -v1
		v2 = li[0] - li[2]
		if v2 < 0:
			v2 = -v2
		v3 = li[1] - li[2]
		if v3 < 0:
			v3 = -v3
		print(v1 + v2 + v3)
	elif len(set(li)) == 2:
		l = list(set(li))
		l.sort()
		a = l[0]
		b = l[1]
		if b == a + 1:
			b -= 1
			value = 0
		else:
			a = a + 1
			b = b - 1
		value = 2 * (b - a)
		print(value)
	else:
		print(0)


def distance(list):
	a = list[0]
	b = list[1]
	c = list[2]
	return abs(a - b) + abs(a - c) + abs(b - c)
n = int(input())
for i in range(n):
	instring = input()
	inlist = instring.split()
	inlist = [int(i) for i in inlist]
	inlist.sort()
	if inlist[0] < inlist[1] < inlist[2]:
		inlist[0] = inlist[0] + 1
		inlist[2] = inlist[2] - 1
	elif inlist[0] == inlist[1] == inlist[2]:
		print(0)
		continue
	elif inlist[0] == inlist[1]:
		if inlist[1] == inlist[2] - 1:
			print(0)
			continue
		inlist[2] = inlist[2] - 1
		inlist[1] = inlist[1] + 1
		inlist[0] = inlist[0] + 1
	elif inlist[1] == inlist[2]:
		if inlist[0] == inlist[2] - 1:
			print(0)
			continue
		inlist[2] = inlist[2] - 1
		inlist[1] = inlist[1] - 1
		inlist[0] = inlist[0] + 1
	print(distance(inlist))


for t in range(int(input())):
	l = list(map(int, input().split()))
	if max(l) == min(l):
		print(0)
	else:
		p = sorted(l)
		if p[0] == p[1] or p[1] == p[2]:
			if abs(max(l) - min(l)) >= 2:
				print((abs(max(l) - min(l)) - 2) * 2)
			else:
				print((abs(max(l) - min(l)) - 1) * 2)
		else:
			p[0] += 1
			p[2] -= 1
			c = abs(p[2] - p[1]) + abs(p[2] - p[0]) + abs(p[1] - p[0])
			print(c)


R = lambda : map(int, input().split())
for _ in range(int(input())):
	a = sorted(list(R()))
	print(2 * max(a[2] - a[0], 2) - 4)


n = int(input())
for i in range(n):
	L = [int(e) for e in input().strip().split()]
	c = max(L)
	a = min(L)
	L.remove(a)
	L.remove(c)
	b = L[0]
	if c - a > 2:
		a += 1
		c -= 1
		print(2 * (c - a))
	else:
		print('0')


lt = []
n = int(input())
for i in range(n):
	lt = list(map(int, input().split()))
	lt.sort()
	if lt[0] + 1 >= lt[1] and lt[1] + 1 >= lt[2]:
		print(0)
	else:
		print(2 * (lt[2] - lt[0]) - 4)


def cal_dis(num_list):
	(a, b, c) = sorted(num_list)
	return b - a + (c - b) + (c - a)
q = input()
ans_list = []
for _ in range(int(q)):
	(a, b, c) = input().split(' ')
	num_list = [int(a), int(b), int(c)]
	_min = 10000000000.0
	total_list = []
	for idx in range(3):
		can_list = []
		for x in [1, 0, -1]:
			can_list.append(num_list[idx] + x)
		total_list.append(can_list)
	for i in range(3):
		for j in range(3):
			for k in range(3):
				temp = cal_dis([total_list[0][i], total_list[1][j], total_list[2][k]])
				if temp < _min:
					_min = temp
	ans_list.append(_min)
for ans in ans_list:
	print(ans)


t = int(input())
for i in range(t):
	sumn = 0
	(a, b, c) = map(int, input().split())
	sumn += abs(a - b) + abs(b - c) + abs(c - a)
	if sumn >= 4:
		print(sumn - 4)
	elif sumn >= 2 and sumn < 4:
		print(sumn - 2)
	else:
		print(sumn)


n = int(input())
for i in range(n):
	s = list(map(int, input().split()))
	s.sort()
	if s[0] < s[1]:
		s[0] += 1
	elif s[1] + 1 < s[2]:
		s[0] += 1
		s[1] += 1
	if s[0] < s[1]:
		s[2] -= 1
		s[1] -= 1
	elif s[1] < s[2]:
		s[2] -= 1
	print(2 * s[2] - 2 * s[0])


q = int(input())
for i in range(q):
	num = [int(j) for j in input().split()]
	num.sort()
	medio = (num[0] + num[2]) // 2
	if num[0] < medio:
		num[0] += 1
	elif num[0] > medio:
		num[0] -= 1
	if num[1] < medio:
		num[1] += 1
	elif num[1] > medio:
		num[1] -= 1
	if num[2] > medio:
		num[2] -= 1
	print(abs(num[0] - num[1]) + abs(num[0] - num[2]) + abs(num[1] - num[2]))


t = int(input())
for i in range(t):
	a = [int(x) for x in input().split()]
	a.sort()
	if a[0] == a[2] or a[0] == a[2] - 1:
		print(0)
	else:
		print(2 * abs(a[0] - a[2] + 2))


import sys
from sys import stdin, stdout
import math
import time
import random
from functools import lru_cache
from collections import Counter
import heapq
try:
	for _ in range(int(input())):
		pos = sorted([int(i) for i in input().split()])
		ans = 2 * (pos[2] - pos[0]) - 4
		if ans < 0:
			print(0)
		else:
			print(ans)
except EOFError as e:
	print(e)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	A = LIST()
	A.sort()
	if A[2] - A[0] <= 1:
		print(0)
		continue
	if A[0] <= A[1]:
		A[0] += 1
	if A[1] <= A[2]:
		A[2] -= 1
	if A[0] > A[1]:
		A[1] += 1
	elif A[1] > A[2]:
		A[1] -= 1
	ans = 0
	ans += A[1] - A[0]
	ans += A[2] - A[1]
	ans += A[2] - A[0]
	print(ans)


t = input()
for _ in range(int(t)):
	(x, y, z) = map(int, input().split())
	(x, y, z) = (min(x, y, z), x + y + z - min(x, y, z) - max(x, y, z), max(x, y, z))
	temp = set([x, y, z])
	if len(temp) == 1:
		ans = 0
	elif len(temp) == 2:
		ans = min(2 * abs(z - x - 1), 2 * abs(z - x - 2))
	else:
		ans = abs(x + 1 - y) + abs(y - z + 1) + abs(x + 1 - z + 1)
	print(ans)


for m in range(int(input())):
	(a, b, c) = map(int, input().split())
	l1 = [a, a - 1, a + 1]
	l2 = [b, b - 1, b + 1]
	l3 = [c, c - 1, c + 1]
	l4 = []
	for i in l1:
		for j in l2:
			for k in l3:
				p = abs(i - j) + abs(j - k) + abs(i - k)
				l4.append(p)
	print(min(l4))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ret = float('inf')
	for da in (-1, 0, 1):
		for db in (-1, 0, 1):
			for dc in (-1, 0, 1):
				(na, nb, nc) = (a + da, b + db, c + dc)
				ret = min(ret, abs(na - nb) + abs(na - nc) + abs(nb - nc))
	print(ret)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	print(max(0, abs(a - b) + abs(a - c) + abs(b - c) - 4))


import sys
q = int(sys.stdin.readline())

def dist(x, y, z):
	return abs(x - y) + abs(x - z) + abs(y - z)

def solve(a, b, c):
	best_dist = 10 ** 18
	for ax in [-1, 0, 1]:
		for bx in [-1, 0, 1]:
			for cx in [-1, 0, 1]:
				best_dist = min(best_dist, dist(a + ax, b + bx, c + cx))
	return best_dist
for _ in range(q):
	(a, b, c) = map(int, sys.stdin.readline().strip().split(' '))
	print(solve(a, b, c))


def main():
	buf = input()
	q = int(buf)
	a = []
	b = []
	c = []
	for i in range(q):
		buf = input()
		buflist = buf.split()
		a.append(int(buflist[0]))
		b.append(int(buflist[1]))
		c.append(int(buflist[2]))
	ans = []
	for i in range(q):
		p = [a[i], b[i], c[i]]
		p.sort()
		if p[0] == p[1] and p[0] < p[2]:
			p[1] += 1
		if p[1] == p[2] and p[0] < p[2]:
			p[1] -= 1
		if p[0] < p[1]:
			p[0] += 1
		if p[1] < p[2]:
			p[2] -= 1
		ans.append(p[1] - p[0] + (p[2] - p[0]) + (p[2] - p[1]))
	for i in range(q):
		print(ans[i])
main()


q = int(input())
while q:
	q += -1
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1]:
		if l[1] == l[2]:
			print(0)
		else:
			print(max(0, 2 * (l[2] - l[1] - 2)))
	elif l[1] == l[2]:
		print(max(0, 2 * (l[1] - l[0] - 2)))
	else:
		print(l[2] - 1 - l[1] + l[1] - l[0] - 1 + l[2] - l[0] - 2)


for _ in range(int(input())):
	s = sorted([int(i) for i in input().split()])
	if s[0] == s[1] and s[1] == s[2]:
		print(0)
	elif abs(s[1] - s[0]) + abs(s[2] - s[1]) + abs(s[2] - s[0]) <= 4:
		print(0)
	elif s[0] == s[1]:
		s[0] += 1
		s[1] += 1
		s[2] -= 1
		print(abs(s[2] - s[1]) * 2)
	elif s[1] == s[2]:
		s[0] += 1
		s[1] -= 1
		s[2] -= 1
		print(abs(s[2] - s[0]) * 2)
	else:
		s[0] += 1
		s[2] -= 1
		print(abs(s[1] - s[0]) + abs(s[2] - s[1]) + abs(s[2] - s[0]))


t = int(input())
for _ in range(t):
	a = sorted(list(map(int, input().split())))
	A = abs(a[0] - a[1])
	B = abs(a[1] - a[2])
	C = abs(a[0] - a[2])
	if A == 0:
		if C == 1:
			B = 0
			C = 0
		elif C > 1:
			B -= 2
			C -= 2
	elif B == 0:
		if A == 1:
			A = 0
			C = 0
		elif C > 1:
			A -= 2
			C -= 2
	elif C != 0:
		A -= 1
		B -= 1
		C -= 2
	print(A + B + C)


x = int(input())
c = 0
for i in range(x):
	(a, b, c) = map(int, input().split())

	def calc(a, b, c):
		return abs(a - b) + abs(a - c) + abs(b - c)
	ans = calc(a, b, c)
	for j in range(-1, 2):
		for k in range(-1, 2):
			for l in range(-1, 2):
				p = a + j
				q = b + k
				r = c + l
				ans = min(ans, calc(p, q, r))
	print(ans)


nos = int(input())
for iii in range(nos):
	pos = list(map(int, input().split()))
	pos.sort()
	flag1 = 5
	flag2 = 0
	dist = 0
	if abs(pos[0] - pos[1]) < 1:
		flag1 = 0
		if abs(pos[1] - pos[2]) > 0:
			pos[1] += 1
			pos[0] += 1
	else:
		dist += abs(pos[0] - pos[1]) - 1
		pos[0] += 1
	if abs(pos[1] - pos[2]) < 1:
		flag2 = 0
		if abs(pos[0] - pos[1]) > 0:
			pos[1] -= 1
			pos[2] -= 1
	else:
		dist += abs(pos[1] - pos[2]) - 1
		pos[2] -= 1
	dist += abs(pos[0] - pos[2])
	dist = 0
	dist = abs(pos[0] - pos[1])
	dist += abs(pos[1] - pos[2])
	dist += abs(pos[0] - pos[2])
	print(dist)


for _ in range(int(input())):
	(a, _, c) = sorted(map(int, input().split()))
	print(2 * max(0, c - a - 2))


def main():
	q = int(input())
	for _ in range(q):
		(a, b, c) = [int(x) for x in input().strip().split(' ')]
		min_ans = abs(a - b) + abs(b - c) + abs(c - a)
		for ap in range(a - 1, a + 2):
			for bp in range(b - 1, b + 2):
				for cp in range(c - 1, c + 2):
					ans = abs(ap - bp) + abs(bp - cp) + abs(cp - ap)
					min_ans = min(min_ans, ans)
		print(min_ans)
main()


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
t = I()
for i in range(0, t):
	a = li()
	a.sort()
	if a[0] != a[1] and a[1] != a[2]:
		if a[0] != a[1]:
			a[0] += 1
		elif a[0] != a[2]:
			a[0] += 1
			a[1] += 1
		if a[2] != a[1]:
			a[2] -= 1
	elif a[0] == a[1]:
		if a[0] != a[2]:
			a[0] += 1
			a[1] += 1
		if a[0] != a[2]:
			a[2] -= 1
	elif a[1] == a[2]:
		if a[0] != a[1]:
			a[0] += 1
		if a[0] != a[1]:
			a[1] -= 1
			a[2] -= 1
	print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))


t = int(input())
while t > 0:
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	l.sort()
	b = l[1]
	a = l[0]
	c = l[2]
	if a == b and b == c:
		print('0')
	else:
		if a < b:
			a = a + 1
		else:
			a += 1
			b += 1
		if c > b:
			c -= 1
		elif c == b and c != a:
			c -= 1
			b -= 1
		d = abs(a - b) + abs(a - c) + abs(b - c)
		print(d)
	t -= 1


def solve():
	x = list(map(int, input().split()))
	ans = 10 ** 10
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				(a, b, c) = x
				a += i
				b += j
				c += k
				t = abs(a - b) + abs(b - c) + abs(a - c)
				ans = min(ans, t)
	return ans

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	Q = int(input())
	for _ in [0] * Q:
		ABC = list(map(int, input().split()))
		ABC.sort()
		print(max(0, (ABC[2] - ABC[0]) * 2 - 4))
main()


for test in range(0, int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	distance = abs(a - b) + abs(b - c) + abs(a - c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				a_ = a + i
				b_ = b + j
				c_ = c + k
				distance = min(distance, abs(a_ - b_) + abs(b_ - c_) + abs(a_ - c_))
	print(distance)


def main():
	noTest = int(input())
	cases = []
	for i in range(0, noTest):
		case = input()
		cases.append(case.split(' '))
	for j in cases:
		print(threeFriends(int(j[0]), int(j[1]), int(j[2])))

def threeFriends(a, b, c):
	initial = [a, b, c]
	initial.sort(reverse=True)
	left = initial[0] - initial[1]
	right = initial[1] - initial[2]
	if left == 0 and right == 0:
		return 0
	elif left == right:
		initial[0] = initial[0] - 1
		initial[2] = initial[2] + 1
		distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
		return distance
	elif left > right:
		if right == 0:
			if left - right == 1:
				return 0
			initial[1] = initial[1] + 1
			initial[2] = initial[2] + 1
			initial[0] = initial[0] - 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
		elif left - right == 1:
			initial[0] = initial[0] - 1
			initial[2] = initial[2] + 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
		else:
			initial[0] = initial[0] - 1
			initial[2] = initial[2] + 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
	elif right > left:
		if left == 0:
			if right - left == 1:
				return 0
			initial[1] = initial[1] - 1
			initial[2] = initial[2] + 1
			initial[0] = initial[0] - 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
		elif right - left == 1:
			initial[0] = initial[0] - 1
			initial[2] = initial[2] + 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
		else:
			initial[1] = initial[1] - 1
			initial[2] = initial[2] + 1
			initial[0] = initial[0] - 1
			distance = initial[0] - initial[1] + (initial[0] - initial[2]) + (initial[1] - initial[2])
			return distance
main()


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	l1 = []
	l2 = []
	l3 = []
	l1.append(a)
	l1.append(a + 1)
	l1.append(a - 1)
	l2.append(b)
	l2.append(b + 1)
	l2.append(b - 1)
	l3.append(c)
	l3.append(c + 1)
	l3.append(c - 1)
	p = []
	for x in l1:
		for y in l2:
			for z in l3:
				res = abs(x - y) + abs(y - z) + abs(z - x)
				p.append(res)
	print(min(p))


t = int(input())
for _ in range(t):
	ar = list(map(int, input().strip().split()))
	ar.sort()
	if ar[0] == ar[1] and ar[1] == ar[2]:
		ar[0] = ar[0]
	elif ar[0] == ar[1]:
		if ar[1] + 1 < ar[2]:
			ar[0] += 1
			ar[1] += 1
		ar[2] -= 1
	elif ar[1] == ar[2]:
		if ar[1] - 1 > ar[0]:
			ar[1] -= 1
			ar[2] -= 1
		ar[0] += 1
	else:
		ar[0] = ar[0] + 1
		ar[2] = ar[2] - 1
	ans = abs(ar[0] - ar[1]) + abs(ar[1] - ar[2]) + abs(ar[0] - ar[2])
	print(ans)


x = int(input())
for i in range(x):
	all_str = input()
	all_pos = [int(x) for x in all_str.split()]
	a = max(*all_pos)
	b = min(*all_pos)
	ans = 2 * max(0, a - b - 2)
	print(ans)


n = int(input())
result = []

def f(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for i in range(n):
	aao = [int(i) for i in input().split()]
	(a, b, c) = (aao[0], aao[1], aao[2])
	aM = a + 1
	am = a - 1
	bM = b + 1
	bm = b - 1
	cM = c + 1
	cm = c - 1
	ans = []
	for i in [a, am, aM]:
		for j in [b, bm, bM]:
			for k in [c, cm, cM]:
				ans.append(f(i, j, k))
	result.append(min(ans))
for i in result:
	print(i)


q = int(input())
i = 1
while i <= q:
	inp = list(map(int, input().split()))
	a = inp[0]
	b = inp[1]
	c = inp[2]
	dis = abs(a - b) + abs(b - c) + abs(a - c)
	if dis >= 4:
		print(dis - 4)
	else:
		print(0)
	i += 1


q = int(input())
for _ in range(q):
	l = list(map(int, input().split()))
	l.sort()
	s1 = 2 * (l[2] - l[0] - 2)
	if s1 >= 0:
		print(s1)
	else:
		print(0)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = round((a + b + c) / 3, 0)
	if a > x:
		a -= 1
	if a < x:
		a += 1
	if b > x:
		b -= 1
	if b < x:
		b += 1
	if c > x:
		c -= 1
	if c < x:
		c += 1
	print(abs(a - b) + abs(b - c) + abs(a - c))


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	d = li()
	print(max(0, 2 * (max(d) - min(d) - 2)))


n = int(input())
while n > 0:
	n -= 1
	(a, b, c) = [int(s) for s in input().split()]
	summa = int(abs(b - a) + abs(c - a) + abs(b - c))
	if a == b or b == c or a == c:
		if summa <= 4:
			print(0)
		else:
			print(summa - 4)
	elif abs(a - b) == 1 or abs(a - c) == 1 or abs(c - b) == 1:
		if summa <= 4:
			print(0)
		else:
			print(summa - 4)
	elif summa <= 4:
		print(0)
	else:
		print(summa - 4)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().strip().split())
	if a == b == c:
		ans = abs(a - b) + abs(b - c) + abs(c - a)
	elif a == b:
		if c < b:
			if b - c == 1:
				c += 1
			else:
				c += 1
				a -= 1
				b -= 1
		elif c - b == 1:
			c -= 1
		else:
			c -= 1
			a += 1
			b += 1
		ans = abs(a - b) + abs(b - c) + abs(c - a)
	elif a == c:
		if b < a:
			if a - b == 1:
				b += 1
			else:
				b += 1
				c -= 1
				a -= 1
		elif b - a == 1:
			b -= 1
		else:
			b -= 1
			c += 1
			a += 1
		ans = abs(a - b) + abs(b - c) + abs(c - a)
	elif b == c:
		if a < b:
			if b - a == 1:
				a += 1
			else:
				a += 1
				b -= 1
				c -= 1
		elif a - b == 1:
			a -= 1
		else:
			a -= 1
			b += 1
			c += 1
		ans = abs(a - b) + abs(b - c) + abs(c - a)
	else:
		x = max(a, b, c)
		y = min(a, b, c)
		z = a + b + c - (x + y)
		x -= 1
		y += 1
		ans = abs(x - y) + abs(y - z) + abs(z - x)
	print(ans)


for tc in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	x = l[0]
	y = l[1]
	z = l[2]
	t = 0
	if x == y and x != z:
		z = z - 1
		if z - x > 0:
			t = 2 * (z - x - 1)
		else:
			t = 2 * (z - x)
		print(t)
		continue
	elif y == z and x != y:
		x = x + 1
		if y - x > 0:
			t = 2 * (y - x - 1)
		else:
			t = 2 * (y - x)
		print(t)
		continue
	elif x == y and x == z:
		print(0)
		continue
	x = x + 1
	z = z - 1
	t = y - x + z - y + z - x
	print(t)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().rstrip().split(' '))
	d = abs(a - b) + abs(b - c) + abs(c - a)
	if d < 4:
		print('0')
	else:
		print(d - 4)


for i in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
	if x == 0:
		print(0)
	elif a[0] == a[2]:
		print(x)
	elif a[0] == a[1]:
		l = []
		a[0] += 1
		a[1] += 1
		x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		l.append(x)
		a[2] -= 1
		x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		l.append(x)
		print(min(l))
	elif a[1] == a[2]:
		k = []
		a[2] -= 1
		a[1] -= 1
		x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		k.append(x)
		a[0] += 1
		x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		k.append(x)
		print(min(k))
	else:
		a[0] += 1
		a[2] -= 1
		x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		print(x)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	x = abs(a - b) + abs(a - c) + abs(b - c)
	if x > 4:
		print(x - 4)
	else:
		print(0)


def main():
	q = int(input())
	for i in range(q):
		nums = list(map(int, input().split()))
		nums.sort()
		if nums[-1] == nums[1] and nums[0] != nums[1]:
			nums[-1] -= 1
			nums[1] -= 1
		if nums[0] == nums[1] and nums[1] != nums[-1]:
			nums[0] += 1
			nums[1] += 1
		if nums[0] != nums[1]:
			nums[0] += 1
		if nums[-1] != nums[1]:
			nums[-1] -= 1
		print(nums[1] - nums[0] + nums[-1] - nums[1] + nums[-1] - nums[0])
main()


tcs = int(input())

def calc(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for _ in range(tcs):
	num = list(map(int, input().split()))
	res = abs(num[0] - num[1]) + abs(num[1] - num[2]) + abs(num[0] - num[2])
	res = min(res, calc(num[0] - 1, num[1] - 1, num[2] - 1))
	res = min(res, calc(num[0], num[1] - 1, num[2] - 1))
	res = min(res, calc(num[0] + 1, num[1] - 1, num[2] - 1))
	res = min(res, calc(num[0] - 1, num[1], num[2] - 1))
	res = min(res, calc(num[0], num[1], num[2] - 1))
	res = min(res, calc(num[0] + 1, num[1], num[2] - 1))
	res = min(res, calc(num[0] - 1, num[1] + 1, num[2] - 1))
	res = min(res, calc(num[0], num[1] + 1, num[2] - 1))
	res = min(res, calc(num[0] + 1, num[1] + 1, num[2] - 1))
	res = min(res, calc(num[0] - 1, num[1] - 1, num[2]))
	res = min(res, calc(num[0], num[1] - 1, num[2]))
	res = min(res, calc(num[0] + 1, num[1] - 1, num[2]))
	res = min(res, calc(num[0] - 1, num[1], num[2]))
	res = min(res, calc(num[0], num[1], num[2]))
	res = min(res, calc(num[0] + 1, num[1], num[2]))
	res = min(res, calc(num[0] - 1, num[1] + 1, num[2]))
	res = min(res, calc(num[0], num[1] + 1, num[2]))
	res = min(res, calc(num[0] + 1, num[1] + 1, num[2]))
	res = min(res, calc(num[0] - 1, num[1] - 1, num[2] + 1))
	res = min(res, calc(num[0], num[1] - 1, num[2] + 1))
	res = min(res, calc(num[0] + 1, num[1] - 1, num[2] + 1))
	res = min(res, calc(num[0] - 1, num[1], num[2] + 1))
	res = min(res, calc(num[0], num[1], num[2] + 1))
	res = min(res, calc(num[0] + 1, num[1], num[2] + 1))
	res = min(res, calc(num[0] - 1, num[1] + 1, num[2] + 1))
	res = min(res, calc(num[0], num[1] + 1, num[2] + 1))
	res = min(res, calc(num[0] + 1, num[1] + 1, num[2] + 1))
	print(res)


def ras(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for i in range(q):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] == a[2]:
		print(0)
		continue
	elif a[0] == a[1]:
		a[0] += 1
		a[1] += 1
		print(min(ras(a[0], a[1], a[2]), ras(a[0], a[1], a[2] - 1)))
	elif a[1] == a[2]:
		a[1] -= 1
		a[2] -= 1
		print(min(ras(a[0], a[1], a[2]), ras(a[0] + 1, a[1], a[2])))
	else:
		a[0] += 1
		a[2] -= 1
		print(ras(a[0], a[1], a[2]))


t = int(input())
for i in range(0, t):
	a = [int(x) for x in input().split()]
	a.sort()
	p = a[0]
	q = a[1]
	r = a[2]
	if p == q and p == r:
		ans = 0
	elif p == q:
		r -= 1
		if p != r:
			p += 1
			q += 1
	elif q == r:
		p += 1
		if p != q:
			q -= 1
			r -= 1
	else:
		p += 1
		r -= 1
	ans = abs(p - q) + abs(q - r) + abs(p - r)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	mn = 9999999999
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				mn = min(mn, abs(i - j) + abs(i - k) + abs(j - k))
	print(mn)


t = int(input())
for i in range(t):
	dic = {}
	arr = list(map(int, input().split()))
	for i in range(len(arr)):
		if arr[i] not in dic:
			dic[arr[i]] = 1
		else:
			dic[arr[i]] += 1
	if len(dic) == 3:
		arr.sort()
		arr[0] += 1
		arr[2] -= 1
		x = arr[2] - arr[1] + (arr[2] - arr[0]) + (arr[1] - arr[0])
		print(x)
	elif len(dic) == 2:
		arr.sort()
		if dic[arr[0]] > 1:
			arr[0] += 1
			arr[1] += 1
			if arr[1] != arr[2]:
				arr[2] -= 1
		else:
			arr[1] -= 1
			arr[2] -= 1
			if arr[1] != arr[0]:
				arr[0] += 1
		x = arr[2] - arr[1] + (arr[2] - arr[0]) + (arr[1] - arr[0])
		print(x)
	if len(dic) == 1:
		print('0')


import sys
input = sys.stdin.readline

def getAns(k):
	s = min(k)
	l = max(k)
	if s < l:
		s += 1
	if l > s:
		l -= 1
	print(2 * l - 2 * s)
n = int(input())
for i in range(n):
	getAns([int(x) for x in input().split(' ')])


def solve(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
q = int(input())
while q:
	(a, b, c) = map(int, input().split())
	ls = [-1, 0, 1]
	ans = 10 ** 10
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ans = min(ans, solve(a + ls[i], b + ls[j], c + ls[k]))
	print(ans)
	q -= 1


n = int(input())
for i in range(n):
	(p, q, r) = map(int, input().split())
	avg = round((p + q + r) / 3)
	if p > avg:
		p = p - 1
	elif p < avg:
		p = p + 1
	if q > avg:
		q = q - 1
	elif q < avg:
		q = q + 1
	if r > avg:
		r = r - 1
	elif r < avg:
		r = r + 1
	print(abs(p - q) + abs(p - r) + abs(q - r))


for i in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	res = l[1] - l[0] - 1 + l[2] - 1 - l[1] + l[2] - l[0] - 2
	if res <= 0:
		res = 0
		print(res)
	else:
		print(res)


for i in range(int(input())):
	(a, b, c) = sorted([int(s) for s in input().split()])
	if c - a <= 2:
		print(0)
	else:
		print(2 * c - 2 * a - 4)


def minn(a, b, c):
	l = [a, b, c]
	l.sort()
	if len(set(l)) == 3:
		l[0] += 1
		l[2] -= 1
	elif l[0] == l[1] and l[1] != l[2]:
		if l[2] - l[1] != 1:
			l[0] += 1
			l[1] += 1
		l[2] -= 1
	elif l[1] == l[2] and l[0] != l[2]:
		if l[2] - l[0] != 1:
			l[1] -= 1
			l[2] -= 1
		l[0] += 1
	ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	return ans
t = int(input())
for i in range(t):
	(a, b, c) = [int(j) for j in input().split()]
	print(minn(a, b, c))


for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	x = abs(a - b) + abs(b - c) + abs(a - c)
	if x <= 4:
		print(0)
	else:
		print(x - 4)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	x = abs(a - b)
	y = abs(b - c)
	z = abs(a - c)
	if a == b and b == c:
		print(0)
	elif a != b and b != c and (a != c):
		a = a + 1
		c = c - 1
		print(abs(a - b) + abs(b - c) + abs(c - a))
	elif x == 0 and y == 1:
		print(0)
	elif x == 0 and y != 1:
		a = a + 1
		b = b + 1
		c = c - 1
		print(abs(a - b) + abs(b - c) + abs(c - a))
	elif y == 0 and x == 1:
		print(0)
	elif y == 0 and x != 1:
		a = a + 1
		b = b - 1
		c = c - 1
		print(abs(a - b) + abs(b - c) + abs(c - a))


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1]:
		if l[1] == l[2]:
			ans = 0
		elif l[1] == l[2] - 1:
			ans = 0
		else:
			ans = 2 * (l[2] - l[1] - 2)
	elif l[1] == l[2]:
		if l[0] == l[1] - 1:
			ans = 0
		else:
			ans = 2 * (l[1] - l[0] - 2)
	else:
		ans = l[1] - l[0] - 1 + (l[2] - l[1] - 1) + (l[2] - l[0] - 2)
	print(ans)


q = int(input())
for _ in range(q):
	(a, b, c) = [int(t) for t in input().split(' ')]
	m = 10 ** 15
	for x in (-1, 0, 1):
		for y in (-1, 0, 1):
			for z in (-1, 0, 1):
				da = a + x
				db = b + y
				dc = c + z
				m = min(m, abs(da - db) + abs(da - dc) + abs(db - dc))
	print(m)


t = int(input())
for i in range(t):
	A = input().split()
	(a, b, c) = [int(x) for x in A]
	if b < a:
		(a, b) = (b, a)
	if c < a:
		(a, c) = (c, a)
	if b > c:
		(b, c) = (c, b)
	if a == c:
		print(0)
		continue
	elif a == b:
		a += 1
		b += 1
		c = max(c - 1, a)
	elif b == c:
		b -= 1
		c -= 1
		a = min(a + 1, c)
	else:
		a += 1
		c -= 1
	print(2 * (c - a))


q = int(input())
for i in range(q):
	x = list(map(int, input().split()))
	x = sorted(x)
	l = []
	a = x[0]
	b = x[1]
	c = x[2]
	p = [a - 1, a, a + 1]
	q = [b - 1, b, b + 1]
	r = [c - 1, c, c + 1]
	for i in p:
		for j in q:
			for k in r:
				l.append(abs(i - j) + abs(j - k) + abs(k - i))
	print(min(l))


t = int(input())
for _ in range(t):
	v = list(map(int, input().split()))
	print(max(max(v) - min(v) - 2, 0) * 2)


def calc(a, b, c):
	return abs(a - c) + abs(a - b) + abs(b - c)
for __ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = calc(a, b, c)
	for da in range(-1, 2, 1):
		for db in range(-1, 2, 1):
			for dc in range(-1, 2, 1):
				a1 = a + da
				b1 = b + db
				c1 = c + dc
				ans = min(ans, calc(a1, b1, c1))
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] and (a[2] == a[1] or a[2] == a[1] + 1):
		print(0)
	elif a[0] == a[1] and a[2] > a[1]:
		print(2 * (a[2] - a[1] - 2))
	elif a[0] < a[1] and a[1] == a[2]:
		t = (a[2] - a[0] - 2) * 2
		if t < 1:
			print(0)
		else:
			print(t)
	else:
		print(a[2] - a[1] - 1 + a[2] - a[0] - 2 + a[1] - a[0] - 1)


q = int(input())
while q > 0:
	(a, b, c) = [int(i) for i in input().split()]
	A = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				A.append(abs(a + i - b - j) + abs(a + i - c - k) + abs(c + k - b - j))
	ans = A[0]
	for k in range(1, len(A)):
		if ans > A[k]:
			ans = A[k]
	print(ans, '\n')
	q -= 1


q = int(input())

def dif(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for i in range(q):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	if len(set(l)) == 2:
		if l[0] == l[1] and l[1] != l[2]:
			l[0] += 1
			l[1] += 1
			if len(set(l)) != 1:
				l[2] -= 1
		elif l[0] != l[1] and l[1] == l[2]:
			l[2] -= 1
			l[1] -= 1
			if len(set(l)) != 1:
				l[0] += 1
		print(dif(l[0], l[1], l[2]))
	elif len(set(l)) == 1:
		print(0)
	else:
		l[0] += 1
		l[2] -= 1
		print(dif(l[0], l[1], l[2]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = abs(a - b) + abs(a - c) + abs(b - c)
	print(max(0, x - 4))


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	d = abs(a - b) + abs(b - c) + abs(c - a)
	if d < 4:
		print(0)
	else:
		print(d - 4)


nb_test = int(input())
for _ in range(nb_test):
	given = sorted([int(x) for x in input().split()])
	answer = (max(given) - min(given)) * 2 - 4
	print([0, answer][answer > 0])


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	ans = 0
	a.sort()
	ans += a[1] - a[0] - 2
	ans += a[2] - a[0] - 2
	ans += a[2] - a[1]
	print(max(0, ans))


n = int(input())
for i in range(n):
	k = input().split()
	k[0] = int(k[0])
	k[1] = int(k[1])
	k[2] = int(k[2])
	k.sort()
	if k[1] - k[0] >= 2:
		k[0] += 1
		k[1] -= 1
	elif k[0] != k[1]:
		k[0] += 1
	elif k[0] == k[1] and k[1] != k[2]:
		k[0] += 1
		k[1] += 1
	if k[2] != k[1]:
		k[2] -= 1
	print(abs(k[0] - k[1]) + abs(k[1] - k[2]) + abs(k[0] - k[2]))


for i in range(int(input())):
	a = list(map(int, input().strip().split()))
	a.sort()
	if a[1] - a[0] > 1:
		if a[2] - a[1] > 1:
			a[1] -= 1
			a[0] += 1
			a[2] -= 1
		elif a[2] - a[1] == 1:
			a[2] -= 1
			a[1] -= 1
			a[0] += 1
		else:
			a[1] -= 1
			a[2] -= 1
			a[0] += 1
	elif a[1] - a[0] == 1:
		if a[2] - a[1] > 1:
			a[0] += 1
			a[2] -= 1
		elif a[2] - a[1] == 1:
			a[0] += 1
			a[2] -= 1
		else:
			a[0] += 1
	elif a[1] - a[0] < 1:
		if a[2] - a[1] > 1:
			a[2] -= 1
			a[1] += 1
			a[0] += 1
		elif a[2] - a[1] == 1:
			a[2] -= 1
	print(abs(a[0] - a[1]) + abs(a[2] - a[0]) + abs(a[2] - a[1]))


q = int(input())
for i in range(q):
	[a, b, c] = list(map(int, input().rstrip().split()))
	mi = min(a, b, c)
	ma = max(a, b, c)
	altro = a + b + c - mi - ma
	if mi == ma:
		print(0)
	elif ma - mi == 1:
		print(0)
	else:
		mi += 1
		ma -= 1
		print(2 * (ma - mi))


for _ in range(int(input())):
	(c, b, a) = sorted([int(s) for s in input().split()])
	print(2 * max(a - c - 2, 0))


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	l = sorted(l)
	if abs(l[0] - l[2]) <= 2:
		print(0)
	else:
		l[0] = l[0] + 1
		l[2] = l[2] - 1
		print(2 * (l[2] - l[0]))


a = int(input().strip())
arr = []

def calc(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for i in range(a):
	ans = []
	arr = list(map(int, input().rstrip().split()))
	(a, b, c) = arr
	ans.append(calc(a, b, c))
	ans.append(calc(a, b, c - 1))
	ans.append(calc(a, b, c + 1))
	ans.append(calc(a, b - 1, c))
	ans.append(calc(a, b - 1, c - 1))
	ans.append(calc(a, b - 1, c + 1))
	ans.append(calc(a, b + 1, c))
	ans.append(calc(a, b + 1, c - 1))
	ans.append(calc(a, b + 1, c + 1))
	ans.append(calc(a - 1, b, c))
	ans.append(calc(a - 1, b, c - 1))
	ans.append(calc(a - 1, b, c + 1))
	ans.append(calc(a - 1, b - 1, c))
	ans.append(calc(a - 1, b - 1, c - 1))
	ans.append(calc(a - 1, b - 1, c + 1))
	ans.append(calc(a - 1, b + 1, c))
	ans.append(calc(a - 1, b + 1, c - 1))
	ans.append(calc(a - 1, b + 1, c + 1))
	ans.append(calc(a + 1, b, c))
	ans.append(calc(a + 1, b, c - 1))
	ans.append(calc(a + 1, b, c + 1))
	ans.append(calc(a + 1, b - 1, c))
	ans.append(calc(a + 1, b - 1, c - 1))
	ans.append(calc(a + 1, b - 1, c + 1))
	ans.append(calc(a + 1, b + 1, c))
	ans.append(calc(a + 1, b + 1, c - 1))
	ans.append(calc(a + 1, b + 1, c + 1))
	print(min(ans))


from sys import stdin

def solution(t: int) -> None:
	input = stdin.readline
	output = []
	for i in range(t):
		total = 0
		l = sorted([int(x) for x in input().split()])
		if l[0] == l[1]:
			if l[2] > l[1]:
				l[2] -= 1
				if l[2] != l[1]:
					l[0] += 1
					l[1] += 1
		elif l[1] == l[2]:
			if l[0] < l[1]:
				l[0] += 1
				if l[0] != l[1]:
					l[1] -= 1
					l[2] -= 1
		else:
			if l[0] < l[1]:
				l[0] += 1
			if l[2] > l[1]:
				l[2] -= 1
		total = abs(l[2] - l[0]) + abs(l[1] - l[0]) + abs(l[2] - l[1])
		output.append(total)
	print('\n'.join(map(str, output)))

def main():
	t = int(input())
	solution(t)
main()


n = int(input())
for _ in range(n):
	(left, mid, right) = sorted(map(int, input().split()))
	if right - left > 1:
		left += 1
		right -= 1
	elif right - left == 1:
		left += 1
	mid = min(mid, right)
	mid = max(mid, left)
	dist = abs(right - left) + abs(right - mid) + abs(mid - left)
	print(dist)


q = int(input(''))
matrix = []
for i in range(q):
	matrix.append(list(map(int, input().split())))
for i in range(q):
	t = matrix[i]
	t.sort()
	if t[0] == t[1]:
		if t[1] == t[2] or t[2] - t[1] == 1:
			print(0)
		else:
			print(2 * (t[2] - t[1] - 2))
	elif t[1] == t[2]:
		if t[1] - t[0] == 1:
			print(0)
		else:
			print(2 * (t[1] - t[0] - 2))
	else:
		t[0] = t[0] + 1
		t[2] = t[2] - 1
		print(abs(t[1] - t[0]) + abs(t[1] - t[2]) + abs(t[2] - t[0]))


for _ in range(int(input())):
	l = sorted(list(map(int, input().split())))
	(a, b, c) = (l[0], l[1], l[2])
	m = (c - a - 2) * 2
	print(max(0, m))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	(a, b, c) = sorted(f())
	if c - a > 1:
		print(2 * (c - 1) - 2 * (a + 1))
	elif a != c or b != c:
		print(2 * c - 2 * a - 2)
	else:
		print(0)


for _ in range(int(input())):
	a = input().split()
	a1 = int(a[0])
	a2 = int(a[1])
	a3 = int(a[2])
	result = abs(a1 - a2) + abs(a2 - a3) + abs(a1 - a3)
	if result == 0:
		print('0')
	elif result < 4:
		print('0')
	else:
		print(result - 4)


n = 0
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print(0)
	else:
		n = abs(b - a) + abs(c - a) + abs(c - b) - 4
		print(max(0, n))


for p in range(int(input())):
	(a, b, c) = map(int, input().split(' '))
	print(max(0, abs(a - b) + abs(a - c) + abs(b - c) - 4))


num = int(input())
ans = []
for i in range(num):
	pos = input()
	pos = [int(i) for i in pos.split()]
	l = min(pos)
	r = max(pos)
	ans.append(max(0, 2 * (r - l - 2)))
for i in range(num):
	print(ans[i])


import math

def distance(data):
	return sum((abs(data[i] - data[i + 1]) for i in range(2))) + abs(data[2] - data[0])

def func(data, i):
	if i == 2:
		a = distance(data)
		data[2] = data[2] - 1
		b = distance(data)
		data[2] = data[2] + 1
		data[2] = data[2] + 1
		c = distance(data)
		data[2] = data[2] - 1
		return min([a, b, c])
	data[i] = data[i] + 0
	s = func(data, i + 1)
	data[i] = data[i] - 1
	l = func(data, i + 1)
	data[i] = data[i] + 1
	data[i] = data[i] + 1
	r = func(data, i + 1)
	data[i] = data[i] - 1
	return min([s, l, r])
n = int(input())
for t in range(n):
	data = list(map(int, input().strip().split()))
	print(func(data, 0))


import math
x = list(map(int, input().split()))
y = []
for i in range(0, x[0]):
	y.append(list(map(int, input().split())))
for i in range(0, x[0]):
	if max(y[i]) - min(y[i]) < 2:
		print(0)
	else:
		print(2 * (max(y[i]) - min(y[i]) - 2))


import sys

class Input:
	stdin_input = []

	def get_next_token(self):
		if not self.stdin_input or len(self.stdin_input) == 0:
			self.stdin_input = sys.stdin.readline().split(' ')
		result = self.stdin_input[0]
		self.stdin_input = self.stdin_input[1:]
		return result

	def get_next_line(self):
		return sys.stdin.readline()

	def read_str(self):
		return self.get_next_token()

	def read_int(self):
		return int(self.get_next_token())
read = Input()
test = read.read_int()
for no in range(test):
	(a, b, c) = (read.read_int(), read.read_int(), read.read_int())
	res = 10 ** 10
	for x in range(a - 1, a + 2):
		for y in range(b - 1, b + 2):
			for z in range(c - 1, c + 2):
				res = min(res, abs(x - y) + abs(x - z) + abs(z - y))
	print(res)


q = int(input())
for _ in range(q):
	s = list(map(int, input().split()))
	s = sorted(s)
	if s[0] == s[1] == s[2]:
		pass
	elif s[0] == s[1]:
		s[0] += 1
		s[1] += 1
		if s[1] != s[2]:
			s[2] -= 1
	elif s[1] == s[2]:
		s[1] -= 1
		s[2] -= 1
		if s[0] != s[1]:
			s[0] += 1
	else:
		s[0] += 1
		s[2] -= 1
	ans = s[1] - s[0] + s[2] - s[1] + s[2] - s[0]
	print(ans)


for _ in range(int(input())):
	(a, b, c) = sorted([int(s) for s in input().split()])
	(a1, a2, a3) = (b - a, c - b, c - a)
	ans = a1 + a2 + a3
	if ans == 0:
		print(0)
	elif a1 == 0 or a2 == 0:
		if ans < 4:
			print(ans - 2)
		else:
			print(ans - 4)
	else:
		print(ans - 4)


q = int(input())
for i in range(q):
	a = list(map(int, input().split()))
	if max(a) - min(a) < 3:
		print(0)
	else:
		print((max(a) - min(a) - 2) * 2)


for _ in [0] * int(input()):
	(a, b, c) = sorted(map(int, input().split()))
	print(2 * max(c - a, 2) - 4)


for _ in range(int(input())):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	mean = (a + b + c) / 3
	mean = round(mean)
	x = [a, b, c]
	for i in range(len(x)):
		if x[i] == mean:
			continue
		elif x[i] > mean:
			x[i] = x[i] - 1
		else:
			x[i] = x[i] + 1
	ds = abs(x[0] - x[1]) + abs(x[0] - x[2]) + abs(x[1] - x[2])
	print(ds)


for _ in range(int(input())):
	(a, b, c) = sorted(tuple(map(int, input().split())))
	if a < c:
		a += 1
	if c > a:
		c -= 1
	m = (a + c) // 2
	if m > b:
		b += 1
	elif m < b:
		b -= 1
	out = abs(a - b) + abs(a - c) + abs(b - c)
	print(out)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for i in range(t):
	(a, b, c) = [int(x) for x in input().split()]
	total = abs(a - b) + abs(a - c) + abs(b - c)
	if total <= 4:
		print(0)
	else:
		print(total - 4)


q = int(input())
for _ in range(q):
	p = list(map(int, input().split()))
	p.sort()
	tmp = p.copy()
	ans = abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2])
	if p[0] < p[1]:
		p[0] += 1
	if p[0] < p[1]:
		p[0] -= 1
	if p[0] < p[2]:
		p[2] -= 1
	ans = min(abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2]), ans)
	p = tmp.copy()
	if p[0] < p[1]:
		p[0] += 1
	if p[0] < p[1]:
		p[1] -= 1
	if p[0] < p[2]:
		p[2] -= 1
	ans = min(abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2]), ans)
	p = tmp.copy()
	if p[0] < p[2]:
		p[0] += 1
	if p[1] < p[2]:
		p[1] += 1
	if p[0] < p[2]:
		p[2] -= 1
	ans = min(abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2]), ans)
	print(ans)


q = int(input())
for i in range(q):
	a = [int(i) for i in input().split()]
	a.sort()
	print(max((a[2] - a[0] - 2) * 2, 0))


q = int(input())
mas = []
for i in range(q):
	x = list(map(int, input().split()))
	a = [int(x[0]) + 1, int(x[0]) - 1, x[0]]
	b = [int(x[1]) + 1, int(x[1]) - 1, x[1]]
	c = [int(x[2]) + 1, int(x[2]) - 1, x[2]]
	res = int(x[0]) + int(x[1]) + int(x[2])
	mr = []
	for ax in a:
		for bx in b:
			for cx in c:
				res_1 = abs(ax - bx) + abs(ax - cx) + abs(bx - cx)
				mr.append(res_1)
	mas.append(min(mr))
print(*mas, sep='\n')


t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	d = abs(a - c) + abs(a - b) + abs(b - c)
	if d <= 4:
		print(0)
	else:
		print(d - 4)
	t -= 1


n = int(input())
for i in range(n):
	friends = list(map(int, input().split()))
	med = round(sum(friends) / 3, 0)
	for j in range(3):
		if friends[j] < med:
			friends[j] += 1
		elif friends[j] > med:
			friends[j] -= 1
		else:
			pass
	print(abs(friends[0] - friends[1]) + abs(friends[1] - friends[2]) + abs(friends[2] - friends[0]))


import math
t = int(input())
for _ in range(t):
	arr = [int(i) for i in input().split()]
	ans = math.inf
	for i in range(0, 3):
		t1 = arr[0] + i - 1
		for j in range(0, 3):
			t2 = arr[1] + j - 1
			for k in range(0, 3):
				t3 = arr[2] + k - 1
				ans = min(ans, abs(t1 - t2) + abs(t1 - t3) + abs(t2 - t3))
	print(ans)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	s = []
	s.extend([a, b, c])
	s.sort()
	if s[0] == s[1] and s[0] == s[2]:
		print(0)
	elif s[0] == s[1] and s[1] != s[2]:
		if s[2] - s[1] > 1:
			s[2] = s[2] - 1
			s[0] = s[0] + 1
			print(2 * (s[2] - s[0]))
		else:
			print(0)
	elif s[0] != s[1] and s[1] == s[2]:
		if s[1] - s[0] > 1:
			s[1] = s[1] - 1
			s[0] = s[0] + 1
			print(2 * (s[1] - s[0]))
		else:
			print(0)
	else:
		s[0] = s[0] + 1
		s[2] = s[2] - 1
		print(s[1] - s[0] + (s[2] - s[0]) + (s[2] - s[1]))


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	ls = sorted([a, b, c])
	flag = 0
	if ls[0] == ls[1] and ls[1] < ls[2]:
		flag = 1
		ls[0] += 1
		ls[1] += 1
	elif ls[0] < ls[1]:
		ls[0] += 1
	if ls[-1] == ls[-2] and ls[0] < ls[-2] and (flag == 0):
		ls[-1] -= 1
		ls[-2] -= 1
	elif ls[-1] > ls[-2]:
		ls[-1] -= 1
	print(ls[1] - ls[0] + ls[2] - ls[1] + ls[2] - ls[0])


for _ in range(int(input())):
	l = list(map(int, input().split()))
	print(max(abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2]) - 4, 0))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mdist = 10 ** 100
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				(d, e, f) = (a + i, b + j, c + k)
				dist = abs(d - e) + abs(d - f) + abs(e - f)
				mdist = min(mdist, dist)
	print(mdist)


import sys
input = sys.stdin.readline

def get_ans(l):
	return abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
N = int(input())
ans = []
for _ in range(N):
	l = list(map(int, input().split()))
	l = list(map(lambda x: x - min(l), l))
	l.sort()
	if l[-1] - l[-3] > 1:
		l[-1] -= 1
		l[-3] += 1
	elif l[-1] - l[-3]:
		l[-1] -= 1
	if l[-1] == l[-2] == l[-3]:
		ans.append(get_ans(l))
		continue
	if max(l) == l[-2]:
		l[-2] -= 1
		ans.append(get_ans(l))
		continue
	if min(l) == l[-2]:
		l[-2] += 1
		ans.append(get_ans(l))
		continue
	ans.append(get_ans(l))
for a in ans:
	print(a)


q = int(input())
for tc in range(q):
	(a, b, c) = [int(i) for i in input().split()]
	ans = 1e+18
	for ai in range(-1, 2):
		for bi in range(-1, 2):
			for ci in range(-1, 2):
				ans = min(ans, abs(a + ai - b - bi) + abs(a + ai - c - ci) + abs(b + bi - c - ci))
	print(ans)


test = int(input())
for i in range(test):
	ans = 10 ** 10
	(a, b, c) = map(int, input().split())
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				ta = a + i
				tb = b + j
				tc = c + k
				ans = min(ans, abs(ta - tb) + abs(tb - tc) + abs(ta - tc))
	print(ans)


def dis(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for _ in range(int(input())):
	(a, b, c) = sorted([int(i) for i in input().split()])
	if dis(a, b, c) <= 4:
		print(0)
	elif a == b or b == c:
		print(dis(a, b, c) - 4)
	else:
		print(dis(a, b, c) - 4)


n = int(input())
for x in range(n):
	(a, b, c) = map(int, input().strip().split()[:3])
	k = [a, b, c]
	if a == b or b == c or c == a:
		if a == b and b == c:
			print(0)
		else:
			p = abs(k[0] - k[1]) + abs(k[1] - k[2]) + abs(k[0] - k[2]) - 4
			if p < 0:
				print(0)
			else:
				print(p)
	else:
		k.sort()
		k[0] += 1
		k[2] -= 1
		print(abs(k[0] - k[1]) + abs(k[1] - k[2]) + abs(k[0] - k[2]))


def rec(a, i, res):
	if i == len(a):
		return abs(res[0] - res[1]) + abs(res[1] - res[2]) + abs(res[0] - res[2])
	return min(rec(a, i + 1, res + [a[i]]), rec(a, i + 1, res + [a[i] + 1]), rec(a, i + 1, res + [a[i] - 1]))
t = int(input())
while t > 0:
	a = sorted(list(map(int, input().split())))
	print(rec(a, 0, []))
	t -= 1


for _ in [0] * int(input()):
	li = sorted(list(map(int, input().split())))
	if li[2] - li[0] < 3:
		print(0)
	else:
		li[0] += 1
		li[2] -= 1
		print(li[2] - li[1] + (li[2] - li[0]) + (li[1] - li[0]))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	ma = max(a, b, c)
	mi = min(a, b, c)
	if a == ma and b == mi or (a == mi and b == ma):
		mid = c
	elif b == ma and c == mi or (b == mi and c == ma):
		mid = a
	else:
		mid = b
	if a == b and b == c and (c == a):
		print(0)
	elif ma - 1 == mid and mid == mi and (ma - 1 == mi) or (ma == mid and mid == mi + 1 and (ma == mi + 1)):
		print(0)
	else:
		d = ma - 1 - (mi + 1) + (ma - 1 - mid) + (mid - (mi + 1))
		print(d)


def translation():
	word_1 = input()
	word_2 = input()[::-1]
	print(['NO', 'YES'][word_1 == word_2])
	return

def anton_and_danik():
	games = int(input())
	wins = input()
	anton_wins = sum((i == 'A' for i in wins))
	if anton_wins * 2 > len(wins):
		print('Anton')
	elif anton_wins * 2 == len(wins):
		print('Friendship')
	else:
		print('Danik')
	return

def acoomodation():
	cnt = 0
	for _ in range(int(input())):
		(p, q) = map(int, input().split())
		if q - p >= 2:
			cnt += 1
	print(cnt)
	return

def juicer():
	(n, b, d) = map(int, input().split())
	sum_orange = 0
	cnt_empty = 0
	for orange in list(map(int, input().split())):
		if orange <= b:
			sum_orange += orange
			if sum_orange > d:
				cnt_empty += 1
				sum_orange = 0
	print(cnt_empty)
	return

def digit_game():
	for game in range(int(input())):
		breach_odd_cnt = 0
		breach_even_cnt = 0
		raze_odd_cnt = 0
		raze_even_cnt = 0
		n = int(input())
		number = input()
		breach_numbers = ''
		raze_numbers = ''
		len_number = len(number)
		idx = 1
		for digit in number:
			if idx % 2 == 0:
				breach_numbers += digit
				if digit in '13579':
					breach_odd_cnt += 1
				else:
					breach_even_cnt += 1
			else:
				raze_numbers += digit
				if digit in '13579':
					raze_odd_cnt += 1
				else:
					raze_even_cnt += 1
			idx += 1
		if len_number == 1:
			if int(number) % 2 == 0:
				print(2)
			else:
				print(1)
		elif len_number % 2 == 0:
			if breach_even_cnt >= 1:
				print(2)
			else:
				print(1)
		elif raze_odd_cnt >= 1:
			print(1)
		else:
			print(2)
	return

def modular_exponentiation():
	n = int(input())
	m = int(input())
	calc = m % int(1 << n)
	print(int(calc))
	return

def tricky_sum():
	for _ in range(int(input())):
		number = int(input())
		pow_two = 1
		while pow_two <= number:
			pow_two *= 2
			print(pow_two)
		sum_formula = number * (number + 1) // 2
		trick_sum = sum_formula - 2 * pow_two + 2
		print(trick_sum)
	return

def three_indices():
	for _ in range(int(input())):
		n = int(input())
		permutation = list(map(int, input().split()))
		(idx_i, idx_j, idx_k) = (1, 2, 3)
		(num_i, num_j, num_k) = (0, 0, 0)
		for idx in range(1, n - 1):
			if permutation[idx] > permutation[idx - 1] and permutation[idx] > permutation[idx + 1]:
				print('YES')
				print(idx, idx + 1, idx + 2)
				break
		else:
			print('NO')
	return

def three_friends():
	for test_cases in range(int(input())):
		coords = list(map(int, input().split()))
		coords_neu = sorted(coords)
		if coords_neu[2] - coords_neu[0] <= 2:
			print(0)
		else:
			print(2 * (coords_neu[2] - coords_neu[0]) - 4)
	return
three_friends()


n = int(input())
anw = []
for _ in range(n):
	positions = list(map(int, input().split()))
	positions.sort()
	if positions[1] == positions[0] and positions[0] == positions[2]:
		anw.append(0)
	elif positions[1] == positions[0]:
		if abs(positions[2] - positions[0]) == 1:
			positions[2] -= 1
			anw.append(abs(positions[0] - positions[1]) + abs(positions[1] - positions[2]) + abs(positions[0] - positions[2]))
		else:
			positions[2] -= 1
			positions[0] += 1
			positions[1] += 1
			anw.append(abs(positions[0] - positions[1]) + abs(positions[1] - positions[2]) + abs(positions[0] - positions[2]))
	elif positions[1] == positions[2]:
		if abs(positions[0] - positions[1]) == 1:
			positions[0] += 1
			anw.append(abs(positions[0] - positions[1]) + abs(positions[1] - positions[2]) + abs(positions[0] - positions[2]))
		else:
			positions[0] += 1
			positions[1] -= 1
			positions[2] -= 1
			anw.append(abs(positions[0] - positions[1]) + abs(positions[1] - positions[2]) + abs(positions[0] - positions[2]))
	else:
		positions.sort()
		positions[0] += 1
		positions[2] -= 1
		anw.append(abs(positions[0] - positions[1]) + abs(positions[1] - positions[2]) + abs(positions[0] - positions[2]))
[print('{}'.format(str(x))) for x in anw]


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	mn = min(a, min(b, c))
	mx = max(a, max(b, c))
	md = a + b + c - mn - mx
	if md == mx and md == mn:
		print(0)
	elif md == mx:
		print(min(abs(2 * (md - mn - 2)), abs(2 * (md - mn - 1))))
	elif md == mn:
		print(min(abs(2 * (mx - mn - 2)), abs(2 * (mx - mn - 1))))
	else:
		print(abs(mx - 1 - mn + (md - mn - 1) + (mx - md - 2)))


def form(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
while True:
	x = int(input(''))
	if 1 <= x <= 10 ** 9:
		break
d = []
for k in range(x):
	n = input('')
	d.append(n.split(' '))
for i in range(len(d)):
	for j in range(len(d[i])):
		d[i][j] = int(d[i][j])
	d[i].sort()
for s in range(x):
	if d[s][0] < d[s][1] < d[s][2]:
		print(form(d[s][0] + 1, d[s][1], d[s][2] - 1))
	elif d[s][0] == d[s][1] and d[s][1] < d[s][2]:
		if abs(d[s][1] - d[s][2]) > 1:
			print(form(d[s][0] + 1, d[s][1] + 1, d[s][2] - 1))
		else:
			print('0')
	elif d[s][0] < d[s][1] and d[s][1] == d[s][2]:
		if abs(d[s][1] - d[s][0]) > 1:
			print(form(d[s][0] + 1, d[s][1] - 1, d[s][2] - 1))
		else:
			print('0')
	else:
		print(0)


t = int(input())
for i in range(t):
	d = [int(x) for x in input().split()]
	d.sort()
	(a, b, c) = (d[0], d[1], d[2])
	if a == b == c:
		print(0)
	elif a == b or b == c:
		res = abs(a - b) + abs(b - c) + abs(a - c) - 4
		print(max(0, res))
	elif abs(a - b) >= abs(a - c) and abs(a - b) >= abs(b - c):
		a += 1
		b -= 1
		res = abs(a - b) + abs(b - c) + abs(a - c)
		c -= 1
		res1 = abs(a - b) + abs(b - c) + abs(a - c)
		print(min(res, res1))
	elif abs(a - c) >= abs(a - b) and abs(a - c) >= abs(b - c):
		a += 1
		c -= 1
		res = abs(a - b) + abs(b - c) + abs(a - c)
		b += 1
		res1 = abs(a - b) + abs(b - c) + abs(a - c)
		b -= 2
		res2 = abs(a - b) + abs(b - c) + abs(a - c)
		print(min(res, res1, res2))
	elif abs(b - c) >= abs(a - b) and abs(a - c) <= abs(b - c):
		b += 1
		c -= 1
		res = abs(a - b) + abs(b - c) + abs(a - c)
		a += 1
		res1 = abs(a - b) + abs(b - c) + abs(a - c)
		print(min(res, res1))


for _ in range(int(input())):
	(a, b, c) = sorted(list(map(int, input().split())))
	if a == b and b == c:
		print(0)
	elif a == b or b == c:
		if abs(a - b) + abs(b - c) + abs(a - c) == 2:
			print(0)
		else:
			print(abs(a - b) + abs(b - c) + abs(a - c) - 4)
	else:
		print(abs(a - b) + abs(b - c) + abs(a - c) - 4)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().strip().split())
	print(max(0, abs(a - b) + abs(c - b) + abs(a - c) - 4))


for _ in range(int(input())):
	lst = list(map(int, input().split()))
	a = abs(lst[0] - lst[1])
	b = abs(lst[0] - lst[2])
	c = abs(lst[2] - lst[1])
	print(max(a + b + c - 4, 0))


def examA():
	Q = I()
	ans = []
	for _ in range(Q):
		a = LI()
		a.sort()
		if a[0] == a[1]:
			if a[1] == a[2]:
				ans.append(0)
				continue
			else:
				a[0] += 1
				a[1] += 1
				if a[1] != a[2]:
					a[2] -= 1
		else:
			a[0] += 1
			if a[1] != a[2]:
				a[2] -= 1
			elif a[0] != a[1]:
				a[1] -= 1
				a[2] -= 1
		cur = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
		ans.append(cur)
	for v in ans:
		print(v)

def examB():
	return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
inf = float('inf')
examA()


from collections import defaultdict as dc
from collections import deque as dq
from bisect import bisect_left, bisect_right, insort_left
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def bs(a, b):
	l = a
	r = b + 1
	x = b
	ans = 0
	while l < r:
		mid = (l + r) // 2
		if x | mid > ans:
			ans = x | mid
			l = mid + 1
		else:
			r = mid
	return ans

def digit(n):
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	return a

def value(a, p, c):
	return abs(a - p) + abs(p - c) + abs(a - c)
for _ in range(inp()):
	z = line()
	z.sort()
	(a, b, c) = z
	ans = value(a, b, c)
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				ans = min(ans, value(a + i, b + j, c + k))
	print(ans)


test = int(input())
for _ in range(test):
	mas = list(map(int, input().split()))
	mas.sort()
	if mas[0] < mas[1]:
		mas[0] += 1
	elif mas[0] == mas[1] and mas[0] < mas[2]:
		mas[0] += 1
	if mas[1] < mas[0] and mas[2] > mas[1]:
		mas[1] += 1
	elif mas[1] > mas[0] and mas[1] == mas[2]:
		mas[1] -= 1
	elif mas[1] == mas[0] and mas[1] < mas[2] - 1:
		mas[1] += 1
	if mas[1] < mas[2] or mas[1] < mas[2]:
		mas[2] -= 1
	print(abs(mas[0] - mas[1]) + abs(mas[0] - mas[2]) + abs(mas[2] - mas[1]))


from math import *
t = int(input())
while t > 0:
	a = []
	a = [int(x) for x in input().split()]
	a.sort()
	if a[1] == a[0] and a[1] == a[2]:
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	elif a[1] == a[0]:
		if a[2] - a[1] > 1:
			a[0] += 1
			a[1] += 1
			a[2] -= 1
		else:
			a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	elif a[1] == a[2]:
		if a[1] - a[0] > 1:
			a[0] += 1
			a[1] -= 1
			a[2] -= 1
		else:
			a[0] += 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	else:
		a[0] += 1
		a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	t -= 1


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	(a, b, c) = kk()
	v = 10 ** 10
	for i in range(-1, 2, 1):
		d = a + i
		for j in range(-1, 2, 1):
			e = b + j
			for k in range(-1, 2, 1):
				f = c + k
				v = min(v, abs(d - e) + abs(d - f) + abs(e - f))
	print(v)
exit()


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 100000000007
for t in range(I()):
	(a, b, c) = In()
	a1 = [a - 1, a, a + 1]
	b1 = [b - 1, b, b + 1]
	c1 = [c - 1, c, c + 1]
	mn = P
	for i in a1:
		for j in b1:
			for k in c1:
				mn = min(mn, abs(i - j) + abs(j - k) + abs(i - k))
	print(mn)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a, b, c) = sorted(map(int, stdin.readline().split()))
	dist = abs(a - b) + abs(a - c) + abs(b - c) - 4
	if dist < 0:
		dist = 0
	print(dist)


for _ in range(int(input())):
	a = [int(x) for x in input().split()]
	a.sort()
	a[0] += 1
	a[-1] -= 1
	print(max(0, 2 * (a[1] - a[0] + a[2] - a[1])))


t = int(input())
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	ans = max(abs(a - b) + abs(b - c) + abs(c - a) - 4, 0)
	print(ans)


def solve():
	a = list(map(int, input().strip().split()))
	a.sort()
	if a[0] < a[2]:
		a[0] += 1
	if a[2] > a[0]:
		a[2] -= 1
	print(a[2] * 2 - 2 * a[0], end='\n')
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())
import collections as c
for i in range(t):
	pos = input().split()
	pos = [int(x) for x in pos]
	count = c.Counter(pos)
	count = dict(sorted(count.items()))
	if len(count) == 1:
		print(0)
	elif len(count) == 2:
		key = list(count.keys())
		val = 0
		if key[1] - key[0] < 2:
			val = 0
		else:
			val = 2 * (key[1] - key[0]) - 4
		print(val)
	else:
		key = list(count.keys())
		print(2 * (key[2] - key[0]) - 4)


tc = int(input())
for _ in range(tc):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] != l[1]:
		l[0] += 1
	elif l[0] != l[2]:
		l[0] += 1
	if l[0] < l[1]:
		l[1] -= 1
	elif l[1] != l[2] and l[0] != l[1]:
		l[1] += 1
	if l[2] != l[1]:
		l[2] -= 1
	print(l[1] - l[0] + l[2] - l[1] + l[2] - l[0])


q = int(input())
for i in range(0, q):
	a = [int(j) for j in input().split()]
	a.sort()
	s = 0
	if a[2] == a[1] and abs(a[0] - a[1]) > 1 and (abs(a[2] - a[0]) > 1):
		a[2] = a[2] - 1
		a[1] = a[1] - 1
		a[0] = a[0] + 1
	elif a[0] == a[1] and abs(a[2] - a[1]) > 1 and (abs(a[2] - a[0]) > 1):
		a[0] = a[0] + 1
		a[1] = a[1] + 1
		a[2] = a[2] - 1
	else:
		if abs(a[1] - a[0]) > 0:
			a[0] = a[0] + 1
		if abs(a[2] - a[1]) > 0:
			a[2] = a[2] - 1
	s = abs(a[1] - a[0]) + abs(a[2] - a[1]) + abs(a[2] - a[0])
	print(s)


t = int(input())
for test in range(t):
	x = [int(x) for x in input().split()]
	x.sort()
	if x[0] == x[1] and x[1] == x[2]:
		print(0)
	elif x[0] == x[1]:
		x[2] -= 1
		if x[2] == x[1]:
			print(0)
			continue
		x[0] += 1
		x[1] += 1
		print(2 * (x[2] - x[1]))
	elif x[2] == x[1]:
		x[0] += 1
		if x[0] == x[1]:
			print(0)
			continue
		x[1] -= 1
		x[2] -= 1
		print(2 * (x[1] - x[0]))
	else:
		x[0] += 1
		x[2] -= 1
		print(abs(x[2] - x[1]) + abs(x[1] - x[0]) + abs(x[0] - x[2]))


for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	da = [a, a - 1, a + 1]
	db = [b, b - 1, b + 1]
	dc = [c, c - 1, c + 1]
	ans = 10 ** 12
	for i in da:
		for j in db:
			for k in dc:
				ans = min(ans, abs(i - j) + abs(i - k) + abs(j - k))
	print(ans)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l.sort()
	temp = 2 * (l[2] - l[0])
	temp = temp - 4
	if temp < 0:
		print('0')
	else:
		print(temp)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	nums = list(map(int, sys.stdin.readline().split()))
	nums = sorted(nums)
	mid = nums[1]
	judge1 = True
	same = []
	for i in range(len(nums)):
		if mid != nums[i]:
			judge1 = False
		else:
			same.append(i)
	if judge1 == True:
		print('0')
	else:
		for i in range(len(nums)):
			if mid == nums[i]:
				pass
			elif mid > nums[i]:
				nums[i] += 1
			elif mid < nums[i]:
				nums[i] -= 1
		if same == [0, 1] and nums[1] < nums[2]:
			nums[0] += 1
			nums[1] += 1
		elif same == [1, 2] and nums[1] > nums[0]:
			nums[1] -= 1
			nums[2] -= 1
		print(abs(nums[0] - nums[1]) + abs(nums[0] - nums[2]) + abs(nums[1] - nums[2]))


n = int(input())
l = [[int(j) for j in input().split()] for i in range(n)]
for i in range(n):
	sort = sorted(list(set(l[i])))
	if len(sort) == 1:
		print(0)
	elif len(sort) == 2:
		if sort[1] - sort[0] == 1:
			print(2 * abs(sort[1] - 1 - sort[0]))
		else:
			print(2 * abs(sort[1] - 1 - sort[0] - 1))
	else:
		print(sort[1] - sort[0] - 1 + (sort[2] - 1 - sort[1]) + (sort[2] - 1 - sort[0] - 1))


entrada = int(input())
for i in range(entrada):
	lista = list(input().split(' '))
	lista.sort()
	a = int(lista[0])
	b = int(lista[1])
	c = int(lista[2])
	medio = (a + c) // 2
	if a > medio:
		a = a - 1
	elif a < medio:
		a = a + 1
	if b > medio:
		b = b - 1
	elif b < medio:
		b = b + 1
	if c > medio:
		c = c - 1
	elif c < medio:
		c += 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	d = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = a - i
				y = b - j
				z = c - k
				d.append(abs(x - y) + abs(y - z) + abs(z - x))
	print(min(d))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	k1 = l[1] - l[0]
	k2 = l[2] - l[1]
	k3 = l[2] - l[0]
	k4 = k1 + k2 + k3
	if k4 == 0 or k4 == 1 or k4 == 2 or (k4 == 3) or (k4 == 4):
		print(0)
	else:
		print(k4 - 4)


num = int(input())
for i in range(num):
	read = input().split()
	a = int(read[0])
	b = int(read[1])
	c = int(read[2])
	d = min(a, b, c)
	e = max(a, b, c)
	if e - d >= 2:
		f = (e - d - 2) * 2
	if e - d <= 2:
		f = 0
	print(f)


from math import *
for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if len(set(a)) == 3:
		a[0] += 1
		a[2] -= 1
	elif len(set(a)) == 1:
		a[0] = a[0]
		a[2] = a[2]
	elif a[0] == a[1]:
		a[0] += 1
		a[1] += 1
		if a[1] == a[2]:
			a[2] = a[2]
		else:
			a[2] -= 1
	elif a[1] == a[2]:
		a[1] -= 1
		a[2] -= 1
		if a[1] == a[0]:
			a[0] = a[0]
		else:
			a[0] += 1
	ans = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
	print(ans)


t = int(input())
while t:
	t -= 1
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[2]:
		print(0)
		continue
	if a[1] == a[2]:
		a[0] += 1
		if a[2] - a[0] + 1 >= 2:
			a[2] -= 1
			a[1] -= 1
	elif a[0] == a[1]:
		a[2] -= 1
		if a[2] - a[0] + 1 >= 2:
			a[0] += 1
			a[1] += 1
	else:
		a[0] += 1
		a[2] -= 1
	x = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
	print(x)


def dist(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
q = int(input())
while q:
	q -= 1
	ar = list(map(int, input().split()))
	ar.sort()
	if ar[0] == ar[1] == ar[2]:
		print(0)
	elif ar[0] == ar[1]:
		if ar[2] - 1 == ar[0]:
			print(dist(ar[0], ar[0], ar[2] - 1))
		else:
			print(dist(ar[0] + 1, ar[0] + 1, ar[2] - 1))
	elif ar[1] == ar[2]:
		if ar[0] + 1 == ar[1]:
			print(dist(ar[0] + 1, ar[1], ar[2]))
		else:
			print(dist(ar[0] + 1, ar[1] - 1, ar[2] - 1))
	else:
		print(dist(ar[0] + 1, ar[1], ar[2] - 1))


q = int(input())
ls = []
for i in range(q):
	(a, b, c) = sorted(map(int, input().split()))
	k = 2 * c - 2 * a - 4
	if k < 0:
		k = 0
	ls.append(k)
for i in range(q):
	print(ls[i])


sum_dist = lambda a, b, c: abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	frens = sorted(list(map(int, input().split())))
	mid = (frens[0] + frens[2]) // 2
	tar = []
	for fren in frens:
		if fren > mid:
			tar.append(fren - 1)
		elif fren < mid:
			tar.append(fren + 1)
		else:
			tar.append(fren)
	print(sum_dist(*tar))


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	d = abs(a - b) + abs(a - c) + abs(b - c)
	print(max(0, d - 4))


def isAnagram(str1, str2):
	return sorted(str1) == sorted(str2)
t = int(input())
for c in range(0, t):
	s1 = [int(i) for i in input().split()]
	so = round(sum(s1) / 3)
	for g in range(0, 3):
		if s1[g] > so:
			s1[g] -= 1
		elif s1[g] < so:
			s1[g] += 1
		else:
			s1[g] = s1[g]
	s2 = abs(s1[0] - s1[1]) + abs(s1[1] - s1[2]) + abs(s1[0] - s1[2])
	print(s2)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	print(2 * max(max(a, b, c) - min(a, b, c) - 2, 0))


q = int(input())
a = []
s = []
for i in range(q):
	a = map(int, input().split(maxsplit=3))
	b = list(a)
	if b[0] == b[1] and b[1] == b[2] and (b[0] == b[2]):
		m = 0
	elif abs(b[0] - b[1]) == 1 and abs(b[0] - b[2]) == 1 or (abs(b[0] - b[1]) == 1 and abs(b[1] - b[2]) == 1) or (abs(b[0] - b[2]) == 1 and abs(b[1] - b[2]) == 1):
		m = 0
	elif b[0] == b[1] or b[2] == b[1] or b[0] == b[2]:
		k = b.pop(b.index(min(b)))
		l = b.pop(b.index(max(b)))
		m = abs(k + 1 - l + 1) * 2
	else:
		l = b.pop(b.index(max(b)))
		k = b.pop(b.index(min(b)))
		m = abs(l - 1 - k - 1) + abs(l - 1 - b[0]) + abs(k + 1 - b[0])
	s.append(m)
for i in range(q):
	print(s[i])


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	l[0] += 1
	l[2] -= 1
	x = l[2] - l[0] + l[1] - l[0] + l[2] - l[1]
	if x >= 0:
		print(x)
	else:
		print(0)


for i in range(0, int(input())):
	ip = input().split(' ')
	ip = list(map(lambda a: int(a), ip))
	ip.sort()
	if abs(min(ip) - max(ip)) >= 2:
		print(abs(ip[0] + 1 - (ip[2] - 1)) * 2)
	else:
		print(0)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	diff = a[2] - a[0]
	m = (diff - 2) * 2
	if m <= 0:
		print('0')
	else:
		print(str(m))


def __pairwise_distance__(friends):
	a1 = abs(friends[0] - friends[1])
	a2 = abs(friends[1] - friends[2])
	a3 = abs(friends[2] - friends[0])
	return a1 + a2 + a3

def make_closer(friends):
	small = min(friends)
	big = max(friends)
	mid = small + (big - small) // 2
	for i in range(3):
		if friends[i] > mid:
			friends[i] -= 1
		elif friends[i] < mid:
			friends[i] += 1
	return __pairwise_distance__(friends)

def solution(inp):
	return make_closer(inp)

def main():
	inp1 = input()
	length = int(inp1)
	result = []
	for i in range(length):
		inputs = list(map(int, input().split()))
		result.append(solution(inputs))
	print(*result, sep='\n', end='')
main()


t = int(input())
z = 0
while t > 0:
	a = list(map(int, input().split()))
	a.sort()
	if a[2] - a[0] <= 2:
		print(z)
	else:
		print(2 * (a[2] - a[0]) - 4)
	t -= 1


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	sum = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0])
	if sum <= 4:
		print(0)
	else:
		print(sum - 4)


import sys
input = sys.stdin.readline
for test in range(int(input())):
	a = sorted([int(i) for i in input().split()])
	if a[0] == a[1] and a[1] == a[2]:
		res = 0
	else:
		res = 4
	ans = abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2])
	print(max(0, ans - res))


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	(left, right) = (min(a, b, c), max(a, b, c))
	if right - left <= 2:
		print(0)
	else:
		print((right - left - 2) * 2)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	L = [a, b, c]
	L.sort()
	if L[0] == L[1] and L[1] == L[2]:
		L[0] = L[0]
	elif L[0] == L[1] and L[1] != L[2]:
		L[0] += 1
		L[1] += 1
		if L[2] != L[1]:
			L[2] -= 1
	elif L[0] != L[1] and L[1] == L[2]:
		L[1] -= 1
		L[2] -= 1
		if L[0] != L[1]:
			L[0] += 1
	else:
		if L[0] != L[1]:
			L[0] += 1
		if L[-1] != L[1]:
			L[-1] -= 1
	ans = abs(L[0] - L[1]) + abs(L[0] - L[2]) + abs(L[1] - L[2])
	print(ans)


T = int(input())
while T > 0:
	T -= 1
	s = input().split()
	a = [int(s[0]), int(s[1]), int(s[2])]
	a.sort()
	ans = a[1] - a[0] + a[2] - a[0] + a[2] - a[1]
	if ans - 4 < 0:
		print(0)
	else:
		print(ans - 4)


for _ in range(int(input())):
	f = list(map(int, input().split()))
	f.sort()
	a = f[0]
	b = f[1]
	c = f[2]
	ans = 0
	if a == b == c:
		ans = 0
	else:
		if a == b < c:
			c -= 1
			if c > b:
				a += 1
		elif a < b == c:
			a += 1
			if a < b:
				c -= 1
		else:
			a += 1
			c -= 1
		ans = 2 * (c - a)
	print(ans)


t = int(input())
for _ in range(t):
	arr = list(map(int, input().split()))
	arr.sort()
	a = arr[1] - arr[0]
	b = arr[2] - arr[1]
	if a * b >= 1:
		print(2 * (a + b - 2))
	elif a == 0 and b == 0:
		print(0)
	elif b == 0:
		print(max(0, 2 * (a - 2)))
	else:
		print(max(0, 2 * (b - 2)))


def distance(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def minimum(a, b, c):
	lst = []
	valer = [-1, 0, 1]
	for i in range(3):
		iadd = a + valer[i]
		for j in range(3):
			jadd = b + valer[j]
			for k in range(3):
				kadd = c + valer[k]
				lst.append(distance(iadd, jadd, kadd))
	return min(lst)

def main():
	n = eval(input())
	for i in range(n):
		at = input()
		at = at.split()
		a = eval(at[0])
		b = eval(at[1])
		c = eval(at[2])
		print(minimum(a, b, c))
main()


tc = int(input())
for i in range(tc):
	arr = [int(x) for x in input().split()]
	arr.sort()
	mid = round((arr[0] + arr[2]) / 2)
	for i in range(3):
		if arr[i] < mid:
			arr[i] += 1
		elif arr[i] > mid:
			arr[i] -= 1
	print(abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2]))


def tpd(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	goal = round((a + b + c) / 3)
	fs = [a, b, c]
	for f in range(3):
		if goal < fs[f]:
			fs[f] -= 1
		elif goal > fs[f]:
			fs[f] += 1
	print(tpd(fs[0], fs[1], fs[2]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	pd = abs(a - b) + abs(b - c) + abs(a - c)
	for x in range(-1, 2):
		for y in range(-1, 2):
			for z in range(-1, 2):
				(a1, b1, c1) = (a + x, b + y, c + z)
				pd = min(pd, abs(a1 - b1) + abs(b1 - c1) + abs(a1 - c1))
	print(pd)


def solve(case: list):
	if case[0] == case[1] == case[2]:
		pass
	elif case[0] == case[1]:
		case[2] -= 1
		if not case[0] == case[1] == case[2]:
			case[0] += 1
			case[1] += 1
	elif case[1] == case[2]:
		case[0] += 1
		if not case[0] == case[1] == case[2]:
			case[1] -= 1
			case[2] -= 1
	else:
		case[2] -= 1
		case[0] += 1
	return (case[1] - case[0] + (case[2] - case[1])) * 2
casenum = int(input())
for _ in range(casenum):
	case = input().split()
	case = [int(c) for c in case]
	case.sort()
	print(solve(case))


n = int(input())
for i in range(n):
	x1 = list(map(int, input().split()))
	x1.sort()
	l1 = x1[0]
	l2 = x1[1]
	l3 = x1[2]
	if l3 > l1:
		l3 = l3 - 1
		if l3 > l1:
			l1 = l1 + 1
			l2 = l2 + 1
		elif l3 > l1:
			l1 = l1 + 1
	elif l2 > l1:
		l1 = l1 + 1
	print(l3 - l2 + l2 - l1 + l3 - l1)


import sys
import math
import itertools
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
q = ii()
for _ in range(q):
	a = li()
	t = max(0, max(a) - 2 - min(a))
	print(2 * abs(t))


moves = [-1, 1, 0]

def backtrack(val, ind):
	if ind > 2:
		return abs(val[0] - val[1]) + abs(val[0] - val[2]) + abs(val[1] - val[2])
	ans = 10 ** 11 + 1
	for i in range(3):
		val[ind] += moves[i]
		ans = min(ans, backtrack(val, ind + 1))
		val[ind] -= moves[i]
	return ans
q = int(input())
while q > 0:
	q -= 1
	(a, b, c) = map(int, input().split())
	print(backtrack([a, b, c], 0))


q = int(input())
for i in range(q):
	data = list(map(int, input().split()))
	data.sort()
	if abs(data[0] - data[1]) == 0 and abs(data[1] - data[2]) == 0:
		distance = 0
		print(distance)
		continue
	if abs(data[0] - data[1]) == 0:
		data[0] += 1
		data[1] += 1
		if data[1] != data[2]:
			data[2] -= 1
		distance = abs(data[0] - data[1]) + abs(data[0] - data[2]) + abs(data[1] - data[2])
		print(distance)
		continue
	if abs(data[1] - data[2]) == 0:
		data[2] -= 1
		data[1] -= 1
		if data[1] != data[0]:
			data[0] += 1
		distance = abs(data[0] - data[1]) + abs(data[0] - data[2]) + abs(data[1] - data[2])
		print(distance)
		continue
	data[0] += 1
	data[2] -= 1
	distance = abs(data[0] - data[1]) + abs(data[0] - data[2]) + abs(data[1] - data[2])
	print(distance)


q = int(input())
for _ in range(q):
	a = sorted(list(map(int, input().split())))
	if a[2] - a[0] > 1:
		print((a[2] - a[0] - 2) * 2)
	else:
		print(0)


t = int(input())
while t:
	t -= 1
	(a, b, c) = map(int, input().split())
	s = 0
	if a == b and b == c and (c == a):
		print('0')
	elif abs(a - b) >= 1 and abs(b - c) >= 1 and (abs(c - a) >= 1):
		mini = min(a, b, c)
		maxi = max(a, b, c)
		med = a + b + c - (mini + maxi)
		mini += 1
		maxi -= 1
		s += abs(med - mini)
		s += abs(maxi - med)
		s += abs(maxi - mini)
		print(s)
	elif a == b and abs(b - c) == 1:
		print('0')
	elif b == c and abs(b - a) == 1:
		print('0')
	elif c == a and abs(c - b) == 1:
		print('0')
	else:
		mini = min(a, b, c)
		maxi = max(a, b, c)
		s = 0
		temp = a + b + c - (mini + maxi)
		if temp == mini:
			temp += 1
			mini += 1
			maxi -= 1
		else:
			mini += 1
			maxi -= 1
			temp -= 1
		s += abs(temp - mini)
		s += abs(maxi - mini)
		s += abs(temp - maxi)
		print(s)


q = int(input())
for _ in range(q):
	a = list(map(int, input().split()))
	a.sort()
	c = []
	b0 = []
	b0.append(a[0] - 1)
	b0.append(a[0])
	b0.append(a[0] + 1)
	b1 = []
	b1.append(a[1] - 1)
	b1.append(a[1])
	b1.append(a[1] + 1)
	b2 = []
	b2.append(a[2] - 1)
	b2.append(a[2])
	b2.append(a[2] + 1)
	for i in range(3):
		for j in range(3):
			for k in range(3):
				c.append(abs(b0[i] - b1[j]) + abs(b1[j] - b2[k]) + abs(b0[i] - b2[k]))
	print(min(c))


t = int(input())
while t > 0:
	num = input().split()
	n1 = []
	for i in num:
		n1.append(int(i))
	n1.sort()
	mini = n1[0]
	mid = n1[1]
	maxi = n1[2]
	if mini != mid and maxi != mid:
		if mini != mid:
			mini += 1
		if maxi != mid:
			maxi -= 1
	elif mini == mid or mid == maxi:
		if mini == mid:
			if mini == mid and maxi - mid == 1:
				maxi -= 1
			elif maxi - mid != 0:
				mini += 1
				mid += 1
				maxi -= 1
		elif maxi == mid:
			if maxi == mid and mid - mini == 1:
				mini += 1
			elif mid - mini != 0:
				mini += 1
				mid -= 1
				maxi -= 1
	print(2 * (maxi - mini))
	t -= 1


def hitung(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
dist = [-1, 1, 0]
q = int(input())
for _ in range(q):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	res = hitung(a, b, c)
	for da in dist:
		for db in dist:
			for dc in dist:
				res = min(res, hitung(a + da, b + db, c + dc))
	print(res)


t = int(input())
for _ in range(t):
	(*arr,) = map(int, input().split())
	arr.sort()
	if abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) <= 2:
		print(0)
	else:
		if arr[1] - arr[0] == 1:
			if arr[2] - arr[1] >= 1:
				arr[0] += 1
				arr[2] -= 1
			elif arr[2] - arr[1] == 0:
				arr[0] += 1
		elif arr[1] - arr[0] == 0:
			if arr[2] - arr[1] >= 1:
				arr[0] += 1
				arr[1] += 1
				arr[2] -= 1
		else:
			arr[0] += 1
			arr[1] -= 1
			arr[2] -= 1
		print(abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split(' '))
	new_a = [a - 1, a, a + 1]
	new_b = [b - 1, b, b + 1]
	new_c = [c - 1, c, c + 1]
	dist = abs(a - b) + abs(a - c) + abs(b - c)
	for x in range(3):
		for y in range(3):
			for z in range(3):
				dist = min(dist, abs(new_a[x] - new_b[y]) + abs(new_b[y] - new_c[z]) + abs(new_a[x] - new_c[z]))
	print(dist)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = min(a, b, c)
	y = max(a, b, c)
	if y - x <= 2:
		print(0)
	else:
		print(2 * (y - x - 2))


t = int(input())
for i in range(t):
	q = list(map(int, input().split()))
	q.sort()
	middle_point = int((max(q) + min(q)) / 2)
	for j in range(len(q)):
		if q[j] < middle_point:
			q[j] += 1
		elif q[j] > middle_point:
			q[j] -= 1
	print(abs(q[0] - q[1]) + abs(q[0] - q[2]) + abs(q[1] - q[2]))


def calc(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	result = calc(a, b, c)
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				na = a + i
				nb = b + j
				nc = c + k
				result = min(result, calc(na, nb, nc))
	print(result)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = pow(10, 10)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				na = a + i
				nb = b + j
				nc = c + k
				ans = min(ans, abs(na - nb) + abs(nb - nc) + abs(nc - na))
	print(ans)


import math
t = int(input())
for i in range(t):
	array = list(map(int, input().split()))
	a = array[0]
	b = array[1]
	c = array[2]
	friends = sorted([a, b, c])
	if friends[0] == friends[1] and friends[1] == friends[2]:
		a = friends[0]
		c = friends[2]
		b = friends[1]
	elif friends[0] != friends[1] and friends[1] != friends[2]:
		a = friends[0] + 1
		c = friends[2] - 1
		b = friends[1]
	elif friends[0] == friends[1] and friends[1] + 1 != friends[2]:
		a = friends[0] + 1
		b = friends[1] + 1
		c = friends[2] - 1
	elif friends[1] == friends[2] and friends[1] - 1 != friends[0]:
		a = friends[0] + 1
		b = friends[1] - 1
		c = friends[2] - 1
	elif friends[0] == friends[1]:
		a = friends[0] + 1
		b = friends[1] + 1
		c = friends[2]
	elif friends[1] == friends[2]:
		a = friends[0]
		b = friends[1] - 1
		c = friends[2] - 1
	result = abs(a - b) + abs(b - c) + abs(a - c)
	print(result)


from math import *
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	s = 0
	if l[0] == l[1] and l[1] == l[2]:
		pass
	elif l[0] != l[1] and l[1] != l[2]:
		l[0] = l[0] + 1
		l[2] = l[2] - 1
	elif l[0] == l[1] and l[1] != l[2]:
		if l[2] - l[1] == 1:
			l[2] = l[2] - 1
		else:
			l[2] = l[2] - 1
			l[0] = l[0] + 1
			l[1] = l[1] + 1
	elif l[1] == l[2] and l[0] != l[1]:
		if l[1] - l[0] == 1:
			l[0] = l[0] + 1
		else:
			l[0] = l[0] + 1
			l[1] = l[1] - 1
			l[2] = l[2] - 1
	s = abs(l[1] - l[0]) + abs(l[2] - l[0]) + abs(l[2] - l[1])
	print(s)


def cal(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = cal(a, b, c)
	for da in range(-1, 2):
		for db in range(-1, 2):
			for dc in range(-1, 2):
				na = a + da
				nb = b + db
				nc = c + dc
				ans = min(ans, cal(na, nb, nc))
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] < a[1]:
		a[0] += 1
	elif a[1] == a[0] and a[1] < a[2]:
		a[0] += 1
		a[1] += 1
	if a[1] < a[2]:
		a[2] -= 1
	elif a[2] == a[1] and a[1] > a[0]:
		a[2] -= 1
		a[1] -= 1
	ans = a[2] - a[1] + (a[2] - a[0]) + (a[1] - a[0])
	print(ans)


def calc(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	ans = 10000000000.0
	(x, y, z) = map(int, input().split())
	for f in range(-1, 2):
		for s in range(-1, 2):
			for l in range(-1, 2):
				ans = min(ans, calc(x - f, y - s, z - l))
	print(ans)


for i in range(int(input())):
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	q = [a, b, c]
	q.sort()
	if a == b and b == c:
		print('0')
	elif q[0] == q[1]:
		if abs(q[1] - q[2]) > 1:
			q[2] -= 1
		print(2 * abs(q[0] + 1 - q[2]))
	elif q[1] == q[2]:
		if abs(q[1] - q[0]) > 1:
			q[0] += 1
		print(2 * abs(q[2] - 1 - q[0]))
	else:
		print(abs(q[0] + 1 - q[1]) + abs(q[0] + 1 - (q[2] - 1)) + abs(q[1] - (q[2] - 1)))


def solve(a, b, c):
	k = abs(a - b)
	l = abs(b - c)
	m = abs(a - c)
	sum = k + l + m
	sum -= 4
	if sum < 0:
		print(0)
	else:
		print(sum)
t = int(input())
while t:
	t -= 1
	(k, l, m) = map(int, input().split())
	solve(k, l, m)


t = int(input())
while t > 0:
	t -= 1
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] and a[1] == a[2]:
		print(a[2] - a[0] + a[2] - a[1] + a[1] - a[0])
	elif a[0] == a[1]:
		a[2] -= 1
		if a[2] != a[1]:
			a[1] += 1
			a[0] += 1
		print(a[2] - a[0] + a[2] - a[1] + a[1] - a[0])
	elif a[1] == a[2]:
		a[0] += 1
		if a[0] != a[1]:
			a[2] -= 1
			a[1] -= 1
		print(a[2] - a[0] + a[2] - a[1] + a[1] - a[0])
	else:
		a[0] += 1
		if a[0] == a[1]:
			a[2] -= 1
		else:
			a[2] -= 1
			a[1] -= 1
		print(a[2] - a[0] + a[2] - a[1] + a[1] - a[0])


def f(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
n = int(input())
for i in range(n):
	m = list(map(int, input().split()))
	m.sort()
	if m[0] != m[1] != m[2]:
		m[0] += 1
		m[2] -= 1
		print(f(m[0], m[1], m[2]))
	elif m[0] == m[1] == m[2]:
		print(f(m[0], m[1], m[2]))
	elif m[0] == m[1]:
		m[0] += 1
		m[1] += 1
		if not m[0] == m[1] == m[2]:
			m[2] -= 1
		print(f(m[0], m[1], m[2]))
	elif m[1] == m[2]:
		m[1] -= 1
		m[2] -= 1
		if not m[0] == m[1] == m[2]:
			m[0] += 1
		print(f(m[0], m[1], m[2]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a == b == c:
		print(0)
	elif a == b or b == c or a == c:
		print(max(0, abs(a - b) + abs(b - c) + abs(c - a) - 4))
	else:
		print(2 * (max(a, b, c) - min(a, b, c) - 2))


i = input
exec(int(i()) * 'a,b,c=sorted(map(int,i().split()));print(max(2*(c-a-2),0));')


t = int(input())
while t > 0:
	(a, b, c) = [int(i) for i in input().split()]
	sum = abs(a - b) + abs(b - c) + abs(a - c)
	if sum > 4:
		sum = sum - 4
	else:
		sum = 0
	print(sum)
	t -= 1


def function(a, b, c):
	(a, b, c) = (min(a, b, c), min(max(a, b), max(a, c), max(b, c)), max(a, b, c))
	a += 1
	c -= 1
	result = 2 * (c - a)
	if result < 0:
		result = 0
	print(result)
q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	function(a, b, c)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))

def cal(a, b, c):
	return abs(b - a) + abs(c - a) + abs(c - b)
for _ in range(get_int()):
	lst = get_int_list()
	mini = float('inf')
	for i in range(lst[0] - 1, lst[0] + 2):
		for j in range(lst[1] - 1, lst[1] + 2):
			for k in range(lst[2] - 1, lst[2] + 2):
				mini = min(mini, cal(i, j, k))
	print(mini)


for _ in ' ' * int(input()):
	a = sorted(list(map(int, input().split())))
	print(max(0, a[1] - 1 - a[0] - 1 + a[2] - 1 - a[0] - 1 + a[2] - a[1]))


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	(a, b, c) = (max(a, b, c), a + b + c - max(a, b, c) - min(a, b, c), min(a, b, c))
	print(min(2 * (a - c), abs(2 * (a - c) - 4), abs(2 * (a - c) - 2)))


def distance(x, y, z):
	return abs(x - y) + abs(x - z) + abs(y - z)
for _ in range(int(input())):
	x = sorted(list(map(int, input().split())))
	(a, b, c) = x[0:]
	if a == b == c:
		print(0)
	elif a == b:
		print(min(distance(a, b, c - 1), distance(a + 1, b + 1, c - 1)))
	elif b == c:
		print(min(distance(a + 1, b, c), distance(a + 1, b - 1, c - 1)))
	else:
		print(min(distance(a + 1, b, c - 1), distance(a + 1, b - 1, c - 1), distance(a + 1, b + 1, c - 1)))


for s in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = min(a, b, c)
	z = max(a, b, c)
	y = a + b + c - x - z
	if x < y and y < z:
		x += 1
		z -= 1
	elif x == y and y < z:
		if z == y + 1:
			z -= 1
		else:
			x = y = y + 1
			z -= 1
	elif x < y and y == z:
		if x + 1 == y:
			x += 1
		else:
			x += 1
			y = z = y - 1
	print(abs(x - y) + abs(y - z) + abs(x - z))


from sys import stdin

def input():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
for _ in range(input()):
	(a, b, c) = minput()
	m = 9999999999999
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				a_ = a + i
				b_ = b + j
				c_ = c + k
				d = abs(a_ - b_) + abs(a_ - c_) + abs(b_ - c_)
				if m > d:
					m = d
	print(m)


q = int(input())
for i in range(q):
	x = [int(j) for j in input().split()]
	x.sort()
	if x[0] == x[1] == x[2]:
		print(0)
	elif x[0] == x[1]:
		if x[2] - x[1] <= 2:
			print(0)
		else:
			print(2 * (x[2] - 1 - x[1] - 1))
	elif x[1] == x[2]:
		if x[2] - x[0] <= 2:
			print(0)
		else:
			print(2 * (x[2] - 1 - x[0] - 1))
	else:
		x[2] -= 1
		x[0] += 1
		print(x[2] - x[1] + x[2] - x[0] + x[1] - x[0])


def walk(a, b, c):
	if a == b:
		a = a
	else:
		a = a + 1
	if c == b:
		c = c
	else:
		c = c - 1
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	L = [a, b, c]
	L.sort()
	if L[0] == L[1] and L[1] == L[2] and (L[2] == L[0]):
		print(0)
	if L[0] != L[1] and L[0] != L[2] and (L[1] != L[2]):
		r = walk(L[0], L[1], L[2])
		print(r)
	if L[0] == L[1] and L[0] != L[2] and (L[2] != L[1]):
		if abs(L[2] - L[1]) > 1:
			L[0] = L[0] + 1
			L[1] = L[1] + 1
			L[2] = L[2] - 1
			r = abs(L[0] - L[1]) + abs(L[2] - L[1]) + abs(L[0] - L[2])
			print(r)
		elif abs(L[2] - L[1]) == 1:
			print(0)
	if L[0] != L[1] and L[1] == L[2] and (L[0] != L[2]):
		if abs(L[0] - L[1]) > 1:
			L[0] = L[0] + 1
			L[1] = L[1] - 1
			L[2] = L[2] - 1
			r = abs(L[0] - L[1]) + abs(L[2] - L[1]) + abs(L[0] - L[2])
			print(r)
		elif abs(L[0] - L[1]) == 1:
			print(0)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(a, b, c) = sorted(list(map(int, input().split())))
	if c - a <= 2:
		print(0)
	else:
		print((c - a - 2) * 2)


for i in range(int(input())):
	friends = list(map(int, input().split()))
	friends.sort()
	a = friends[2] - friends[0]
	if a == 0 or a == 1 or a == 2:
		print(0)
	else:
		print((a - 2) * 2)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = -1
	x = 0
	y = 0
	z = 0
	for i in range(3):
		if i == 0:
			x = a - 1
		elif i == 1:
			x = a + 1
		else:
			x = a
		for j in range(3):
			if j == 0:
				y = b - 1
			elif j == 1:
				y = b + 1
			else:
				y = b
			for k in range(3):
				if k == 0:
					z = c - 1
				elif k == 1:
					z = c + 1
				else:
					z = c
				if ans == -1:
					ans = abs(x - y) + abs(x - z) + abs(y - z)
				else:
					ans = min(ans, abs(x - y) + abs(x - z) + abs(y - z))
	print(ans)


a = int(input())
for i in range(a):
	b = list(map(int, input().split()))
	b.sort()
	c = (b[0] + b[1] + b[2]) / 3
	if abs(b[0] - c) > abs(b[2] - c) and abs(b[0] - c) != abs(b[2] - c):
		if b[0] != b[1]:
			b[0] += 1
		if b[1] != b[0]:
			b[1] -= 1
		if b[2] != b[1]:
			b[2] -= 1
	else:
		b.reverse()
		if b[0] != b[1]:
			b[0] -= 1
		if b[1] != b[0]:
			b[1] += 1
		if b[2] != b[1]:
			b[2] += 1
	print(abs(b[0] - b[1]) + abs(b[0] - b[2]) + abs(b[1] - b[2]))


t = int(input())
res = []
for i in range(t):
	l = [int(a) for a in input().split(' ')]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	mi = 10000000000000
	for z in range(3):
		for y in range(3):
			for x in range(3):
				if z == 0:
					t1 = a - 1
				if z == 1:
					t1 = a
				if z == 2:
					t1 = a + 1
				if y == 0:
					t2 = b - 1
				if y == 1:
					t2 = b
				if y == 2:
					t2 = b + 1
				if x == 0:
					t3 = c - 1
				if x == 1:
					t3 = c
				if x == 2:
					t3 = c + 1
				temp = abs(t1 - t2) + abs(t1 - t3) + abs(t2 - t3)
				if temp < mi:
					mi = temp
	res.append(mi)
for re in res:
	print(re)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	a.sort()
	print(max(a[2] - a[0] - 2, 0) * 2)


t = int(input())
for i in range(t):
	l = [int(x) for x in input().split()]
	ll = len(set(l))
	if ll == 1:
		print(0)
	elif ll == 2:
		l = list(set(l))
		l.sort()
		x = l[0]
		y = l[1]
		if y - x <= 2:
			print(0)
		else:
			print(2 * (y - x - 2))
	elif ll == 3:
		l.sort()
		a = 0
		x = l[0]
		y = l[1]
		z = l[2]
		a += z - y - 1
		a += y - x - 1
		a += z - x - 2
		print(a)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	right = max(a, b, c)
	left = min(a, b, c)
	if right == left:
		print('0')
	elif right == left + 1:
		print('0')
	else:
		print(2 * abs(right - left - 2))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	x = [a - 1, a, a + 1]
	y = [b - 1, b, b + 1]
	z = [c - 1, c, c + 1]
	sum = []
	for j in x:
		for k in y:
			for t in z:
				sum.append(abs(j - k) + abs(j - t) + abs(k - t))
	print(min(sum))


for _ in range(int(input())):
	list1 = [*map(int, input().split())]
	moy = (max(list1) + min(list1)) // 2
	for i in list1:
		if i > moy:
			i -= 1
		elif i < moy:
			i += 1
	a = list1[0]
	b = list1[1]
	c = list1[2]
	dist = abs(a - c) + abs(a - b) + abs(b - c) - 4
	print('0' if dist < 0 else dist)


n = int(input())
for i in range(n):
	v = []
	a = sorted(list(map(int, input().split())))
	for i in range(a[0] - 1, a[0] + 2):
		for j in range(a[1] - 1, a[1] + 2):
			for k in range(a[2] - 1, a[2] + 2):
				z = abs(k - j) + abs(k - i) + abs(i - j)
				v.append(z)
	print(min(v))


q = int(input())
while q > 0:
	lst = [int(x) for x in input().split()]
	lst.sort()
	lst[0] += 1
	lst[1] -= 1
	lst[2] -= 1
	ans = lst[1] - lst[0] + (lst[2] - lst[1]) + (lst[2] - lst[0])
	if ans < 0:
		print(0)
	else:
		print(ans)
	q -= 1


def g(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def h(a, b, c):
	return min(g(a + 1, b, c), g(a, b, c), g(a - 1, b, c))

def f(a, b, c):
	return min(h(a, b - 1, c - 1), h(a, b - 1, c), h(a, b - 1, c + 1), h(a, b, c - 1), h(a, b, c), h(a, b, c + 1), h(a, b + 1, c - 1), h(a, b + 1, c), h(a, b + 1, c + 1))
q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	print(f(a, b, c))


l = [-1, 0, 1]

def dist(L):
	return abs(L[0] - L[1]) + abs(L[0] - L[2]) + abs(L[1] - L[2])
sol = list()
q = int(input())
for i in range(0, q):
	f = input().split(' ')
	d = 4 * 10 ** 9 + 1
	F = [int(f[i]) for i in range(0, len(f))]
	for j in l:
		for k in l:
			for v in l:
				d = min(d, dist([F[0] + j, F[1] + k, F[2] + v]))
	sol.append(d)
for i in range(0, q - 1):
	print(sol[i])
print(sol[q - 1], end='')


try:
	for _ in range(int(input())):
		pos = sorted([int(i) for i in input().split()])
		ans = pos[2] - pos[0]
		ans -= 2
		if ans < 0:
			print(0)
		else:
			print(2 * ans)
except:
	pass


def totdis(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	minval = 3000000000.0
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				minval = min(minval, totdis(a + i, b + j, c + k))
	print(minval)


def lol_kek():
	t = int(input())
	for i in range(t):
		k = list(map(int, input().split()))
		k.sort()
		s = 0
		if k[0] == k[1] and k[1] == k[2]:
			print(0)
		else:
			if k[1] != k[0]:
				k[0] += 1
			elif k[1] == k[0] and k[2] != k[0]:
				k[1] += 1
				k[0] += 1
			if k[1] != k[2]:
				k[2] -= 1
			elif k[1] == k[2] and k[2] != k[0]:
				k[1] -= 1
				k[2] -= 1
			print(k[2] - k[1] + k[2] - k[0] + k[1] - k[0])
lol_kek()


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	(a, b, c) = (min(a, b, c), a + b + c - min(a, b, c) - max(a, b, c), max(a, b, c))
	if c - a <= 1:
		print('0')
	else:
		print(2 * c - 2 * a - 4)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
for _ in range(ii()):
	p = li()
	p.sort()
	(a, b, c) = p
	if a < c:
		a += 1
	if c > a:
		c -= 1
	print(2 * (c - a))


for i in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	if l[1] == l[0] and l[1] == l[2]:
		print(0)
	elif l[1] == l[0]:
		if l[2] - l[1] == 1:
			print(0)
			continue
		print(2 * (l[2] - 2 - l[0]))
	elif l[1] == l[2]:
		if l[2] - l[0] == 1:
			print(0)
			continue
		print(2 * (l[2] - l[0] - 2))
	else:
		print(l[1] - l[0] - 1 - 1 + l[2] - l[1] + l[2] - 1 - l[0] - 1)


n = int(input())
i = 0
m = [0] * 3
k = [0] * n
for i in range(n):
	m = list(map(int, input().split()))
	m = sorted(m)
	if m[2] - m[0] > 1:
		k[i] = abs(m[0] - m[1]) + abs(m[1] - m[2]) + abs(m[2] - m[0]) - 4
	else:
		k[i] = 0
i = 0
for i in range(n):
	print(k[i])


print('\n'.join([str(2 * max(0, sum(map(lambda x: max(x[1]) if x[0] == 0 else -min(x[1]), enumerate(2 * [list(map(int, input().split()))]))) - 2)) for testId in range(int(input()))]))


for u in range(int(input())):
	(x, y, z) = map(int, input().split())
	print(max(abs(x - y) + abs(y - z) + abs(z - x) - 4, 0))


def absu(p, q, r):
	sum_x = abs(abs(p - q) + abs(p - r) + abs(q - r))
	return sum_x
k = int(input())
for jj in range(0, k):
	(a, b, c) = map(int, input().split())
	d = []
	for m in range(-2, 1):
		for n in range(-2, 1):
			for o in range(-2, 1):
				d.append(absu(a + m, b + n, c + o))
	d.sort()
	print(d[0])


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = 1e+18
	for x in (-1, 0, 1):
		for y in (-1, 0, 1):
			for z in (-1, 0, 1):
				tmp1 = a + x
				tmp2 = b + y
				tmp3 = c + z
				ans = min(ans, abs(tmp1 - tmp2) + abs(tmp1 - tmp3) + abs(tmp3 - tmp2))
	print(ans)


t = int(input())
for i in range(t):
	s = list(map(int, input().split()))
	a = s[0]
	b = s[1]
	c = s[2]
	p = abs(a - b) + abs(a - c) + abs(b - c)
	if a == b and b == c:
		p = 0
	elif a == b or b == c or a == c:
		if p == 2:
			p -= 2
		else:
			p -= 4
	else:
		p -= 4
	print(p)


def absu(p, q, r):
	sum_x = abs(abs(p - q) + abs(p - r) + abs(q - r))
	return sum_x
k = int(input())
for jj in range(0, k):
	(a, b, c) = map(int, input().split())
	d = []
	a1 = a - 1
	a2 = a + 1
	b1 = b - 1
	b2 = b + 1
	c1 = c - 1
	c2 = c + 1
	d.append(absu(a, b1, c2))
	d.append(absu(a, b1, c1))
	d.append(absu(a, b1, c))
	d.append(absu(a1, b1, c2))
	d.append(absu(a1, b1, c1))
	d.append(absu(a1, b1, c))
	d.append(absu(a2, b1, c2))
	d.append(absu(a2, b1, c1))
	d.append(absu(a2, b1, c))
	d.append(absu(a, b, c2))
	d.append(absu(a, b, c1))
	d.append(absu(a, b, c))
	d.append(absu(a1, b, c2))
	d.append(absu(a1, b, c1))
	d.append(absu(a1, b, c))
	d.append(absu(a2, b, c2))
	d.append(absu(a2, b, c1))
	d.append(absu(a2, b, c))
	d.append(absu(a, b2, c2))
	d.append(absu(a, b2, c1))
	d.append(absu(a, b2, c))
	d.append(absu(a1, b2, c2))
	d.append(absu(a1, b2, c1))
	d.append(absu(a1, b2, c))
	d.append(absu(a2, b2, c2))
	d.append(absu(a2, b2, c1))
	d.append(absu(a2, b2, c))
	d.sort()
	print(d[0])


gi = lambda : list(map(int, input().split()))
for _ in range(gi()[0]):
	(a, b, c) = sorted(gi())
	print(2 * max(0, c - a - 2))


for i in range(int(input())):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	x = max(abs(a - b), abs(b - c), abs(c - a))
	print(2 * max(x, 2) - 4)


import sys
N = sys.stdin.readline()
for _ in range(int(N)):
	(a, b, c) = sys.stdin.readline().split()
	(x, y, z) = (int(a), int(b), int(c))
	l = []
	l.append(x)
	l.append(y)
	l.append(z)
	l.sort()
	(i, j, k) = (l[0], l[1], l[2])
	if i == j and j == k:
		print(0)
	else:
		if i == j and j < k:
			k -= 1
			if j < k:
				i += 1
				j += 1
			somme = abs(i - j) + abs(i - k) + abs(j - k)
			print(somme)
		if j == k and i < j:
			i += 1
			if i < j:
				j -= 1
				k -= 1
			somme = abs(i - j) + abs(i - k) + abs(j - k)
			print(somme)
		if i < j and j < k:
			i += 1
			k -= 1
			somme = abs(i - j) + abs(i - k) + abs(j - k)
			print(somme)


for _ in range(int(input())):
	l = sorted(list(map(int, input().split())))
	(a, b, c) = (l[0], l[1], l[2])
	if a == b and b == c:
		print(0)
	elif a == b:
		if c == a + 1:
			print(0)
		else:
			print((c - 1 - (a + 1)) * 2)
	elif b == c:
		if a == b - 1:
			print(0)
		else:
			print((b - 1 - (a + 1)) * 2)
	else:
		a = a + 1
		c = c - 1
		print(c - a + c - b + b - a)


from math import *
import os, sys
from io import BytesIO

def f(a, x):
	if a == x:
		return x
	if a > x:
		return a - 1
	else:
		return a + 1
for i in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	x = int((a + b + c) / 3 + 0.5)
	(a1, b1, c1) = (a, b, c)
	print(abs(f(a, x) - f(b, x)) + abs(f(c, x) - f(b, x)) + abs(f(a, x) - f(c, x)))


T = int(input())
for _ in range(T):
	ans = float('inf')
	(a, b, c) = map(int, input().split())
	C = [-1, 0, 1]
	for a_c in C:
		for b_c in C:
			for c_c in C:
				t_a = a + a_c
				t_b = b + b_c
				t_c = c + c_c
				tmp = abs(t_a - t_b) + abs(t_a - t_c) + abs(t_b - t_c)
				ans = min(tmp, ans)
	print(ans)


q = int(input())
for testcase in range(q):
	A = [int(x) for x in input().split()]
	A.sort()
	(a, b, c) = (A[0], A[1], A[2])
	ans = max(0, 2 * c - 2 * a - 4)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	l = list(map(int, input().split()))
	l.sort()
	max_ = max(l[2] - l[1], l[1] - l[0], l[2] - l[0])
	if max_ > 1:
		print(2 * abs(l[2] - 1 - l[0] - 1))
	else:
		print(0)


n = int(input())
for _ in range(n):
	a = [int(s) for s in input().split()]
	a.sort()
	if a[0] == a[1] and a[0] != a[2]:
		a[0] += 1
		a[1] += 1
		if a[2] != a[1]:
			a[2] -= 1
	elif a[1] == a[2] and a[0] != a[2]:
		a[2] -= 1
		a[1] -= 1
		if a[0] != a[1]:
			a[0] += 1
	elif a[0] != a[1] and a[1] != a[2]:
		a[0] += 1
		a[2] -= 1
	d = a[2] - a[1] + (a[1] - a[0]) + (a[2] - a[0])
	print(d)


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	f = lambda a, b, c: abs(a - b) + abs(a - c) + abs(b - c)
	ans = f(a, b, c)
	for d1 in range(-1, 2):
		for d2 in range(-1, 2):
			for d3 in range(-1, 2):
				ans = min(ans, f(a + d1, b + d2, c + d3))
	print(ans)


t = int(input())
for i in range(0, t):
	p = [int(x) for x in input().split()]
	p = sorted(p)
	if p[2] - p[0] <= 2:
		print(0)
	else:
		print(2 * (p[2] - p[0] - 2))


n = int(input())
for i in range(n):
	a = sorted(list(map(int, input().split())))
	if len(set(a)) == 1:
		print(0)
	elif len(set(a)) == 2:
		if max(a) - min(a) >= 2:
			print((max(a) - min(a)) * 2 - 4)
		else:
			print((max(a) - min(a)) * 2 - 2)
	else:
		print(a[1] - a[0] + a[2] - a[1] + a[2] - a[0] - 4)


for _ in range(int(input())):
	l1 = input().split()
	l1 = [int(x) for x in l1]
	l1.sort()
	if l1[1] > l1[0] and l1[1] == l1[2]:
		l1[1] = l1[1] - 1
	if l1[1] < l1[2] and l1[1] == l1[0]:
		l1[1] = l1[1] + 1
	if l1[0] < l1[1]:
		l1[0] = l1[0] + 1
	if l1[2] > l1[1]:
		l1[2] = l1[2] - 1
	print(2 * l1[2] - 2 * l1[0])


def f(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = f(a, b, c)
	a = [a - 1, a, a + 1]
	b = [b - 1, b, b + 1]
	c = [c - 1, c, c + 1]
	for i in range(3):
		for j in range(3):
			for k in range(3):
				m = min(f(a[i], b[j], c[k]), m)
	print(m)


t = int(input())
for _ in range(t):
	pos = list(map(int, input().split()))
	pos.sort()
	(p1, p2, p3) = (pos[0], pos[1], pos[2])
	if p1 != p2 and p1 != p3 and (p2 != p3):
		p1 += 1
		p3 -= 1
		(d1, d2, d3) = (p2 - p1, p3 - p2, p3 - p1)
		print(d1 + d2 + d3)
	elif p1 == p2 == p3:
		print(0)
	elif p1 == p2:
		if p3 - p2 > 1:
			p2 += 1
			p1 += 1
			p3 -= 1
			(d1, d2, d3) = (p2 - p1, p3 - p2, p3 - p1)
			print(d1 + d2 + d3)
		else:
			print(0)
	elif p2 - p1 > 1:
		p2 -= 1
		p3 -= 1
		p1 += 1
		(d1, d2, d3) = (p2 - p1, p3 - p2, p3 - p1)
		print(d1 + d2 + d3)
	else:
		print(0)


n = int(input())
for i in range(n):
	lista = input().split(' ')
	lista.sort()
	n1 = int(lista[0])
	n2 = int(lista[1])
	n3 = int(lista[2])
	pm = (n1 + n3) // 2
	if n1 < pm:
		n1 += 1
	elif n1 > pm:
		n1 -= 1
	if n2 < pm:
		n2 += 1
	elif n2 > pm:
		n2 -= 1
	if n3 > pm:
		n3 -= 1
	elif n3 < pm:
		n3 += 1
	print(abs(n1 - n2) + abs(n1 - n3) + abs(n2 - n3))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	x1 = abs(a - b) + abs(a - c) + abs(b - c)
	x2 = abs(a - b) + abs(a - c + 2) + abs(b - c + 2)
	x3 = abs(a - b) + abs(a - c - 2) + abs(b - c - 2)
	x4 = abs(a - b + 2) + abs(a - c) + abs(b - c - 2)
	x5 = abs(a - b - 2) + abs(a - c) + abs(b - c + 2)
	x6 = abs(a - b - 2) + abs(a - c - 2) + abs(b - c)
	x7 = abs(a - b + 2) + abs(a - c + 2) + abs(b - c)
	x8 = abs(a - b + 1) + abs(a - c + 1) + abs(b - c)
	x9 = abs(a - b - 1) + abs(a - c - 1) + abs(b - c)
	x10 = abs(a - b) + abs(a - c + 1) + abs(b - c + 1)
	x11 = abs(a - b) + abs(a - c - 1) + abs(b - c - 1)
	x12 = abs(a - b + 1) + abs(a - c) + abs(b - c - 1)
	x13 = abs(a - b - 1) + abs(a - c) + abs(b - c + 1)
	x14 = abs(a - b + 1) + abs(a - c + 2) + abs(b - c + 1)
	x15 = abs(a - b - 1) + abs(a - c - 2) + abs(b - c - 1)
	x16 = abs(a - b + 2) + abs(a - c + 1) + abs(b - c - 1)
	x17 = abs(a - b - 2) + abs(a - c - 1) + abs(b - c + 1)
	x18 = abs(a - b - 1) + abs(a - c + 1) + abs(b - c + 2)
	x19 = abs(a - b + 1) + abs(a - c - 1) + abs(b - c - 2)
	print(min(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19))


t = int(input())
for i in range(t):
	a = list(map(int, input().strip().split(' ')))
	a.sort()
	a1 = a[0]
	b1 = a[1]
	c1 = a[2]
	x = 2 * (c1 - a1)
	ans = max(0, x - 4)
	print(ans)


def dist(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	minSoFar = dist(a, b, c)
	for i in (a - 1, a, a + 1):
		for j in (b - 1, b, b + 1):
			for k in (c - 1, c, c + 1):
				minSoFar = min(minSoFar, dist(i, j, k))
	print(minSoFar)


for test in range(int(input())):
	test = map(int, input().split())
	test = sorted(test)
	if test[2] - test[0] < 2:
		print(0)
	else:
		print((test[2] - test[0]) * 2 - 4)


import sys
Input = sys.stdin.readline
n = int(Input())
for i in range(n):
	x = list(sorted(map(int, Input().split())))
	tmp = x[2] - x[1] + (x[1] - x[0]) + (x[2] - x[0])
	if len(set(x)) == 1:
		print(0)
	elif len(set(x)) == 2:
		if tmp >= 4:
			print(tmp - 4)
		else:
			print(tmp - 2)
	else:
		print(tmp - 4)


for i in range(int(input())):
	B = list(map(int, input().split()))
	A = sorted(B)
	(a, b, c) = (A[0], A[1], A[2])
	print(max(0, 2 * (c - a - 2)))


for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	distance = max(c - 1 - a - 1, 0)
	print(distance * 2)


q = int(input().strip())
for i in range(q):
	(a, b, c) = map(int, input().strip().split())
	s = sorted([a, b, c])
	x = 2 * (abs(s[2]) - abs(s[0]) - 2)
	if x > 0:
		print(x)
	else:
		print(0)


from itertools import permutations
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	combos = list(permutations([1] * 3 + [0] * 3 + [-1] * 3, 3))
	curr_min = float('inf')
	for combo in combos:
		curr_sum = abs(a + combo[0] - (b + combo[1])) + abs(a + combo[0] - (c + combo[2])) + abs(b + combo[1] - (c + combo[2]))
		curr_min = min(curr_min, curr_sum)
	print(curr_min)


for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	if abs(a - c) <= 2:
		print(0)
	else:
		print(2 * (abs(a - c) - 2))


def three(a, b, c):
	arr = []
	arr.append(a)
	arr.append(b)
	arr.append(c)
	if a == b and a == c:
		return 0
	for i in range(0, 3):
		for j in range(i, 3):
			if arr[i] > arr[j]:
				temp = arr[i]
				arr[i] = arr[j]
				arr[j] = temp
	if arr[0] < arr[1] and arr[1] < arr[2]:
		arr[0] = arr[0] + 1
		arr[2] = arr[2] - 1
		return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
	if arr[0] == arr[1]:
		if arr[0] + 1 < arr[2]:
			arr[0] = arr[0] + 1
			arr[1] = arr[1] + 1
			arr[2] = arr[2] - 1
			return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
		else:
			arr[0] = arr[0] + 1
			arr[1] = arr[1] + 1
			return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
	if arr[1] == arr[2]:
		if arr[0] + 1 == arr[2]:
			arr[0] = arr[0] + 1
			return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
		else:
			arr[0] = arr[0] + 1
			arr[1] = arr[1] - 1
			arr[2] = arr[2] - 1
			return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
test = eval(input())
lines = []
for i in range(test):
	line = input()
	lines.append(line)
for i in lines:
	input = i.split(' ')
	print(three(int(input[0]), int(input[1]), int(input[2])))


q = int(input())
pairs = []
answers = []
for i in range(q):
	(a, b, c) = input().split()
	for k in range(-1, 2):
		a1 = int(a) + k
		for l in range(-1, 2):
			b1 = int(b) + l
			for m in range(-1, 2):
				c1 = int(c) + m
				pair = abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1)
				pairs.append(pair)
	answers.append(min(pairs))
	pairs = []
for f in answers:
	print(f)


for i in range(int(input())):
	lst = [int(i) for i in input().split()]
	if len(set(lst)) == 1:
		print(0)
	elif len(set(lst)) == 2:
		mn = min(lst)
		mx = max(lst)
		if lst.count(mn) == 2:
			for (ind, j) in enumerate(lst):
				if mn == j:
					lst[ind] += 1
				else:
					indx = ind
			mnqu = abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2])
			lst[indx] -= 1
			mnqu1 = abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2])
			if mnqu < mnqu1:
				print(mnqu)
			else:
				print(mnqu1)
		else:
			for (ind, j) in enumerate(lst):
				if mx == j:
					lst[ind] -= 1
				else:
					indx = ind
			mnqu = abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2])
			lst[indx] += 1
			mnqu1 = abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2])
			if mnqu < mnqu1:
				print(mnqu)
			else:
				print(mnqu1)
	else:
		lst[lst.index(max(lst))] -= 1
		lst[lst.index(min(lst))] += 1
		print(abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2]))


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	a = sorted(a)
	if min(a[1] - (a[0] + 1) + a[2] - 1 - a[1] + a[2] - 1 - (a[0] + 1), a[1] - a[0] + a[2] - 1 - a[1] + a[2] - 1 - a[0], a[1] - (a[0] + 1) + a[2] - a[1] + a[2] - (a[0] + 1), a[1] - a[0] + a[2] - a[1] + a[2] - a[0]) < 0:
		print(0)
	else:
		print(min(a[1] - (a[0] + 1) + a[2] - 1 - a[1] + a[2] - 1 - (a[0] + 1), a[1] - a[0] + a[2] - 1 - a[1] + a[2] - 1 - a[0], a[1] - (a[0] + 1) + a[2] - a[1] + a[2] - (a[0] + 1), a[1] - a[0] + a[2] - a[1] + a[2] - a[0]))


n = int(input())
for j in range(n):
	y = input().split(' ')
	a = []
	for char in y:
		a.append(int(char))
	a.sort()
	u = (a[2] - a[0] - 2) * 2
	if u < 0:
		u = 0
	print(u)


q = int(input())

def max_distance(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
res = []
for x in range(q):
	(a, b, c) = [int(y) for y in input().split()]
	suma = a + b + c
	minx = min(a, b, c)
	maxx = max(a, b, c)
	a = minx
	b = suma - maxx - minx
	c = maxx
	if a < b and b < c:
		a += 1
		c -= 1
	elif a == b and b < c:
		if c - b == 1:
			a += 1
			b += 1
		else:
			a += 1
			b += 1
			c -= 1
	elif a < b and b == c:
		if b - a == 1:
			b -= 1
			c -= 1
		else:
			a += 1
			b -= 1
			c -= 1
	res.append(max_distance(a, b, c))
for x in res:
	print(x)


def yes_no(r, g, b):
	sumi = abs(r - g) + abs(r - b) + abs(g - b) - 4
	if sumi < 0:
		return 0
	return sumi
for _ in range(int(input())):
	(r, g, b) = map(int, input().split())
	print(yes_no(r, g, b))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	lt = [a, b, c]
	lt = sorted(lt)
	if lt[0] == lt[2]:
		print(0)
	elif lt[0] == lt[1] or lt[1] == lt[2]:
		if abs(lt[0] - lt[2]) <= 2:
			print(0)
		else:
			print(abs(2 * (lt[0] + 1 - (lt[2] - 1))))
	else:
		print(abs(2 * lt[0] - 2 * lt[2] + 4))


from itertools import product
n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
B = [0, 1, -1]
for a in A:
	ans = float('inf')
	(a, b, c) = a
	for x in product(B, B, B):
		(x1, y1, z1) = x
		(a1, b1, c1) = (a + x1, b + y1, c + z1)
		ans = min(ans, abs(b1 - a1) + abs(c1 - a1) + abs(c1 - b1))
	print(ans)


N = eval(input())
A = []
for i in range(N):
	(a, b, c) = map(eval, input().split())
	if a == b and a == c:
		A.append(0)
	elif a == b or a == c or b == c:
		s = abs(a - b) + abs(b - c) + abs(a - c) - 4
		if s < 0:
			s = 0
		A.append(s)
	else:
		s = abs(a - b) + abs(b - c) + abs(a - c) - 4
		A.append(s)
for i in A:
	print(i)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	lis = [a, b, c]
	lis.sort()
	dist = 0
	flag = 0
	if lis[0] - lis[1] == 0 and lis[1] - lis[2] == 0:
		print(dist)
		continue
	if abs(lis[0] - lis[1] != 0):
		dist = abs(lis[0] - lis[1]) - 1
		lis[0] += 1
	else:
		lis[0] += 1
		lis[1] += 1
		flag = 1
	if abs(lis[1] - lis[2] != 0):
		dist = dist + abs(lis[1] - lis[2]) - 1
		lis[2] -= 1
	elif flag == 0:
		dist -= 1
		lis[2] -= 1
	dist += abs(lis[0] - lis[2])
	print(dist)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	if a == b and b == c:
		print(0)
	else:
		l = sorted(l)
		if l[0] == l[1]:
			l[1] += 1
		if l[1] == l[2]:
			l[1] = l[1] - 1
		if l[0] != l[1]:
			l[0] = l[0] + 1
		if l[1] != l[2]:
			l[2] = l[2] - 1
		ans = abs(l[1] - l[0]) + abs(l[2] - l[1]) + abs(l[2] - l[0])
		print(ans)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l.sort()
	if len(set(l)) == 1:
		print(0)
		continue
	if l[0] == l[1]:
		l[0] += 1
		l[1] += 1
		l[2] = max(l[2] - 1, l[1])
	elif l[1] == l[2]:
		l[0] += 1
		l[1] = max(l[1] - 1, l[0])
		l[2] = l[1]
	else:
		l[0] += 1
		l[2] -= 1
	d = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
	print(d)


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1] and l[1] == l[2]:
		print('0')
		continue
	elif l[0] == l[1]:
		if l[2] <= l[1] + 1:
			l[2] -= 1
		else:
			l[0] += 1
			l[1] += 1
			l[2] -= 1
		sum = abs(l[2] - l[0]) + abs(l[2] - l[1])
		print(sum)
		continue
	elif l[1] == l[2]:
		if l[1] <= l[0] + 1:
			l[0] += 1
		else:
			l[0] += 1
			l[1] -= 1
			l[2] -= 1
		sum = abs(l[1] - l[0]) + abs(l[2] - l[0])
		print(sum)
		continue
	else:
		l[0] += 1
		l[2] -= 1
		sum = abs(l[1] - l[0]) + abs(l[2] - l[1]) + abs(l[2] - l[0])
		print(sum)
		continue


q = int(input())
while q:
	a = sorted([int(x) for x in input().split()])
	if sum(a) // 3 == a[0]:
		print(0)
		q -= 1
		continue
	if a[0] == a[1]:
		a[0] = a[1] = a[0] + 1
	else:
		a[0] += 1
	if a[2] == a[1]:
		a[2] = a[1] = a[1] - 1
	else:
		a[2] -= 1
	print(a[2] - a[1] + a[1] - a[0] + a[2] - a[0])
	q -= 1


q = int(input())
for _ in range(q):
	lst = list(map(int, input().split()))
	lst.sort()
	print(max(0, 2 * (lst[2] - lst[0] - 2)))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = 10 ** 12
	la = [a - 1, a, a + 1]
	lb = [b - 1, b, b + 1]
	lc = [c - 1, c, c + 1]
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ans = min(ans, abs(la[i] - lb[j]) + abs(la[i] - lc[k]) + abs(lb[j] - lc[k]))
	print(ans)


def solve(a, b, c):
	if a == b == c:
		return 0
	if a == b:
		return 2 * (abs(b - c) - 2) if abs(b - c) - 2 > 0 else 0
	if b == c:
		return 2 * (abs(a - b) - 2) if abs(a - b) - 2 > 0 else 0
	if a == c:
		return 2 * (abs(c - b) - 2) if abs(c - b) - 2 > 0 else 0
	(min_, mid_, max_) = sorted([a, b, c])
	return abs(min_ - mid_) - 1 + abs(min_ - max_) - 1 + abs(max_ - mid_) - 2

def main():
	q = int(input())
	for _ in range(q):
		(a, b, c) = (int(x) for x in input().split(' '))
		print(solve(a, b, c))
main()


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] != l[1]:
		l[0] += 1
	elif l[1] != l[2]:
		l[0] += 1
		l[1] += 1
	if l[2] != l[1]:
		l[2] -= 1
	elif l[1] != l[0]:
		l[2] -= 1
		l[1] -= 1
	print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	d = max(a, b, c)
	e = min(a, b, c)
	l.remove(d)
	l.remove(e)
	f = l[0]
	z = d - 1 - (e + 1) + (d - 1) - (f + 1) + (f + 1) - (e + 1)
	if z < 0:
		print('0')
	else:
		print(z)
	l.clear()


t = int(input())
for i in range(t):
	positions = list(map(int, input().strip().split()))
	positions.sort()
	if positions[0] + 2 < positions[2]:
		print(2 * (positions[2] - positions[0]) - 4)
	else:
		print(0)


t = int(input())
while t:
	t1 = list(map(int, input().split()))
	t1.sort()
	a = t1[0]
	b = t1[1]
	c = t1[2]
	if a == b and b == c and (a == c):
		print(0)
		t -= 1
		continue
	ans = 10 ** 18
	arr = [-1, 0, 1]
	for k1 in arr:
		for k2 in arr:
			for k3 in arr:
				a1 = a + k1
				b1 = b + k2
				c1 = c + k3
				ans = min(ans, abs(a1 - c1) + abs(b1 - c1) + abs(a1 - b1))
	print(ans)
	t -= 1


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if max(a) - min(a) <= 1:
		print(0)
	else:
		a[0] += 1
		a[2] -= 1
		if a[0] == a[1]:
			a[1] += 1
		elif a[1] == a[2]:
			a[1] -= 1
		print(abs(a[0] - a[2] + a[0] - a[1] + a[1] - a[2]))


from fractions import gcd
from heapq import *
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

def main():
	n = int(input())
	for i in range(n):
		(a, b, c) = map(int, input().split())
		ans = float('inf')
		for i in range(a - 1, a + 2):
			for j in range(b - 1, b + 2):
				for k in range(c - 1, c + 2):
					ans = min(ans, abs(i - j) + abs(j - k) + abs(k - i))
		print(ans)
main()


a = int(input())
b = list()
r = 0
while r < a:
	c = [int(c) for c in input().split()]
	c.sort()
	if c[0] == c[1] and c[1] != c[2]:
		c[0] = c[0] + 1
		c[1] = c[1] + 1
		if c[1] != c[2]:
			c[2] = c[2] - 1
	elif c[1] == c[2] and c[0] != c[1]:
		c[1] = c[1] - 1
		c[2] = c[2] - 1
		if c[1] != c[0]:
			c[0] = c[0] + 1
	elif c[0] != c[1] and c[1] != c[2]:
		c[0] = c[0] + 1
		c[2] = c[2] - 1
	b.append(2 * (c[2] - c[0]))
	r = r + 1
r = 0
while r < a:
	print(b[r])
	r = r + 1


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	A = [a, b, c]
	S = 0
	S += abs(a - b) + abs(b - c) + abs(a - c)
	A = list(set(A))
	if len(A) == 3:
		print(S - 4)
	elif len(A) == 2:
		if abs(A[0] - A[1]) > 1:
			print(S - 4)
		else:
			print(0)
	elif len(A) == 1:
		print(0)


t = int(input())
for i in range(t):
	(x, y, z) = [int(i) for i in input().split()]
	if x == y == z:
		print(0)
	elif x == y or y == z or z == x:
		if x == y:
			if y + 1 == z:
				print(abs(z - y - 1) * 2)
			elif y - 1 == z:
				print(abs(z - y + 1) * 2)
			elif y < z:
				print(abs(z - 1 - (y + 1)) * 2)
			else:
				print(abs(z + 1 - (y - 1)) * 2)
		elif y == z:
			if y + 1 == x:
				print(abs(x - y - 1) * 2)
			elif y - 1 == x:
				print(abs(x - y + 1) * 2)
			elif y < x:
				print(abs(x - 1 - (y + 1)) * 2)
			else:
				print(abs(x + 1 - (y - 1)) * 2)
		elif x == z:
			if x + 1 == y:
				print(abs(y - x - 1) * 2)
			elif x - 1 == y:
				print(abs(y - x + 1) * 2)
			elif x < y:
				print(abs(y - 1 - (x + 1)) * 2)
			else:
				print(abs(y + 1 - (x - 1)) * 2)
	elif x != y != z:
		a = (x, y, z)
		b = list(a)
		b.sort()
		b[2] = b[2] - 1
		b[0] = b[0] + 1
		print(abs(b[0] - b[1]) + abs(b[0] - b[2]) + abs(b[1] - b[2]))


def get_min(a, b, c):
	res = abs(a - b) + abs(a - c) + abs(b - c)
	return res
T = int(input())
for t in range(T):
	(a, b, c) = list(map(int, input().split()))
	cur_min = abs(a - b) + abs(a - c) + abs(b - c)
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				m = get_min(i, j, k)
				cur_min = min(cur_min, m)
	print(cur_min)


def ab(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for _ in range(q):
	a = input()
	asp = a.split(' ')
	for i in range(len(asp)):
		asp[i] = int(asp[i])
	asp.sort()
	asps = []
	ar = [-1, 0, 1]
	for i in ar:
		for j in ar:
			for k in ar:
				asps.append(ab(asp[0] + i, asp[1] + j, asp[2] + k))
	asps.sort()
	print(asps[0])


def fun(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = fun(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				a1 = a + i
				b1 = b + j
				c1 = c + k
				ans = min(ans, fun(a1, b1, c1))
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		(a, b, c) = [int(i) for i in input().split()]
		ans = 0
		if a == b and b == c:
			print(ans)
			continue
		elif a == b and abs(b - c) == 1 or (b == c and abs(c - a) == 1) or (a == c and abs(c - b) == 1):
			print(ans)
			continue
		elif a == b:
			ans = 2 * (abs(b - c) - 2)
			print(ans)
			continue
		elif b == c:
			ans = 2 * (abs(b - a) - 2)
			print(ans)
			continue
		elif a == c:
			ans = 2 * (abs(b - c) - 2)
			print(ans)
			continue
		else:
			ans = abs(a - b) + abs(b - c) + abs(c - a) - 4
			print(ans)
main()


k = int(input())
for _ in range(k):
	(a, b, c) = map(int, input().split())
	m = 10 ** 18
	for i in [-1, 0, 1]:
		for j in [-1, 0, 1]:
			for k in [-1, 0, 1]:
				m = min(m, abs(a + i - (b + j)) + abs(a + i - (c + k)) + abs(b + j - (c + k)))
	print(m)


CASES = int(input())
for i in range(CASES):
	(a, b, c) = map(int, input().split())
	dist = abs(a - b) + abs(b - c) + abs(c - a)
	a = [a - 1, a, a + 1]
	b = [b - 1, b, b + 1]
	c = [c - 1, c, c + 1]
	for i in a:
		for j in b:
			for k in c:
				temp = abs(i - j) + abs(j - k) + abs(k - i)
				dist = min(temp, dist)
	print(dist)


T = int(input())
for _ in range(T):
	(a, b, c) = map(int, input().split())
	temp = abs(a - b) + abs(a - c) + abs(b - c) - 4
	if temp < 0:
		print(0)
	else:
		print(temp)


for i in range(int(input())):
	r = tuple(map(int, input().split()))
	r = set(r)
	mx = max(r)
	mn = min(r)
	if mn == mx:
		print(0)
	elif mx - mn - 2 < 0:
		print(2 * (mx - mn - 1))
	else:
		print(2 * (mx - mn - 2))


n = int(input())
lst = []
for _ in range(n):
	lst.append(list(map(int, input().split())))
for i in lst:
	i.sort()
	if i[1] + 1 == i[2] and i[0] != i[1]:
		i[0] += 1
		i[2] -= 1
		sum1 = abs(i[0] - i[1]) + abs(i[1] - i[2]) + abs(i[2] - i[0])
		print(sum1)
	elif i[0] + 1 == i[1] and i[2] != i[1]:
		i[2] -= 1
		i[0] += 1
		sum1 = abs(i[0] - i[1]) + abs(i[1] - i[2]) + abs(i[2] - i[0])
		print(sum1)
	elif len(set(i)) == len(i) and (not (i[0] + 1 == i[1] and i[2] - 1 == i[1])):
		i[2] -= 1
		i[0] += 1
		i[1] += 1
		sum1 = abs(i[0] - i[1]) + abs(i[1] - i[2]) + abs(i[2] - i[0])
		print(sum1)
	elif len(set(i)) == 1 or (i[0] + 1 == i[1] and i[2] - 1 == i[1]):
		print(0)
	elif i[1] == i[2]:
		i[2] -= 1
		i[1] -= 1
		if i[1] == i[0]:
			print(0)
		else:
			i[0] += 1
			sum1 = abs(i[0] - i[1]) + abs(i[1] - i[2]) + abs(i[2] - i[0])
			print(sum1)
	elif i[0] == i[1]:
		i[0] += 1
		i[1] += 1
		if i[1] == i[2]:
			print(0)
		else:
			i[2] -= 1
			sum1 = abs(i[0] - i[1]) + abs(i[1] - i[2]) + abs(i[2] - i[0])
			print(sum1)
	else:
		continue


n = int(input())
for x in range(n):
	(a, b, c) = sorted(list(map(int, input().split())))
	if c > b + 1 or c > a + 1:
		c -= 1
	if b > a + 1:
		b -= 1
	elif b < c:
		b += 1
	if a < b:
		a += 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


n = int(input())
for i in range(n):
	lst = list(map(int, input().split()))
	lst.sort()
	a = lst[0]
	b = lst[1]
	c = lst[2]
	if a == b and b == c:
		print(0)
	elif a == b:
		a += 1
		b += 1
		if a == c:
			print(0)
		else:
			c = c - 1
			print(abs(a - b) + abs(b - c) + abs(c - a))
	elif b == c:
		b = b - 1
		c = c - 1
		if b == a:
			print(0)
		else:
			a = a + 1
			print(abs(a - b) + abs(a - c) + abs(b - c))
	else:
		print(abs(a - b) + abs(b - c) + abs(a - c) - 4)


t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	l.append(c)
	l.sort()
	ans = 1000000000000000
	if l[0] == l[1] and l[1] == l[2]:
		print(0)
	elif l[0] == l[1] and l[1] != l[2]:
		l[0] += 1
		l[1] += 1
		if l[2] != l[0]:
			l[2] -= 1
		print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0]))
	elif l[0] != l[1] and l[1] == l[2]:
		l[1] -= 1
		l[2] -= 1
		if l[0] != l[1]:
			l[0] += 1
		print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0]))
	else:
		l[0] += 1
		l[2] -= 1
		print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0]))
	t -= 1


def calc(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
n = int(input())
for z in range(n):
	(a, b, c) = map(int, input().split())
	ans = calc(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				na = a + i
				nb = b + j
				nc = c + k
				ans = min(ans, calc(na, nb, nc))
	print(ans)


t = int(input())
for j in range(t):
	(a, b, c) = map(int, input().split(' '))
	list1 = [a, a - 1, a + 1]
	list2 = [b, b - 1, b + 1]
	list3 = [c, c - 1, c + 1]
	list4 = []
	for i in list1:
		for j in list2:
			for k in list3:
				list4.append(abs(i - j) + abs(j - k) + abs(i - k))
	print(min(list4))


M = int(input())
for j in range(M):
	m = list(map(int, input().split()))
	m.sort()
	if m[0] == m[2]:
		print(0)
	elif m[0] == m[1] and m[2] == m[1] + 1 or (m[1] == m[0] + 1 and m[1] == m[2]):
		print(2 * (m[2] - m[0] - 1))
	else:
		print(2 * (m[2] - m[0] - 2))


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	ans = abs(a - b) + abs(a - c) + abs(b - c)
	for q in range(-1, 2, 1):
		for w in range(-1, 2, 1):
			for e in range(-1, 2, 1):
				x = a + q
				y = b + w
				z = c + e
				ans = min(ans, abs(x - y) + abs(x - z) + abs(y - z))
	print(ans)


def ans(a, b, c):
	out = abs(a - b) + abs(b - c) + abs(c - a)
	for x in range(3):
		if x == 1:
			a += 1
		elif x == 2:
			a -= 1
		for y in range(3):
			if y == 1:
				b += 1
			elif y == 2:
				b -= 1
			for z in range(3):
				if z == 1:
					c += 1
				elif z == 2:
					c -= 1
				val = abs(a - b) + abs(b - c) + abs(c - a)
				out = min(val, out)
				if z == 1:
					c -= 1
				elif z == 2:
					c += 1
			if y == 1:
				b -= 1
			elif y == 2:
				b += 1
		if x == 1:
			a -= 1
		elif x == 2:
			a += 1
	return out
q = int(input())
for x in range(q):
	(a, b, c) = [int(i) for i in input().split()]
	print(ans(a, b, c))


q = int(input())
for i in range(q):
	l = [int(x) for x in input().split()]
	l.sort()
	if l[0] == l[1] and l[1] == l[2]:
		print('0')
	elif l[0] == l[1] and l[1] != l[2]:
		if l[2] - l[1] < 3:
			print('0')
		else:
			print(2 * (l[2] - l[1] - 2))
	elif l[0] != l[1] and l[1] == l[2]:
		if l[2] - l[0] < 3:
			print('0')
		else:
			print(2 * (l[2] - l[0] - 2))
	else:
		print(2 * (l[2] - l[0] - 2))


import itertools
q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	best = 10 ** 20
	for (da, db, dc) in itertools.product([-1, 0, 1], repeat=3):
		na = a + da
		nb = b + db
		nc = c + dc
		total = abs(na - nb) + abs(na - nc) + abs(nb - nc)
		best = min(best, total)
	print(best)


def min_total_pair_sum(a, b, c):
	arr = sorted([a, b, c])
	return 2 * max(0, arr[2] - arr[0] - 2)
k = int(input())
while k > 0:
	a = [int(i) for i in input().split()]
	print(min_total_pair_sum(a[0], a[1], a[2]))
	k -= 1


t = int(input())
count = 0
ans = []
while count < t:
	dist = 0
	cor = list(map(int, input().split()))
	cor = sorted(cor)
	(a, b, c) = cor
	if len(set(cor)) == 1:
		dist += 0
	elif len(set(cor)) == 2:
		test = list(set(cor))
		if abs(test[0] - test[1]) <= 2:
			dist += 0
		else:
			dist += (abs(test[0] - test[1]) - 2) * 2
	elif c - a <= 2:
		dist += 0
	else:
		dist += c - a - 2
		if c - 1 == b:
			dist += b - a - 1
		elif c - 1 > b:
			dist += c - b - 2
			dist += b - a
		else:
			pass
	ans.append(dist)
	count += 1
for y in ans:
	print(y)


def f(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	mi = f(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				mi = min(mi, f(a + i, b + j, c + k))
	print(mi)


def position(x, y, z):
	a = [x, y, z]
	a.sort()
	if a[-1] - a[-3] > 1:
		return 2 * (a[-1] - a[-3] - 2)
	else:
		return 0
t = int(input())
for i in range(0, t):
	(x, y, z) = map(int, input().split())
	print(position(x, y, z))


from math import *
T = int(input())
result = ''
for t in range(T):
	text = list(map(int, input().split(' ')))
	text.sort()
	a = text[0]
	b = text[1]
	c = text[2]
	if not a == b == c:
		if a == b:
			a += 1
			b += 1
		else:
			a += 1
	if not a == b == c:
		if c == b:
			c -= 1
			b -= 1
		else:
			c -= 1
	r = int(fabs(a - b) + fabs(b - c) + fabs(a - c))
	result += str(r) + '\n'
print(result)


from sys import stdin
infast = lambda : stdin.readline().strip()
Q = int(infast())
delta = [-1, 0, 1]

def in_range(x):
	return 1 <= x <= 1000000000
for _ in range(Q):
	result = 3000000000
	(A, B, C) = map(int, infast().split())
	for da in delta:
		for db in delta:
			for dc in delta:
				new_a = A + da
				new_b = B + db
				new_c = C + dc
				if not in_range(new_a) or not in_range(new_b) or (not in_range(new_c)):
					continue
				result = min(result, abs(new_a - new_b) + abs(new_b - new_c) + abs(new_c - new_a))
	print(result)


n = int(input())

def minthin(a, b, c):
	ma = max(a, b, c)
	mi = min(a, b, c)
	mid = a + b + c - ma - mi
	if ma == mi == mid:
		pass
	elif ma - mi == 1:
		mi += 1
	else:
		ma -= 1
		mi += 1
	return 2 * abs(ma - mi)
for i in range(n):
	numss = input()
	nums = numss.split(' ')
	ai = int(nums[0])
	ci = int(nums[1])
	bi = int(nums[2])
	print(minthin(ai, bi, ci))


def min_dist(pos):
	dist = 2 * (max(pos) - min(pos))
	if dist < 5:
		return 0
	return dist - 4
rounds = int(input())
for i in range(rounds):
	numbers = input().split()
	for i in range(len(numbers)):
		numbers[i] = int(numbers[i])
	print(min_dist(numbers))


for _ in '0' * int(input()):
	ns = sorted(map(int, input().split()))
	m = sum(ns) // 3 + 1 if sum(ns) % 3 == 2 else sum(ns) // 3
	for i in range(3):
		if ns[i] < m:
			ns[i] += 1
		elif ns[i] > m:
			ns[i] -= 1
	print(2 * (ns[2] - ns[0]))


import math
t = int(input())
P = [-1, 0, 1]
for _ in range(t):
	(a, b, c) = map(int, input().split())
	res = 10000000000
	for i in range(3):
		for j in range(3):
			for k in range(3):
				(x, y, z) = (a + P[i], b + P[j], c + P[k])
				res = min(res, math.fabs(x - y) + math.fabs(x - z) + math.fabs(y - z))
	print(int(res))


q = int(input())
ans = []
for i in range(q):
	(a, b, c) = map(int, input().split())
	l = sorted([a, b, c])
	if l[0] != l[1]:
		l[0] += 1
	elif l[1] != l[2]:
		l[0] += 1
		l[1] += 1
	if l[1] != l[2]:
		l[2] -= 1
	elif l[0] != l[1]:
		l[2] -= 1
		l[1] -= 1
	s = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	ans.append(s)
for i in range(q):
	print(ans[i])


t = int(input())
for _ in range(t):
	l1 = list(map(int, input().split()))
	l1.sort()
	if l1[2] - l1[0] <= 2:
		print(0)
	else:
		l1[2] -= 1
		l1[0] += 1
		print(abs(l1[2] - l1[0]) * 2)


ilo = int(input())
for i in range(ilo):
	tmp = input().split()
	pol = list(map(int, tmp))
	pol.sort()
	if pol[2] - pol[0] > 1:
		wyn = 0
		wyn = (pol[2] - pol[0] - 2) * 2
		print(wyn)
	else:
		print(0)


def find_optimal_distance(distances):
	distance = distances.split()
	distance = [int(distance[i]) for i in range(len(distance))]
	distance = sorted(distance)
	if are_equal(distance):
		return 0
	elif distance[0] == distance[1]:
		distance[2] -= 1
		if are_equal(distance):
			return 0
		else:
			distance[0] += 1
			distance[1] += 1
	elif distance[1] == distance[2]:
		distance[0] += 1
		if are_equal(distance):
			return 0
		else:
			distance[1] -= 1
			distance[2] -= 1
	else:
		distance[0] += 1
		distance[2] -= 1
	optimal_distance = abs(distance[0] - distance[1]) + abs(distance[1] - distance[2]) + abs(distance[0] - distance[2])
	return optimal_distance

def are_equal(distance):
	if distance[0] == distance[1] and distance[1] == distance[2] and (distance[0] == distance[2]):
		return True
	return False

def main():
	tests = eval(input())
	for i in range(tests):
		test = input()
		print(find_optimal_distance(test))
main()


q = int(input())
messages = []
for _ in range(q):
	(a, b, c) = map(int, input().split())
	minimum = float('inf')
	for da in range(-1, 2):
		a_v = a + da
		for db in range(-1, 2):
			b_v = b + db
			for dc in range(-1, 2):
				c_v = c + dc
				value = abs(c_v - b_v) + abs(a_v - b_v) + abs(a_v - c_v)
				minimum = min(value, minimum)
	messages.append(minimum)
print(*messages, sep='\n')


def calc(arr):
	arr = list(set(arr))
	arr.sort()
	if len(arr) == 1:
		return 0
	elif len(arr) == 2:
		if abs(arr[0] - arr[1]) - 2 < 0:
			return 0
		else:
			return 2 * (abs(arr[1] - arr[0]) - 2)
	else:
		if arr[0] != arr[1]:
			arr[0] += 1
		if arr[2] != arr[1]:
			arr[2] -= 1
		return abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	print(calc([a, b, c]))


for _ in range(int(input())):
	L = list(map(int, input().split()))
	L.sort()
	a = L[0]
	b = L[1]
	c = L[2]
	ans = abs(a - b) + abs(b - c) + abs(c - a) - 4
	if ans < 0:
		print(0)
	else:
		print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = (a, b, c)
	a1 = [a, a - 1, a + 1]
	b1 = [b, b - 1, b + 1]
	c1 = [c, c - 1, c + 1]
	ans = 10 ** 15
	for i in a1:
		for j in b1:
			for k in c1:
				ans = min(ans, abs(i - j) + abs(i - k) + abs(j - k))
	print(ans)


for i in range(int(input())):
	x = [int(x) for x in input().split()]
	x[0] -= 1
	x[1] -= 1
	x[2] -= 1
	mx = sum(x) * 10000
	for j in range(3):
		for k in range(3):
			for l in range(3):
				a = x[0] + j
				b = x[1] + k
				c = x[2] + l
				mx = min(mx, abs(a - b) + abs(a - c) + abs(b - c))
	print(mx)


for i in range(int(input())):
	l = list(input().split())
	l = [int(i) for i in l]
	a = [l[0] - 1, l[0], l[0] + 1]
	b = [l[1] - 1, l[1], l[1] + 1]
	c = [l[2] - 1, l[2], l[2] + 1]
	d = []
	for i in a:
		for j in b:
			for k in c:
				d.append(abs(i - j) + abs(i - k) + abs(j - k))
	d.sort()
	print(d[0])


for _ in range(int(input())):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	c = l[2]
	if a == b and b == c:
		print(0)
	else:
		k = abs(a - b) + abs(b - c) + abs(c - a)
		x = k - 4
		if x > 0:
			print(x)
		else:
			print(0)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(a, b, c) = sorted([a, b, c])
	ma = 0
	ma += max(0, b - a - 1)
	ma = float('inf')
	for i in [0, -1, 1]:
		for j in [0, -1, 1]:
			for k in [0, -1, 1]:
				aa = a + i
				cc = c + j
				bb = b + k
				ma = min(ma, abs(aa - cc) + abs(aa - bb) + (cc - bb))
	print(ma)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(a, b, c) = rints()
	mn = 10 ** 18
	for da in (-1, 0, 1):
		for db in (-1, 0, 1):
			for dc in (-1, 0, 1):
				(ai, bi, ci) = (a + da, b + db, c + dc)
				mn = min(mn, abs(ci - ai) + abs(ci - bi) + abs(bi - ai))
	print(mn)


for i in range(int(input())):
	(x, y, z) = sorted(map(int, input().split()))
	if x == y == z:
		print(0)
	elif x == y:
		print(max(2 * (z - x) - 4, 0))
	elif y == z:
		print(max(2 * (z - x) - 4, 0))
	else:
		print(z - x + z - y + y - x - 4)


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().rstrip().split())
	l = sorted([a, b, c])
	if a == b == c or (l[0] == l[1] and l[2] - l[1] == 1) or l[1] - l[0] == l[2] - l[1] == 1 or (l[1] == l[2] and l[1] - l[0] == 1):
		print(0)
	elif l[1] == l[2]:
		tpd = (l[1] - (l[0] + 1)) * 2
		print(tpd - 2)
	elif l[0] == l[1]:
		tpd = (l[2] - 1 - l[1]) * 2
		print(tpd - 2)
	else:
		tpd = abs(l[0] + 1 - l[1]) + abs(l[2] - 1 - l[1]) + abs(l[0] + 1 - (l[2] - 1))
		print(tpd)


def fun(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for i in range(int(input())):
	(a, b, c) = [int(j) for j in input().split()]
	p = [-1, 0, 1]
	m = fun(a, b, c)
	for j in range(3):
		for k in range(3):
			for l in range(3):
				m = min(m, fun(a + p[j], b + p[k], c + p[l]))
	print(m)


q = int(input())
for _ in range(q):
	a = list(map(int, input().split()))
	a.sort()
	ans = 100000000000000
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				n = [0] * 3
				n[0] = a[0] + i
				n[1] = a[1] + j
				n[2] = a[2] + k
				n.sort()
				ans = min(ans, n[1] - n[0] + n[2] - n[1] + n[2] - n[0])
	print(ans)


for _ in range(int(input())):
	a = sorted(list(map(int, input().split())))
	if a[0] == a[1] and a[0] != a[2]:
		a[0] += 1
		a[1] += 1
	if a[1] == a[2] and a[2] != a[0]:
		a[2] -= 1
		a[1] -= 1
	a[0] = a[0] + min(1, a[1] - a[0])
	a[2] = a[2] - min(1, a[2] - a[1])
	print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))


test_cases = int(input())
for each_test_case in range(test_cases):
	abc = list(map(int, input().split()))
	abc.sort(reverse=True)
	most_max = abc[0] - 1
	middle = abc[1]
	middle_mins = abc[1] - 1
	middle_plus = abc[1] + 1
	most_min = abc[2] + 1
	p01 = min(abs(most_max - middle), abs(abc[0] - middle))
	p02 = min(abs(most_max - most_min), abs(abc[0] - most_min), abs(abc[0] - abc[2]))
	p12 = min(abs(middle - most_min), abs(middle - abc[2]))
	p01_mn = min(abs(most_max - middle_mins), abs(abc[0] - middle_mins))
	p12_mn = min(abs(middle_mins - most_min), abs(middle_mins - abc[2]))
	p01_mp = min(abs(most_max - middle_plus), abs(abc[0] - middle_plus))
	p12_mp = min(abs(middle_plus - most_min), abs(middle_plus - abc[2]))
	ans1 = p01 + p02 + p12
	ans2 = p01_mn + p02 + p12_mn
	ans3 = p01_mp + p02 + p12_mp
	print(min(ans1, ans2, ans3))


n = int(input())
for i in range(n):
	(x, y, z) = map(int, input().split())
	a = min([x, y, z])
	c = max([x, y, z])
	b = x + y + z - a - c
	if a == b and c == b:
		print(0)
	elif a == b and c > b:
		print(max(c - 1 - a - 1 + c - 1 - b - 1, 0))
	elif a < b and c == b:
		print(max(c - 1 - a - 1 + b - 1 - a - 1, 0))
	else:
		print(2 * (c - a - 2))


for _ in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	min_pair = None
	for i in [a - 1, a, a + 1]:
		for j in [b - 1, b, b + 1]:
			for k in [c - 1, c, c + 1]:
				pair = abs(i - j) + abs(i - k) + abs(j - k)
				if min_pair is None or min_pair > pair:
					min_pair = pair
	print(min_pair)


for i in range(int(input())):
	arr = sorted(list(map(int, input().split())))
	print(2 * max(arr[2] - arr[0], 2) - 4)


q = int(input())
for p in range(q):
	(a, b, c) = map(int, input().split())
	r = max(a, b, c) - min(a, b, c)
	if r > 1:
		print((r - 2) * 2)
	else:
		print(0)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	if a == b and b == c and (a == c):
		print(0)
	elif a != b and b != c and (a != c):
		mid = a + b + c - max(a, b, c) - min(a, b, c)
		print(abs(a - b) + abs(b - c) + abs(a - c) - 4)
	else:
		q = [a, b, c]
		mx = max(a, b, c)
		mn = min(a, b, c)
		d = abs(a - b) + abs(b - c) + abs(a - c) - 4
		if d < 0:
			print(0)
		else:
			print(d)


def dist(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def solve(a, b, c):
	best = dist(a, b, c)
	for da in (-1, 0, 1):
		for db in (-1, 0, 1):
			for dc in (-1, 0, 1):
				best = min(best, dist(a + da, b + db, c + dc))
	return best
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	print(solve(a, b, c))


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	print(max((a[2] - a[0] - 2) * 2, 0))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	A = []
	A.append(a)
	A.append(b)
	A.append(c)
	A = sorted(A)
	if A[0] == A[1] == A[2]:
		print(0)
	elif A[0] == A[1]:
		if A[2] == A[1] + 1:
			print(0)
		elif A[2] > A[1] + 1:
			A[0] += 1
			A[1] += 1
			A[2] -= 1
			print(abs(A[2] - A[1]) + abs(A[1] - A[0]) + abs(A[2] - A[0]))
	elif A[1] == A[2]:
		if A[0] == A[1] - 1:
			print(0)
		elif A[1] > A[0] + 1:
			A[0] += 1
			A[1] -= 1
			A[2] -= 1
			print(abs(A[2] - A[1]) + abs(A[1] - A[0]) + abs(A[2] - A[0]))
	else:
		A[0] += 1
		A[2] -= 1
		print(abs(A[2] - A[1]) + abs(A[1] - A[0]) + abs(A[2] - A[0]))


n = int(input())
for _ in range(n):
	s = list(map(int, input().split()))
	s.sort()
	if s[0] == s[1] == s[2]:
		print(0)
		continue
	if s[0] == s[1] and s[0] != s[2]:
		s[0] += 1
		s[1] += 1
	if s[1] == s[2] and s[0] != s[1]:
		s[2] -= 1
		s[1] -= 1
	if s[0] != s[1]:
		s[0] += 1
	if s[1] != s[2]:
		s[2] -= 1
	sr = abs(s[0] - s[1]) + abs(s[0] - s[2]) + abs(s[1] - s[2])
	print(sr)


n = int(input())
final = []
for i in range(n):
	(a, b, c) = map(int, input().split())
	x = a - 1
	y = b - 1
	z = c - 1
	p = a + 1
	q = b + 1
	r = c + 1
	l = []
	for i in (a, x, p):
		for j in (b, y, q):
			for k in (c, z, r):
				l.append(abs(i - j) + abs(i - k) + abs(j - k))
	final.append(min(l))
for i in range(0, n):
	print(final[i])


n = int(input())
ps = []
ans = []
for i in range(n):
	(a, b, c) = input().split()
	for j in range(-1, 2):
		a1 = int(a) + j
		for k in range(-1, 2):
			b1 = int(b) + k
			for l in range(-1, 2):
				c1 = int(c) + l
				sol = abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1)
				ps.append(sol)
	ans.append(min(ps))
	ps = []
for m in ans:
	print(m)


from sys import stdin, stdout
c = int(stdin.readline().strip())
for caso in range(c):
	(a, b, c) = map(int, stdin.readline().strip().split())
	ans = 10 ** 20
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				ans = min(abs(i - j) + abs(i - k) + abs(j - k), ans)
	print(ans)


n = int(input())
x = []
for i in range(n):
	x = input().split()
	x = [int(i) for i in x]
	res = max(x[0], x[1]) - min(x[0], x[1]) + (max(x[0], x[2]) - min(x[0], x[2])) + (max(x[2], x[1]) - min(x[2], x[1]))
	if res > 4:
		print(res - 4)
	else:
		print(0)


t = int(input())
for i in range(t):
	n = input()
	s = map(int, n.split())
	d = sorted(list(set(s)))
	if len(d) == 1:
		a = 0
	elif len(d) == 2:
		if d[1] - d[0] == 1:
			a = 0
		else:
			(d[0], d[1]) = (d[0] + 1, d[1] - 1)
			a = (d[1] - d[0]) * 2
	else:
		(d[0], d[2]) = (d[0] + 1, d[2] - 1)
		a = d[1] - d[0] + d[2] - d[0] + d[2] - d[1]
	print(a)


def sint():
	return int(input())

def sints():
	return map(int, input().split())

def sara():
	return list(map(int, input().split()))

def sstr():
	s = input()
	return list(s[:len(s)])

def main():
	t = int(input())
	while t:
		t -= 1
		ara = sara()
		ara.sort()
		dis = 2 * ara[2] - 2 * ara[0]
		print(max(dis - 4, 0))
main()


import sys
import math
t = int(input())
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	maxL = min(a, b, c)
	maxR = max(a, b, c)
	maxR -= 1
	maxL += 1
	print(max(0, (maxR - maxL) * 2))


t = int(input())
a = []
for i in range(t):
	b = list(map(int, input().split()))
	a.append(b)
for i in a:
	i.sort()
	if i[0] == i[1] == i[2]:
		print(0)
	elif i[0] == i[2] - 1:
		print(0)
	else:
		print(2 * (i[2] - i[0] - 2))


from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(1000000000)
d = defaultdict(lambda : 0, {})

def io():
	return map(int, input().split())

def op():
	return list(map(int, input().split()))

def o():
	return int(input())

def r(x):
	if type(x) == int:
		return range(x)
	else:
		return range(len(x))

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
MOD = 1000000007
MAX = float('inf')
MIN = -float('inf')
p = input
for i in r(o()):
	l = op()
	l.sort()
	(a, b, c) = l
	if a == b == c:
		print(0)
	elif a == b:
		if c - b == 1:
			print(0)
		else:
			print(2 * (c - b - 2))
	elif b == c:
		if b - a == 1:
			print(0)
		else:
			print(2 * (b - a - 2))
	else:
		a += 1
		c -= 1
		print(b - a + c - a + c - b)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(a, b, c) = inputnums()
	print(max(0, 2 * (max(a, max(b, c)) - min(a, min(b, c)) - 2)))


from sys import stdin
from itertools import product

def solve():
	q = int(stdin.readline().strip())
	for _ in range(q):
		(a, b, c) = [int(i) for i in stdin.readline().strip().split(' ')]
		results = set()
		for (sa, sb, sc) in product([-1, 0, 1], [-1, 0, 1], [-1, 0, 1]):
			a_ = a + sa
			b_ = b + sb
			c_ = c + sc
			res = abs(a_ - b_) + abs(b_ - c_) + abs(c_ - a_)
			results.add(res)
		print(min(results))
solve()


def dis(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
t = int(input())
while t > 0:
	t -= 1
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	c = l[2]
	ans = dis(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = a + i
				y = b + j
				z = c + k
				s = dis(x, y, z)
				if s < ans:
					ans = s
	print(ans)


def solve(nums):
	if nums[0] == nums[1] == nums[2]:
		print(0)
		return
	if nums[0] == nums[1]:
		if nums[0] == nums[2] - 1:
			print(0)
		else:
			nums[0] += 1
			nums[1] += 1
			nums[2] -= 1
			delta = 2 * abs(nums[0] - nums[2])
			print(delta)
		return
	if nums[2] == nums[1]:
		if nums[0] == nums[2] - 1:
			print(0)
		else:
			nums[0] += 1
			nums[1] -= 1
			nums[2] -= 1
			delta = 2 * abs(nums[0] - nums[2])
			print(delta)
		return
	nums[0] += 1
	nums[2] -= 1
	delta = 0
	delta += abs(nums[0] - nums[2])
	delta += abs(nums[0] - nums[1])
	delta += abs(nums[2] - nums[1])
	print(delta)
	return
q = int(input())
for i in range(q):
	nums = [int(x) for x in input().split()]
	nums.sort()
	solve(nums)


q = int(input())
for i in range(q):
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	(a, b, c) = sorted([a, b, c])
	if a != b:
		a += 1
	elif b != c:
		a += 1
		b += 1
	if b != c:
		c -= 1
	elif a != b:
		b -= 1
		c -= 1
	print(c - b + b - a + c - a)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 998244353

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7

def readInts():
	return list(map(int, input().split()))

def I():
	return int(input())
for _ in range(I()):
	(a, b, c) = readInts()
	dist = abs(a - b) + abs(b - c) + abs(c - a)
	print(max(0, dist - 4))


t = int(input())
ans = []
for i in range(t):
	abc = list(map(int, input().split()))
	abc.sort()
	(a, b, c) = abc
	if b - a <= 1 and c - b <= 1:
		ans.append(0)
	elif b - a < c - b:
		a += 1
		b += 1
		c -= 1
		stp = abs(b - a + (c - b) + (c - a))
		ans.append(stp)
	elif b - a > c - b:
		a += 1
		b -= 1
		c -= 1
		stp = abs(b - a + (c - b) + (c - a))
		ans.append(stp)
	else:
		a += 1
		c -= 1
		stp = abs(b - a + (c - b) + (c - a))
		ans.append(stp)
for i in range(len(ans)):
	print(ans[i])


def evaluate(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	results = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				results.append(evaluate(a + i, b + j, c + k))
	print(min(results))


for i in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1] == l[2] or l[0] == l[1] == l[2] - 1 or l[1] == l[2] == l[0] + 1:
		print(0)
	elif l[0] == l[1]:
		print(abs(l[2] - l[1] - 2) + abs(l[2] - l[0] - 2))
	elif l[1] == l[2]:
		c = l[0] + 1
		a = l[1] - 1
		b = l[2] - 1
		print(abs(c - b) + abs(c - a))
	else:
		a = l[0] + 1
		c = l[2] - 1
		print(abs(a - l[1]) + abs(a - c) + abs(l[1] - c))


import time
import string
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
q = int(input())
while q > 0:
	q -= 1
	(a, b, c) = list(map(lambda x: int(x), input().split(' ')))
	f = abs(b - a)
	s = abs(c - a)
	d = abs(b - c)
	print(max(0, f + s + d - 4))
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


def main(l):
	x = [l[0], l[0] + 1, l[0] - 1]
	y = [l[1], l[1] - 1, l[1] + 1]
	z = [l[2], l[2] - 1, l[2] + 1]
	ans = []
	for i in x:
		for j in y:
			for k in z:
				ans.append(abs(i - j) + abs(i - k) + abs(j - k))
	print(min(ans))

def runner():
	val = input()
	x = []
	for i in range(int(val)):
		ans = input()
		ans = ans.split(' ')
		ans = [int(i) for i in ans]
		x.append(ans)
	for i in range(int(val)):
		main(x[i])
runner()


for _ in range(int(input())):
	abc = [int(x) for x in input().split()]
	abc = sorted(abc)
	a = abc[0]
	b = abc[1]
	c = abc[2]
	if c > b and a == b:
		a += 1
		b += 1
	elif a < b:
		a += 1
	if a < b and c == b:
		c -= 1
		b -= 1
	elif c > b:
		c -= 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


import math
q = input()
for i in range(int(q)):
	pos = input()
	lines = pos.split(' ')
	for j in range(len(lines)):
		lines[j] = int(lines[j])
	lines.sort()
	if lines[0] == lines[1]:
		if lines[1] < lines[2]:
			lines[0] += 1
			lines[1] += 1
	if lines[0] < lines[1]:
		lines[0] += 1
	if lines[1] == lines[2]:
		if lines[1] > lines[0]:
			lines[1] -= 1
			lines[2] -= 1
	if lines[1] < lines[2]:
		lines[2] -= 1
	r = math.fabs(lines[0] - lines[1]) + math.fabs(lines[0] - lines[2]) + math.fabs(lines[1] - lines[2])
	print(int(r))


for q in range(int(input())):
	x = [int(e) for e in input().split()]
	(h, l) = (max(x), min(x))
	if h - l < 3:
		print(0)
		continue
	print((h - l - 2) * 2)


n = int(input())
for i in range(n):
	(a, b, c) = [int(x) for x in input().split(' ')]
	min_dist = float('inf')
	for x in range(-1, 2):
		for y in range(-1, 2):
			for z in range(-1, 2):
				aa = a + x
				bb = b + y
				cc = c + z
				min_dist = min(min_dist, abs(aa - bb) + abs(aa - cc) + abs(bb - cc))
	print(min_dist)


import sys
from bisect import bisect
n = int(input())
for _ in range(n):
	(a, b, c) = map(int, input().split())
	r = [-1, 0, 1]
	m = 10 ** 19
	for i in r:
		for j in r:
			for k in r:
				arr = [a + i, b + j, c + k]
				(mn, mx) = (min(arr), max(arr))
				m = min(m, mx - mn)
	print(m * 2)


q = int(input())

def calc(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for i in range(q):
	(a, b, c) = map(int, input().split())
	cases = []
	for i1 in range(-1, 2, 1):
		for i2 in range(-1, 2, 1):
			for i3 in range(-1, 2, 1):
				cases.append(calc(a + i1, b + i2, c + i3))
	print(min(cases))


for _ in range(int(input())):
	(a, b, c) = sorted(list(map(int, input().split())))
	if a < c:
		a += 1
	if c > a:
		c -= 1
	print(2 * c - 2 * a)


for _ in range(int(input())):
	lis = [0] * 3
	(lis[0], lis[1], lis[2]) = map(int, input().split())
	lis.sort()
	ans = lis[1] - lis[0] + lis[2] - lis[1] + lis[2] - lis[0]
	print(max(0, ans - 4))


n = int(input())

def sum_dist(a, b, c):
	return abs(a - b) + abs(a - c) + abs(c - b)
output = ''
for i in range(n):
	(a, b, c) = map(int, input().split())
	mind = sum_dist(a, b, c)
	for ia in range(a - 1, a + 2):
		for ib in range(b - 1, b + 2):
			for ic in range(c - 1, c + 2):
				if sum_dist(ia, ib, ic) < mind:
					mind = sum_dist(ia, ib, ic)
	output = output + str(mind) + '\n'
print(output)


n = int(input())

def solve():
	(a, b, c) = [int(i) for i in input().split(' ')]
	l = min(a, b, c)
	r = max(a, b, c)
	print(max(2 * (r - l) - 4, 0))
for i in range(n):
	solve()


q = int(input())
pairwise = lambda x, y, z: abs(x - y) + abs(x - z) + abs(y - z)
cnt = 0
while cnt < q:
	x = [int(i) for i in input().split()]
	x.sort()
	(a, b, c) = x
	if a == b and b == c:
		print(0)
	else:
		minimum = float('inf')
		for i in range(-1, 2):
			for j in range(-1, 2):
				for k in range(-1, 2):
					minimum = min(minimum, pairwise(a + i, b + j, c + k))
		print(minimum)
	cnt += 1


def cal(a, b, c):
	return abs(a - b) + abs(c - b) + abs(a - c)

def func(a):
	a.sort()
	b = a[1]
	c = a[2]
	a = a[0]
	a1 = min(cal(a + 1, b, c), cal(a + 1, b, c - 1), cal(a, b, c), cal(a, b, c - 1))
	a2 = min(cal(a + 1, b + 1, c), cal(a + 1, b + 1, c - 1), cal(a, b + 1, c), cal(a, b + 1, c - 1))
	a3 = min(cal(a + 1, b - 1, c), cal(a + 1, b - 1, c - 1), cal(a, b - 1, c), cal(a, b - 1, c - 1))
	return min(a1, a2, a3)
for i in range(int(input())):
	a = list(map(int, input().split()))
	print(func(a))


q = int(input())
for test in range(q):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	pos = [a, b, c]
	pos.sort()
	dist_ab = pos[1] - pos[0]
	dist_bc = pos[2] - pos[1]
	dist_ca = pos[2] - pos[0]
	total = dist_ab + dist_bc + dist_ca
	if dist_ab == 0:
		if dist_bc > 2:
			total -= 4
		else:
			total = 0
	elif dist_bc == 0:
		if dist_ab > 2:
			total -= 4
		else:
			total = 0
	else:
		total -= 4
	print(total)


t = int(input())
for i in range(t):
	l = sorted(list(map(int, input().split())))
	s = sorted(set(l))
	if len(s) == 1 or (len(s) == 2 and s[1] - s[0] == 1):
		print(0)
	else:
		l[0] += 1
		l[1] += 1
		l[2] -= 1
		print(l[2] - l[1] + (l[1] - l[0]) + (l[2] - l[0]))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	(a, b, c) = (l[0], l[1], l[2])
	ans1 = abs(a - b) + abs(a - c) + abs(b - c)
	ans2 = abs(a + 1 - b) + abs(a + 1 - c) + abs(b - c)
	ans3 = abs(a - b) + abs(a - (c - 1)) + abs(b - (c - 1))
	ans4 = abs(a + 1 - b) + abs(a + 1 - (c - 1)) + abs(b - (c - 1))
	ans5 = abs(a - b) + abs(a - (c - 2)) + abs(b - (c - 2))
	ans6 = abs(a + 2 - b) + abs(a + 2 - c) + abs(b - c)
	print(min(ans1, ans2, ans3, ans4, ans5, ans6))


def friends(a, b, c):
	l = [a, b, c]
	l.sort()
	total = 0
	total = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
	return max(0, total - 4)
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	print(friends(a, b, c))


t = int(input())
for i in range(t):
	temp = list(input().split())
	x = int(temp[0])
	y = int(temp[1])
	z = int(temp[2])
	a = max(x, max(y, z))
	c = min(x, min(y, z))
	if a - c > 2:
		print(2 * (a - c - 2))
	else:
		print(0)


for _ in range(int(input())):
	F = list(map(int, input().split()))
	F.sort()
	ans = 0
	a = F[1] - F[0]
	b = F[2] - F[1]
	c = F[2] - F[0]
	if a >= 1 and b >= 1:
		ans = a + b + c - 4
	elif a == 0 and b == 1 or (b == 0 and a == 1):
		ans = a + b + c - 2
	elif a > 1 and b == 0 or (a == 0 and b > 1):
		ans = a + b + c - 4
	elif c == 0:
		ans = 0
	print(ans)


t = int(input())
for T in range(t):
	l = [int(x) for x in input().split()]
	l.sort()
	(v1, v2) = (0, 0)
	ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2])
	if l[0] == l[1] and l[1] != l[2]:
		if l[2] == l[1] + 1:
			l[2] -= 1
		else:
			l[2] -= 1
			l[1] += 1
			l[0] += 1
		ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2])
	elif l[0] != l[1] and l[1] != l[2]:
		l[0] += 1
		l[2] -= 1
		ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2])
	elif l[0] != l[1] and l[1] == l[2]:
		if l[0] == l[1] - 1:
			l[0] += 1
		else:
			l[0] += 1
			l[1] -= 1
			l[2] -= 1
		ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2])
	print(ans)


q = int(input())
l = []
for i in range(q):
	l.append([int(i) for i in input().split(' ')])
for i in range(q):
	sr = round((l[i][0] + l[i][1] + l[i][2]) / 3)
	for j in range(3):
		if l[i][j] < sr:
			l[i][j] = l[i][j] + 1
		elif l[i][j] > sr:
			l[i][j] = l[i][j] - 1
	print(abs(l[i][0] - l[i][1]) + abs(l[i][0] - l[i][2]) + abs(l[i][1] - l[i][2]))


for _ in range(int(input())):
	m = 3000000003
	(a, b, c) = map(int, input().split())
	for q in (a, a - 1, a + 1):
		for w in (b, b - 1, b + 1):
			for e in (c, c - 1, c + 1):
				m = min(m, abs(q - w) + abs(w - e) + abs(q - e))
	print(m)


from math import ceil

def solve(a, b, c):
	avg = int(ceil((a + b + c) / 3))
	avg1 = int((a + b + c) / 3)
	ll = [a, b, c]
	ll.sort()
	ll1 = ll.copy()
	if ll[0] < avg:
		ll[0] += 1
	if ll[1] < avg:
		ll[1] += 1
	elif ll[1] > avg:
		ll[1] -= 1
	if ll[2] > avg:
		ll[2] -= 1
	if ll1[0] < avg1:
		ll1[0] += 1
	if ll1[1] < avg1:
		ll1[1] += 1
	elif ll1[1] > avg1:
		ll1[1] -= 1
	if ll1[2] > avg1:
		ll1[2] -= 1
	s1 = abs(ll[0] - ll[1]) + abs(ll[0] - ll[2]) + abs(ll[2] - ll[1])
	s2 = abs(ll1[0] - ll1[1]) + abs(ll1[0] - ll1[2]) + abs(ll1[2] - ll1[1])
	print(min(s1, s2))
	return
t = int(input())
while t != 0:
	(a, b, c) = map(int, input().split())
	solve(a, b, c)
	t -= 1


p = int(input())
out = []
for i in range(p):
	(a, b, c) = sorted(map(int, input().split()))
	out.append(max(0, (c - a - 2) * 2))
for i in out:
	print(i)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	(x, y, z) = a
	x1 = x - 1
	x2 = x + 1
	y1 = y - 1
	y2 = y + 1
	z1 = z - 1
	z2 = z + 2
	m = abs(x - y) + abs(x - z) + abs(y - z)
	for i in (x, x1, x2):
		for j in (y, y1, y2):
			for k in (z, z1, z2):
				m = min(m, abs(i - j) + abs(i - k) + abs(j - k))
	print(m)


for test_Case in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = [a, b, c]
	ans.sort(reverse=True)
	if a == b == c:
		print(0)
	elif ans[0] == ans[1]:
		final = abs(ans[0] - ans[1]) + abs(ans[0] - (ans[2] + 1)) + abs(ans[1] - (ans[2] + 1))
		final_2 = abs(ans[0] - 1 - (ans[1] - 1)) + abs(ans[0] - 1 - (ans[2] + 1)) + abs(ans[1] - 1 - (ans[2] + 1))
		print(min(final, final_2))
	elif ans[1] == ans[2]:
		final = abs(ans[0] - 1 - ans[1]) + abs(ans[0] - 1 - ans[2])
		final_2 = abs(ans[0] - 1 - (ans[1] + 1)) + abs(ans[0] - 1 - (ans[2] + 1))
		print(min(final, final_2))
	else:
		if ans[0] - ans[1] > 0:
			ans[0] -= 1
		if ans[1] - ans[2] > 0:
			ans[2] += 1
		print(abs(ans[0] - ans[1]) + abs(ans[0] - ans[2]) + abs(ans[1] - ans[2]))


q = int(input())
test_cases = list()
j = 0
while j < q:
	test_cases.append(list(map(int, input().split(' '))))
	j += 1

def v(a):
	return abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0])

def mindist(lis_t, j=0):
	minc = v(lis_t)
	if j != 3:
		minc = min(minc, mindist([lis_t[1], lis_t[2], lis_t[0] - 1], j + 1), mindist([lis_t[1], lis_t[2], lis_t[0] + 1], j + 1), mindist([lis_t[1], lis_t[2], lis_t[0]], j + 1))
	return minc
a = list(map(mindist, test_cases))
for i in a:
	print(i)


actions = [-1, 0, 1]

def solve(f1, f2, f3):
	return abs(f1 - f2) + abs(f1 - f3) + abs(f2 - f3)
n_cases = int(input())
results = []
for _ in range(n_cases):
	friends = list(map(int, input().strip().split(' ')))
	solutions = [[current + action for action in actions] for current in friends]
	best = None
	for i in solutions[0]:
		for j in solutions[1]:
			for k in solutions[2]:
				result = solve(i, j, k)
				if best is None:
					best = result
				elif result < best:
					best = result
	results.append(best)
print('\n'.join(map(str, results)))


test = int(input())
for t in range(test):
	arr = input().split()
	arr = [int(i) for i in arr]
	arr.sort()
	if arr[0] == arr[1] and arr[1] == arr[2]:
		print('0')
	elif arr[0] != arr[1] and arr[1] != arr[2] and (arr[0] != arr[2]):
		arr[0] += 1
		arr[2] -= 1
		dist1 = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[2] - arr[0])
		print(dist1)
	else:
		if arr[0] == arr[1]:
			arr[2] -= 1
			if arr[2] != arr[1]:
				arr[0] += 1
				arr[1] += 1
		elif arr[1] == arr[2]:
			arr[0] += 1
			if arr[0] != arr[1]:
				arr[1] -= 1
				arr[2] -= 1
		dist = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[2] - arr[0])
		print(dist)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	p = []
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	l[0] -= 1
	l[1] -= 2
	l[2] += 1
	for k in range(2):
		l[0] += 1
		l[2] = c + 1
		for j in range(2):
			l[2] -= 1
			l[1] = b - 2
			for i in range(3):
				l[1] += 1
				p.append(abs(l[0] - l[1]) + abs(l[2] - l[0]) + abs(l[1] - l[2]))
	print(min(p))


for _ in range(int(input())):
	p = [*map(int, input().split())]
	p.sort()
	if p[1] == p[2] == p[0]:
		print(0)
		continue
	if p[2] > p[1]:
		p[2] -= 1
	else:
		p[2] -= 1
		p[1] -= 1
		if p[0] < p[1]:
			p[0] += 1
			print(abs(p[2] - p[0]) + abs(p[1] - p[0]) + abs(p[2] - p[1]))
			continue
	if p[0] < p[1]:
		p[0] += 1
		print(abs(p[2] - p[0]) + abs(p[1] - p[0]) + abs(p[2] - p[1]))
	elif p[2] > p[1]:
		p[0] += 1
		p[1] += 1
		print(abs(p[2] - p[0]) + abs(p[1] - p[0]) + abs(p[2] - p[1]))
	else:
		print(0)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]

def fun(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	(a, b, c) = value()
	a = [a - 1, a, a + 1]
	b = [b - 1, b, b + 1]
	c = [c - 1, c, c + 1]
	ans = []
	for i in a:
		for j in b:
			for k in c:
				ans.append(fun(i, j, k))
	print(min(ans))


import sys

def calculate_pairwse_distance(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)

def optimize_distance(a, b, c):
	if a < b:
		a += 1
	elif a == b and c - b >= 2:
		a += 1
		b += 1
	if c > b:
		c -= 1
	elif c == b and b - a >= 1:
		b -= 1
		c -= 1
	return (a, b, c)
testcase_num = int(sys.stdin.readline())
for _ in range(testcase_num):
	test = sys.stdin.readline()
	values = [int(val) for val in test.split(' ')]
	values.sort()
	(a, b, c) = values
	(new_a, new_b, new_c) = optimize_distance(a, b, c)
	print(calculate_pairwse_distance(new_a, new_b, new_c))


t = int(input())
for i in range(t):
	a = sorted(list(map(int, input().split())))
	if a[0] != a[-1]:
		a[0] += 1
	if a[-1] != a[0]:
		a[-1] -= 1
	print(2 * (a[-1] - a[0]))


T = int(input())
for i in range(T):
	(a, b, c) = sorted([int(x) for x in input().split()])
	ans = 2 * (c - a)
	if c - a >= 2:
		print(ans - 4)
	else:
		print(0)


q = int(input())
for _ in range(q):
	count = 0
	l = sorted(list(map(int, input().rstrip().split())))
	if l[1] - l[0] > 1:
		count += l[1] - l[0] - 2 + l[2] - l[1] + l[2] - l[0] - 2
	elif l[1] - l[0] == 0 and l[2] - l[1] > 1:
		count += (l[2] - l[1] - 2) * 2
	else:
		if l[2] - l[1] > 1:
			count += l[2] - l[1] - 1
		if l[2] - l[0] > 1:
			count += l[2] - l[0] - 2
	print(count)


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	ans = []
	for i in [-1, 0, 1]:
		for j in [-1, 0, 1]:
			for k in [-1, 0, 1]:
				x = a + i
				y = b + j
				z = c + k
				ans.append(abs(x - y) + abs(y - z) + abs(z - x))
	print(min(ans))


import math
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = abs(a - b) + abs(a - c) + abs(b - c)
	for i in range(2):
		for j in range(2):
			for k in range(2):
				a1 = a + i
				b1 = b + j
				c1 = c + k
				a2 = a - i
				b2 = b - j
				c2 = c - k
				l1 = [a1, a2]
				l2 = [b1, b2]
				l3 = [c1, c2]
				for p in range(2):
					for q in range(2):
						for r in range(2):
							ans1 = abs(l1[p] - l2[q]) + abs(l1[p] - l3[r]) + abs(l2[q] - l3[r])
							if ans1 < ans:
								ans = ans1
	print(ans)


N = int(input())
for _ in range(N):
	(a, b, c) = map(int, input().split())
	ans = 10000000000.0
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				d = abs(i - j) + abs(j - k) + abs(i - k)
				ans = min(ans, d)
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] < a[2]:
		a[2] -= 1
	if a[0] < a[2]:
		a[0] += 1
	print(2 * (a[2] - a[0]))


def sort(m):
	if int(m[0]) > int(m[1]):
		(m[0], m[1]) = (m[1], m[0])
	if int(m[1]) > int(m[2]):
		(m[1], m[2]) = (m[2], m[1])
	if int(m[0]) > int(m[1]):
		(m[0], m[1]) = (m[1], m[0])
	return m
q = int(input())
m: str = ''
for i in range(q):
	n = sort(input().split())
	(a, b, c) = (int(n[0]), int(n[1]), int(n[2]))
	(r1, r2, r3) = (b - a, c - b, c - a)
	if c - a < 3:
		m += '0 '
	elif a - b < 2 or b - c < 2:
		m += str(min(abs(r1 + r2 + r3), abs(r1 + r2 + r3 - 4), abs(r1 + r2 + r3 - 2))) + ' '
	else:
		m += str(min(abs(r1 + r2 + r3), abs(r1 + r2 + r3 - 3), abs(r1 + r2 + r3 - 1))) + ' '
for c in m.split():
	print(c)


def f(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
q = int(input())
for _ in range(q):
	(a, b, c) = tuple([int(i) for i in input().split()])
	ans = f(a, b, c)
	for da in [-1, 0, 1]:
		for db in [-1, 0, 1]:
			for dc in [-1, 0, 1]:
				ans = min(ans, f(a + da, b + db, c + dc))
	print(ans)


q = int(input())
for i in range(q):
	a = [int(x) for x in input().split()]
	a.sort()
	flag = [0, 0, 0]
	if a[0] < a[1]:
		a[0] += 1
		flag[0] = 1
		if a[1] == a[2] and a[1] > a[0]:
			a[1] -= 1
			a[2] -= 1
			flag[1] = flag[2] = 1
	if a[1] < a[2]:
		a[2] -= 1
		flag[2] = 1
		if a[0] == a[1] and a[0] < a[2] and (flag[0] == 0):
			a[0] += 1
			a[1] += 1
	sum = a[1] - a[0] + a[2] - a[1] + a[2] - a[0]
	print(sum)


t = int(input())
for _ in range(t):
	l = list(map(int, input().strip().split()))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if a == b == c or (b - a == 1 and c - b == 1):
		print(0)
	elif a == b:
		if c - b > 1:
			a = a + 1
			b = b + 1
		c = c - 1
		print(b - a + (c - b) + (c - a))
	elif b == c:
		if b - a > 1:
			b = b - 1
			c = c - 1
		a = a + 1
		print(b - a + (c - b) + (c - a))
	else:
		a = a + 1
		b = b + 1
		c = c - 1
		print(b - a + (c - b) + (c - a))


def arr_inp():
	return [int(x) for x in input().split()]
for i in range(int(input())):
	a = sorted(arr_inp())
	if a[2] > a[0]:
		a[2] -= 1
	if a[1] < a[2]:
		a[1] += 1
	elif a[1] > a[2]:
		a[1] -= 1
	if a[0] < a[1]:
		a[0] += 1
	print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))


import math
from sys import stdin, stdout
for a in range(int(stdin.readline())):
	L = list(map(int, stdin.readline().split()))
	L.sort()
	if L[0] < L[1] and L[2] > L[1]:
		L[0] += 1
		L[2] -= 1
	elif L[0] == L[1] != L[2]:
		L[0] += 1
		L[1] += 1
		if L[0] != L[2]:
			L[2] -= 1
	elif L[0] != L[1] == L[2]:
		L[1] -= 1
		L[2] -= 1
		if L[0] != L[2]:
			L[0] += 1
	k = 2 * (L[2] - L[0])
	stdout.write(str(k))
	stdout.write('\n')


def test(a, b, c):
	ans = abs(b - a) + abs(b - c) + abs(a - c)
	for i in range(-1, 2):
		a += i
		for j in range(-1, 2):
			b += j
			for k in range(-1, 2):
				c += k
				if abs(b - a) + abs(b - c) + abs(a - c) < ans:
					ans = ans = abs(b - a) + abs(b - c) + abs(a - c)
				c -= k
			b -= j
		a -= i
	print(ans)
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	test(a, b, c)


print(*[next(map(lambda x: max(0, 2 * (max(x) - min(x) - 2)), [list(map(int, input().split()))])) for _ in range(int(input()))], sep='\n')


import math
for i in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	ans = 2 * a[2] - 2 * a[0]
	if ans - 4 >= 0:
		print(ans - 4)
	elif ans - 2 >= 0:
		print(ans - 2)
	elif ans - 1 >= 0:
		print(ans - 1)
	else:
		print(ans)


def solve():
	num = [int(x) for x in input().split()]
	num.sort()
	if num[2] - num[0] <= 2:
		print(0)
	else:
		print((num[2] - num[0] - 2) * 2)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	xs = sorted(list(map(int, input().strip().split())))
	print(str(max(xs[2] - xs[0] - 2, 0) * 2))


q = int(input())

def ab(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
arr = []
for i in range(q):
	(a, b, c) = [int(x) for x in input().split(' ')]
	ans = ab(a, b, c)
	for r in range(-1, 2):
		for s in range(-1, 2):
			for t in range(-1, 2):
				na = a + r
				nb = b + s
				nc = c + t
				ans = min(ans, ab(na, nb, nc))
	print(ans)


import collections
for _ in range(int(input())):
	tmp = input()
	n = map(int, tmp.split())
	n = list(n)
	n = sorted(n)
	c = collections.Counter(n)
	if len(c) == 1:
		print(0)
	elif len(c) == 2:
		(a, b) = c
		if abs(a - b) == 1:
			print(0)
		else:
			print(abs(a - b) * 2 - 4)
	else:
		(a, b, c) = n
		print(c + c - a - a - 4)


l = [[-1, -1, -1], [-1, -1, 1], [-1, 1, -1], [-1, 1, 1], [1, -1, -1], [1, -1, 1], [1, 1, -1], [1, 1, 1], [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [0, 0, -1], [0, -1, 0], [0, -1, -1], [-1, 0, 0], [-1, 0, -1], [-1, -1, 0], [1, 0, -1], [1, -1, 0], [0, 1, -1], [0, -1, 1], [-1, 0, 1], [-1, 1, 0]]
t = int(input())

def dif(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)

def change(vec, a, b, c):
	return (a + vec[0], b + vec[1], c + vec[2])
while t > 0:
	t -= 1
	dis = []
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print(0)
	else:
		for i in l:
			(d, e, f) = change(i, a, b, c)
			dis.append(dif(d, e, f))
		print(min(dis))


def differance(f1, f2, f3):
	return abs(f1 - f2) + abs(f2 - f3) + abs(f1 - f3)
repeat = int(input())
for rep in range(repeat):
	a = list(map(int, input().split()))
	f3 = max(a)
	a.remove(f3)
	f1 = min(a)
	a.remove(f1)
	f2 = 0
	for i in a:
		f2 = i
	if f1 == f2 and f2 != f3 and (abs(f3 - f2) != 1):
		f1 += 1
		f2 += 1
		f3 -= 1
	elif f2 == f3 and f1 != f2 and (abs(f1 - f2) != 1):
		f1 += 1
		f2 -= 1
		f3 -= 1
	else:
		if f1 != f2:
			f1 += 1
		if f3 != f2:
			f3 -= 1
	print(differance(f1, f2, f3))


for _ in range(int(input())):
	(a, b, c) = [int(__) for __ in input().split()]
	x = min(a, b, c)
	z = max(a, b, c)
	y = a + b + c - x - z
	if z - x == 1:
		x += 1
	elif z - x > 1:
		x += 1
		z -= 1
	print(min(z - x + abs(y - x) + abs(z - y), z - x + abs(y + 1 - x) + abs(z - y - 1), z - x + abs(y - 1 - x) + abs(z - y + 1)))


q = int(input())
for i in range(0, q):
	x = [int(i) for i in input().split()]
	x.sort()
	if x[1] == x[2] and x[1] > x[0]:
		x[1] -= 1
		x[2] -= 1
	if x[0] == x[1] and x[1] < x[2]:
		x[0] += 1
		x[1] += 1
	if x[1] < x[2]:
		x[2] -= 1
	if x[1] > x[0]:
		x[0] += 1
	print(x[1] - x[0] + (x[2] - x[1]) + (x[2] - x[0]))


def f(l):
	mx = max(l)
	mn = min(l)
	return max(mx - mn - 2 << 1, 0)
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


q = int(input())

def mod(x):
	if x < 0:
		return -x
	return x

def calc(x):
	return mod(x[0] - x[1]) + mod(x[1] - x[2]) + mod(x[0] - x[2])

def bt(x, i=0):
	current = calc(x)
	if i > 2:
		return current
	for add in range(-1, 2):
		y = x[:]
		y[i] += add
		current = min(current, bt(y, i + 1))
	return current
while q > 0:
	c = input()
	c = c.split()
	mini = bt([int(a) for a in c])
	print(mini)
	q -= 1


def main():
	for _ in range(int(input())):
		(a, b, c) = sorted(map(int, input().split()))
		print(max(c - a - 2, 0) * 2)
main()


cases = int(input())
for case in range(cases):
	values = list(map(lambda x: int(x), input().split()))
	values.sort()
	(a, b, c) = values
	if c - a:
		c -= 1
		if c - a:
			a += 1
	result = c - a + (c - b) + (b - a)
	print(result)


t = int(input())
for _ in range(t):
	b = input().split()
	a = [int(b[0]), int(b[1]), int(b[2])]
	a.sort()
	(x, y, z) = (int(a[0]), int(a[1]), int(a[2]))
	res = z - x + z - y + y - x
	print(max(res - 4, 0))


t = int(input())
for i in range(t):
	l1 = list(map(int, input().split()))
	a = abs(l1[0] - l1[1]) + abs(l1[1] - l1[2]) + abs(l1[2] - l1[0])
	if a >= 4:
		print(a - 4)
	else:
		print(0)


def pairwise_distance(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for i in range(q):
	(a, b, c) = list(map(int, input().split()))
	s = pairwise_distance(a, b, c)
	na = [a - 1, a, a + 1]
	nb = [b - 1, b, b + 1]
	nc = [c - 1, c, c + 1]
	for x in na:
		for y in nb:
			for z in nc:
				if pairwise_distance(x, y, z) < s:
					s = pairwise_distance(x, y, z)
	print(s)


t = int(input())
for ts in range(t):
	(a, b, c) = [int(i) for i in input().split()]
	print(max(0, abs(a - b) + abs(a - c) + abs(c - b) - 4))


N = int(input())
for _ in range(N):
	l = list(map(int, input().split()))
	ll = l[:]
	m = sum(l) / 3
	l.sort()
	for i in range(3):
		if l[i] < m:
			l[i] += 1
		elif l[i] > m:
			l[i] -= 1
	ans1 = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
	m2 = sum(ll) // 3
	for i in range(3):
		if ll[i] < m2:
			ll[i] += 1
		elif ll[i] > m2:
			ll[i] -= 1
	ans2 = abs(ll[0] - ll[1]) + abs(ll[0] - ll[2]) + abs(ll[1] - ll[2])
	print(min(ans1, ans2))


arv = int(input())
tests = []
for x in range(arv):
	tests.append(input())

def distance(aa, bb, cc):
	dist = abs(aa - bb) + abs(aa - cc) + abs(bb - cc)
	return dist
moves = [0, 1, -1]
for x in tests:
	voimalused = []
	temp = x.split()
	for num1 in range(3):
		a = int(temp[0]) + moves[num1]
		for num2 in range(3):
			b = int(temp[1]) + moves[num2]
			for num3 in range(3):
				c = int(temp[2]) + moves[num3]
				dist = distance(a, b, c)
				voimalused.append(dist)
	print(min(voimalused))


for tc in range(int(input())):
	a = sorted(list(map(int, input().split())))
	f = 1
	ans = abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2])
	print(min(ans, max(0, ans - 4)))


t = int(input())
while t > 0:
	(a, b, c) = map(int, input().split())
	s = abs(a - b) + abs(b - c) + abs(a - c)
	if abs(a - b) != 0 and abs(b - c) != 0 and (abs(a - c) != 0):
		print(s - 4)
	elif abs(a - b) == 0 and abs(b - c) != 0 or (abs(b - c) == 0 and abs(a - b) != 0) or (abs(a - c) == 0 and abs(a - b) != 0):
		if s - 4 >= 0:
			print(s - 4)
		else:
			print(s - 2)
	else:
		print(s)
	t -= 1


import sys
input = sys.stdin.readline
from collections import *
q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	ans = 10 ** 18
	for x in [a - 1, a, a + 1]:
		for y in [b - 1, b, b + 1]:
			for z in [c - 1, c, c + 1]:
				ans = min(ans, abs(x - y) + abs(y - z) + abs(z - x))
	print(ans)


n = int(input())
num_low = 0
num_mid = 0
min_high = 0
ls_abc = []
ls_temp = []
ans = 0
for i in range(n):
	ls_temp = list(map(int, input().split()))
	ls_abc.append(sorted(ls_temp))
for i in ls_abc:
	print(max(2 * (i[2] - i[0]) - 4, 0))


from sys import exit

def iis():
	return map(int, input().split())

def ii():
	return int(input())

def liis():
	return list(map(int, input().split()))

def tp(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
t = ii()
for _ in range(t):
	(a, b, c) = iis()
	ans = tp(a + 1, b + 1, c + 1)
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ans = min(ans, tp(a - i - 1, b - j - 1, c - k - 1))
	print(ans)
exit(0)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	arr = l()
	(x, y, z) = ([arr[0] - 1, arr[0], arr[0] + 1], [arr[1] - 1, arr[1], arr[1] + 1], [arr[2] - 1, arr[2], arr[2] + 1])
	answer = pow(10, 20)
	for i in x:
		for j in y:
			for k in z:
				answer = min(answer, abs(i - j) + abs(j - k) + abs(k - i))
	out(answer)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	first = min(a, b, c)
	third = max(a, b, c)
	second = a + b + c - (first + third)
	if first == second and second == third:
		pass
	elif first != second and second != third:
		first += 1
		third -= 1
	elif first == second and second != third:
		if first + 1 == third:
			third -= 1
		else:
			first += 1
			second += 1
			third -= 1
	elif first != second and second == third:
		if first + 1 == second:
			first += 1
		else:
			first += 1
			second -= 1
			third -= 1
	print(abs(first - second) + abs(second - third) + abs(first - third))


def an(a):
	return abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2])
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = [a, b, c]
	s.sort()
	if s[1] - s[0] > 0:
		s[0] += 1
		if s[1] - s[0] > 0:
			s[1] -= 1
		if s[2] - s[1] > 0:
			s[2] -= 1
	else:
		if s[2] - s[1] > 0:
			s[2] -= 1
		if s[2] - s[1] > 0:
			s[0] += 1
			s[1] += 1
	print(an(s))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	d = [a, b, c]
	f = [0, 0, 0, 0]
	p = 10 ** 20
	while f[-1] != 1:
		m = d * 1
		for j in range(3):
			if f[j] == 0:
				m[j] += 1
			elif f[j] == 1:
				m[j] -= 1
		s = abs(m[0] - m[1]) + abs(m[0] - m[2]) + abs(m[1] - m[2])
		if s < p:
			p = s
		f[0] += 1
		for j in range(3):
			if f[j] > 2:
				f[j] = 0
				f[j + 1] += 1
			else:
				break
	print(p)


def p(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for i in range(int(input())):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	print(min(p(a, b, c), p(a, b, c - 1), p(a, b, c + 1), p(a, b - 1, c), p(a, b + 1, c), p(a + 1, b, c), p(a - 1, b, c), p(a, b + 1, c + 1), p(a, b + 1, c - 1), p(a, b - 1, c + 1), p(a, b - 1, c - 1), p(a + 1, b, c + 1), p(a + 1, b, c - 1), p(a - 1, b, c + 1), p(a - 1, b, c - 1), p(a + 1, b + 1, c), p(a + 1, b - 1, c), p(a - 1, b + 1, c), p(a - 1, b - 1, c), p(a + 1, b + 1, c + 1), p(a - 1, b - 1, c - 1), p(a + 1, b - 1, c - 1), p(a + 1, b + 1, c - 1), p(a + 1, b - 1, c + 1), p(a - 1, b - 1, c + 1), p(a - 1, b + 1, c + 1), p(a - 1, b + 1, c - 1)))


N = int(input())
for i in range(N):
	a = list(map(int, input().split()))
	a.sort()
	ans = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0])
	if a[0] == a[1] and a[1] == a[2]:
		t = 0
	else:
		t = 4
	print(max(0, ans - t))


def solve(a, b, c):
	m2 = abs(a - b) + abs(b - c) + abs(a - c)
	return m2
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = abs(a - b) + abs(b - c) + abs(a - c)
	l1 = [a - 1, a, a + 1]
	l2 = [b - 1, b, b + 1]
	l3 = [c - 1, c, c + 1]
	for i in l1:
		for j in l2:
			for k in l3:
				m = min(m, solve(i, j, k))
	print(m)


for _ in range(int(input())):
	arr = [int(x) for x in input().split(' ')]
	arr.sort()
	ans = 0
	if arr[0] == arr[1] and arr[1] == arr[2]:
		ans = 0
	elif arr[0] == arr[1]:
		ans = max(0, 2 * (arr[2] - 1 - arr[1] - 1))
	elif arr[1] == arr[2]:
		ans = max(0, 2 * (arr[1] - 1 - arr[0] - 1))
	else:
		ans = max(0, arr[1] - arr[0] - 1 + arr[2] - 1 - arr[1] + arr[2] - 1 - arr[0] - 1)
	print(ans)


n = int(input())
for i in range(n):
	k = list(map(int, input().strip().split()))
	k.sort()
	ans = 0
	a = k[0]
	b = k[1]
	c = k[2]
	if b - a < 2 and c - b < 2:
		print(0)
		continue
	a = a + 1
	c = c - 1
	print((c - a) * 2)


import sys
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict, deque
from math import log2, ceil, floor
inp = lambda : int(input())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
Judge = 0
if Judge:
	sys.stdin = open('input.in', 'r')
for _ in range(inp()):
	(a, b, c) = mulip()
	s = abs(a - b) + abs(b - c) + abs(c - a)
	print(max(0, s - 4))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a1, a2, a3) = (a, a - 1, a + 1)
	(b1, b2, b3) = (b, b - 1, b + 1)
	(c1, c2, c3) = (c, c - 1, c + 1)
	(t1, t2, t3) = (abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1), abs(a1 - b1) + abs(a1 - c2) + abs(b1 - c2), abs(a1 - b1) + abs(a1 - c3) + abs(b1 - c3))
	(t4, t5, t6) = (abs(a1 - b2) + abs(a1 - c1) + abs(b2 - c1), abs(a1 - b2) + abs(a1 - c2) + abs(b2 - c2), abs(a1 - b2) + abs(a1 - c3) + abs(b2 - c3))
	(t7, t8, t9) = (abs(a1 - b3) + abs(a1 - c1) + abs(b3 - c1), abs(a1 - b3) + abs(a1 - c2) + abs(b3 - c2), abs(a1 - b3) + abs(a1 - c3) + abs(b3 - c3))
	(t10, t11, t12) = (abs(a2 - b1) + abs(a2 - c1) + abs(b1 - c1), abs(a2 - b1) + abs(a2 - c2) + abs(b1 - c2), abs(a2 - b1) + abs(a2 - c3) + abs(b1 - c3))
	(t13, t14, t15) = (abs(a2 - b2) + abs(a2 - c1) + abs(b2 - c1), abs(a2 - b2) + abs(a2 - c2) + abs(b2 - c2), abs(a2 - b2) + abs(a2 - c3) + abs(b2 - c3))
	(t16, t17, t18) = (abs(a2 - b3) + abs(a2 - c1) + abs(b3 - c1), abs(a2 - b3) + abs(a2 - c2) + abs(b3 - c2), abs(a2 - b3) + abs(a2 - c3) + abs(b3 - c3))
	(t19, t20, t21) = (abs(a3 - b1) + abs(a3 - c1) + abs(b1 - c1), abs(a3 - b1) + abs(a3 - c2) + abs(b1 - c2), abs(a3 - b1) + abs(a3 - c3) + abs(b1 - c3))
	(t22, t23, t24) = (abs(a3 - b2) + abs(a3 - c1) + abs(b2 - c1), abs(a3 - b2) + abs(a3 - c2) + abs(b2 - c2), abs(a3 - b2) + abs(a3 - c3) + abs(b2 - c3))
	(t25, t26, t27) = (abs(a3 - b3) + abs(a3 - c1) + abs(b3 - c1), abs(a3 - b3) + abs(a3 - c2) + abs(b3 - c2), abs(a3 - b3) + abs(a3 - c3) + abs(b3 - c3))
	print(min(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27))


from math import ceil, log, floor, sqrt
import math
k = 1

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_prime(n):
	m = 2
	while m * m <= n:
		if n % m == 0:
			return False
		m += 1
	return True

def find_sum(n, a):
	a.insert(0, 0)
	for i in range(1, n + 1):
		prev = a[i] & a[i - 1]
		cur = a[i] | a[i - 1]
		a[i - 1] = prev
		a[i] = cur
	return sum((m * m for m in a))

def prin_abc(x, y, z):
	l = [x, y, z]
	l.sort()
	if l[1] < l[2]:
		print('NO')
		return
	a = b = l[0]
	c = l[2]
	print('YES')
	print(a, b, c)

def get_scores(n, vals):
	l = 0
	r = n - 1
	turn = 0
	sereja = 0
	dima = 0
	while l <= r:
		if vals[l] > vals[r]:
			cur = vals[l]
			l += 1
		else:
			cur = vals[r]
			r -= 1
		if turn == 0:
			sereja += cur
		else:
			dima += cur
		turn = not turn
	print(sereja, dima)

def count_lamps(n, m):
	return (n * m + 1) // 2

def find_holidays(n):
	cnt = 2 * (n // 7)
	rem = n % 7
	mx = mn = cnt
	if rem == 1:
		mx += 1
	elif rem > 1:
		mx += 2
	if rem == 6:
		mn += 1
	print(mn, mx)

def get_mn(a, b, c):
	val = [a, b, c]
	val.sort()
	if val[0] < val[2]:
		val[0] += 1
	if val[2] > val[0]:
		val[2] -= 1
	if val[1] < val[0]:
		val[1] += 1
	elif val[1] > val[2]:
		val[1] -= 1
	return abs(val[1] - val[0]) + abs(val[2] - val[1]) + abs(val[0] - val[2])
t = 1
t = int(input())
while t:
	t = t - 1
	(k, g) = (0, 0)
	points = []
	(a, b, c) = map(int, input().split())
	print(get_mn(a, b, c))


import sys

def main():
	for tc in range(int(input())):
		(a, b, c) = get_ints()
		A = [a - 1, a, a + 1]
		B = [b - 1, b, b + 1]
		C = [c - 1, c, c + 1]
		ans = 10 ** 18
		for i in range(3):
			for j in range(3):
				for k in range(3):
					ans = min(ans, abs(A[i] - B[j]) + abs(A[i] - C[k]) + abs(B[j] - C[k]))
		print(ans)
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : list(map(int, sys.stdin.readline().split()))
input = lambda : sys.stdin.readline().strip()

def __starting_point():
	main()
__starting_point()


t = int(input())
while t > 0:
	l = list(map(int, input().split()))
	l.sort()
	res = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	if res <= 3:
		print('0')
	else:
		print(abs(l[0] + 1 - l[1] - 1) + abs(l[1] - 1 - l[2] - 1) + abs(l[2] - 1 - l[0] + 1) - 6)
	t -= 1


q = int(input().strip())
for _ in range(q):
	nums = [int(i) for i in input().strip().split()]
	nums.sort()
	pos = [1, -1, 0]
	(a, b, c) = nums
	m = 10000000100
	for i in pos:
		for j in pos:
			for k in pos:
				cur = abs(a + i - (b + j)) + abs(a + i - (c + k)) + abs(b + j - (c + k))
				m = min(cur, m)
	print(m)


tc = int(input())
for _ in range(tc):
	(a, b, c) = list(map(int, input().split()))
	ans = 100000000000
	for i in [1, -1, 0]:
		aa = a + i
		for j in [0, 1, -1]:
			bb = b + j
			for k in [-1, 1, 0]:
				cc = c + k
				ans = min(abs(aa - bb) + abs(aa - cc) + abs(bb - cc), ans)
	print(ans)


a = int(input())
for i in range(a):
	(b, c, d) = sorted(list(map(int, input().split())))
	if c == d and c != b:
		c -= 1
	if c == b and c != d:
		c += 1
	if b < c:
		b += 1
	if d > c:
		d -= 1
	print(abs(d - c) + abs(c - b) + abs(d - b))


for i in range(int(input())):
	a = [int(s) for s in input().split()]
	a.sort()
	if a[0] < a[2]:
		a[0] += 1
	if a[2] > a[0]:
		a[2] -= 1
	if a[1] < a[2]:
		a[1] += 1
	elif a[1] != a[0]:
		a[1] -= 1
	print(a[1] - a[0] + a[2] - a[0] + a[2] - a[1])


def re(n, c):
	if c - n == 0:
		return 0
	if c - n > 0:
		return 1
	if n - c > 0:
		return -1
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mi = min(a, b, c)
	mx = max(a, b, c)
	cn = (mi + mx) // 2
	a += re(a, cn)
	b += re(b, cn)
	c += re(c, cn)
	print(abs(a - b) + abs(b - c) + abs(a - c))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	d = abs(a - b) + abs(b - c) + abs(a - c)
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				na = a + i
				nb = b + j
				nc = c + k
				d = min(d, abs(na - nb) + abs(na - nc) + abs(nb - nc))
	print(d)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1] and l[1] == l[2]:
		print(0)
	elif abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2]) < 4:
		print(0)
	else:
		print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2]) - 4)


import math
q = int(input())

def len_equal(array):
	if len(set(array)) == 1:
		return True
	return False

def calc(array):
	return math.fabs(array[0] - array[1]) + math.fabs(array[1] - array[2]) + math.fabs(array[0] - array[2])
for x in range(q):
	array = list(map(int, input().split()))
	array.sort()
	if len_equal(array) == True:
		print(0)
		continue
	output = [calc(array)]
	if array[0] == array[1]:
		array[0] += 1
		array[1] += 1
		output.append(calc(array))
	if array[2] == array[1]:
		array[1] -= 1
		array[2] -= 1
		output.append(calc(array))
	if array[0] != array[1]:
		array[0] += 1
		output.append(calc(array))
	if array[2] != array[1]:
		array[2] -= 1
		output.append(calc(array))
	print(int(min(output)))


import math
for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	k = (a + b + c) / 3
	k_c = math.ceil(k)
	k_f = math.floor(k)
	if k - k_f < 0.5:
		k = k_f
	else:
		k = k_c
	if a > k:
		a -= 1
	elif a < k:
		a += 1
	if b > k:
		b -= 1
	elif b < k:
		b += 1
	if c > k:
		c -= 1
	elif c < k:
		c += 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


from sys import stdin
for _ in range(int(stdin.readline())):
	l = sorted([int(x) for x in stdin.readline().split()])
	flag1 = l[0] == l[1]
	flag2 = l[1] == l[2]
	if flag1 and (not flag2):
		l[1] += 1
	if not flag1 and flag2:
		l[1] -= 1
	if l[1] - l[0] > 0:
		l[0] += 1
	if l[2] - l[1] > 0:
		l[2] -= 1
	print(abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0]))


q = int(input().strip())
for a0 in range(q):
	(a, b, c) = map(int, input().strip().split(' '))
	arr = [a, b, c]
	arr.sort()
	x = 2 * (arr[2] - arr[0] - 2)
	if x <= 0:
		print('0')
	else:
		print(x)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	arr = [a, b, c]
	arr.sort()
	a = arr[0]
	b = arr[1]
	c = arr[2]
	if a == b and b == c or (a == b and abs(b - c) == 1) or (a == c and abs(b - c) == 1) or (b == c and abs(a - c) == 1):
		print(0)
	elif a == b and abs(b - c) != 1:
		print(abs(a - c + 2) + abs(b - c + 2))
	elif a == c and abs(b - c) != 1:
		print(abs(a - b + 2) + abs(b - c + 2))
	elif b == c and abs(a - c) != 1:
		print(abs(a + 1 - (b - 1)) + abs(a + 1 - (c - 1)))
	else:
		print(abs(a + 1 - (c - 1)) + abs(a + 1 - b) + abs(c - 1 - b))


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	ans = 10 ** 19
	(a, b, c) = [int(x) for x in inp().split()]
	for i in range(-1, 2):
		a1 = a + i
		for j in range(-1, 2):
			b1 = b + j
			for k in range(-1, 2):
				c1 = c + k
				ans = min(ans, abs(a1 - b1) + abs(b1 - c1) + abs(a1 - c1))
	print(ans)


q = int(input())
for i in range(q):
	A = list(map(int, input().split()))
	A.sort()
	if A[0] < A[1]:
		A[0] += 1
	elif A[1] < A[2]:
		A[0] += 1
		A[1] += 1
	if A[2] > A[1]:
		A[2] -= 1
	elif A[1] > A[0]:
		A[1] -= 1
		A[2] -= 1
	print(A[2] - A[1] + A[2] - A[0] + A[1] - A[0])


for x in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] and a[2] == a[0]:
		print(0)
	elif a[0] + 1 == a[1] and a[1] + 1 == a[2]:
		print(0)
	elif a[0] == a[1] and a[0] + 1 == a[2]:
		print(0)
	elif a[1] == a[2] and a[0] + 1 == a[1]:
		print(0)
	else:
		a[0] = a[0] + 1
		a[2] = a[2] - 1
		s = a[1] - a[0] + (a[2] - a[0]) + (a[2] - a[1])
		print(s)


for _ in range(int(input())):
	li = list(map(int, input().split()))
	li.sort()
	m = li[2] - li[0]
	if m > 1:
		print(2 * (m - 2))
	else:
		print(0)


t = int(input())
for io in range(t):
	l = [int(x) for x in input().split()]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if 2 * (l[2] - l[0] - 2) > 0:
		print(2 * (l[2] - l[0]) - 4)
	else:
		print('0')


def min_sum_diff(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	ans = min_sum_diff(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				na = i + a
				nb = j + b
				nc = k + c
				ans = min(ans, min_sum_diff(na, nb, nc))
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	a = [a, b, c]
	a.sort()
	if a[2] - a[0] == 0:
		el = 0
	elif a[2] - a[0] == 1:
		el = 1
	else:
		el = 2
	print(2 * (a[2] - a[0] - el))


def dist(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for qq in range(q):
	(a, b, c) = [int(x) for x in input().split()]
	s = 100000000000.0
	for i in [-1, 0, 1]:
		for j in [-1, 0, 1]:
			for k in [-1, 0, 1]:
				s = min(s, dist(a + i, b + j, c + k))
	print(s)


def li():
	return list(map(int, input().split()))

def ii():
	return int(input())
t = ii()
while t:
	t -= 1
	a = li()
	a.sort()
	if a[0] == a[1] and a[1] != a[2]:
		a[0] += 1
		a[1] += 1
		if a[1] != a[2]:
			a[2] -= 1
	elif a[0] != a[1] and a[1] == a[2]:
		a[1] -= 1
		a[2] -= 1
		if a[0] != a[1]:
			a[0] += 1
	elif a[0] != a[1] and a[1] != a[2]:
		a[0] += 1
		a[2] -= 1
	s = a[1] - a[0]
	s += a[2] - a[1]
	s += a[2] - a[0]
	print(s)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mn = int(1e+18)
	arr = [0, -1, 1]
	for i in range(3):
		aa = a + arr[i]
		for j in range(3):
			bb = b + arr[j]
			for k in range(3):
				cc = c + arr[k]
				mn = min(mn, abs(aa - bb) + abs(aa - cc) + abs(bb - cc))
	print(mn)


try:
	t = int(input())
	for _ in range(t):
		(a, b, c) = map(int, input().split(' '))
		if a == b and c == a and (b == c):
			print(0)
		else:
			if a < b and a > c:
				b -= 1
				c += 1
			elif a < c and a > b:
				c -= 1
				b += 1
			elif b < a and b > c:
				a -= 1
				c += 1
			elif b < c and b > a:
				c -= 1
				a += 1
			elif c < a and c > b:
				a -= 1
				b += 1
			elif c < b and c > a:
				b -= 1
				a += 1
			elif a == b:
				if c == a + 1 or c == a - 1:
					c = a
				elif c > a + 1:
					a += 1
					b += 1
					c -= 1
				elif c < a + 1:
					a -= 1
					b -= 1
					c += 1
			elif c == b:
				if a == c - 1 or a == c + 1:
					a = c
				elif a > b + 1:
					b += 1
					c += 1
					a -= 1
				elif a < b + 1:
					b -= 1
					c -= 1
					a += 1
			elif a == c:
				if b == a - 1 or b == a + 1:
					b = c
				elif b > a + 1:
					a += 1
					c += 1
					b -= 1
				elif b < a + 1:
					a -= 1
					c -= 1
					b += 1
			x = abs(a - b) + abs(b - c) + abs(c - a)
			print(x)
except:
	pass


def main():
	t = int(input())
	for i in range(t):
		x = [int(x) for x in input().split()]
		x.sort()
		a = x[0]
		b = x[2]
		if b - a >= 2:
			b -= 2
		elif b - a == 1:
			b -= 1
		print(2 * (b - a))
main()


from math import inf

def solve(a, b, c):
	mini = inf
	for ia in [-1, 0, 1]:
		for ib in [-1, 0, 1]:
			for ic in [-1, 0, 1]:
				kb = b + ib
				ka = a + ia
				kc = c + ic
				mini = min(mini, abs(kc - ka) + abs(kc - kb) + abs(kb - ka))
	return max(0, mini)

def main():
	for _ in range(int(input())):
		(a, b, c) = list(map(int, input().split()))
		print(solve(a, b, c))
main()


def f(r, g, b):
	x = [r, g, b]
	x.sort()
	if x[0] == x[2] or x[0] + 1 == x[2]:
		if x[0] == x[2] or x[0] + 1 == x[2]:
			print(0)
		else:
			print(x[2] - 1 - (x[0] + 1) + x[2] - 1 - (x[1] + 1))
	elif x[0] + 1 == x[2]:
		print(0)
	elif x[0] + 2 == x[2]:
		print(0)
	else:
		print(x[2] - 1 - (x[1] - 1) + (x[2] - 1 - (x[0] + 1)) + (x[1] - 1 - (x[0] + 1)))
n = int(input())
for i in range(n):
	(r, g, b) = list(map(int, input().split()))
	f(r, g, b)


import sys
input = sys.stdin.readline
q = int(input())
for test in range(q):
	(a, b, c) = map(int, input().split())
	ANS = 1 << 60
	for x in range(a - 1, a + 2):
		for y in range(b - 1, b + 2):
			for z in range(c - 1, c + 2):
				ANS = min(abs(x - y) + abs(y - z) + abs(z - x), ANS)
	print(ANS)


t = int(input())
for _ in range(t):
	arr = [int(j) for j in input().split()]
	arr.sort()
	(a, b, c) = (arr[0], arr[1], arr[2])
	if a == b == c:
		print(0)
	elif a == b and b != c:
		c -= 1
		if a == b == c:
			print(0)
		else:
			a += 1
			b += 1
			print(c - b + c - a)
	elif a != b and b == c:
		a += 1
		if a == b == c:
			print(0)
		else:
			b -= 1
			c -= 1
			print(c - a + b - a)
	else:
		a += 1
		c -= 1
		bb = c - a + c - b + b - a
		a -= 1
		c += 1
		a += 1
		b += 1
		cc = c - a + c - b + b - a
		a -= 1
		b -= 1
		b -= 1
		c -= 1
		aa = c - a + c - b + b - a
		print(min(aa, bb, cc))


q = int(input())
while q:
	(a, b, c) = list(map(int, input().split(' ')))
	d = abs(a - b) + abs(b - c) + abs(c - a)
	if a == b and b == c:
		print(0)
	elif b == c or a == b or a == c:
		if d >= 4:
			print(d - 4)
		elif d == 2:
			print(0)
	elif d >= 4:
		print(d - 4)
	else:
		print(d)
	q = q - 1


t = int(input())
for tt in range(t):
	(a, b, c) = map(int, input().split())
	ans = 1e+18
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				total = abs(a + i - (b + j)) + abs(a + i - (c + k)) + abs(b + j - (c + k))
				ans = min(ans, total)
	print(ans)


from itertools import combinations_with_replacement
import sys
input = sys.stdin.buffer.readline

def mindist(a, b, c):
	x = a - b
	y = b - c
	z = a - c
	return abs(x) + abs(y) + abs(z)
from collections import deque
q = int(input())
for _ in range(q):
	mmmin = 10 ** 10
	x = list(map(int, input().split()))
	s = combinations_with_replacement([-1, 0, 1], 3)
	for i in [0, 1, -1]:
		for j in [0, 1, -1]:
			for k in [0, 1, -1]:
				if mindist(x[0] + i, x[1] + j, x[2] + k) < mmmin:
					mmmin = mindist(x[0] + i, x[1] + j, x[2] + k)
	print(mmmin)


q = int(input())
for r in range(q):
	(a, b, c) = map(int, input().split())
	ans = 1e+18
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for z in range(-1, 2, 1):
				total = abs(a + i - (b + j)) + abs(a + i - (c + z)) + abs(b + j - (c + z))
				ans = min(ans, total)
	print(ans)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	(r, b, g) = map(int, input().strip().split())
	arr = [r, b, g]
	arr = sorted(arr)
	diff = 2 * (arr[2] - arr[0])
	print(max(0, diff - 4))


t = int(input())
ans = []
for i in range(0, t):
	temp = []
	temp = list(map(int, input().split()))
	temp.sort()
	a = temp[2]
	b = temp[1]
	c = temp[0]
	if a - c == 0:
		ans.append(0)
	elif a - c == 1:
		ans.append(0)
	elif a - c == 2:
		ans.append(0)
	else:
		a = a - 1
		c = c + 1
		ans.append(2 * (a - c))
for k in range(0, t):
	print(ans[k])


def solve(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for _ in range(int(input())):
	x = []
	(a, b, c) = list(map(int, input().split()))
	mi = 100000000000
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = a + i
				y = b + j
				z = c + k
				mi = min(mi, solve(x, y, z))
	print(mi)


n = int(input())
for i in range(n):
	lst = list(map(int, input().split()))
	lst.sort()
	a = lst[0]
	b = lst[1]
	c = lst[2]
	if c - a <= 2:
		print(0)
	else:
		anwser = (c - a - 2) * 2
		print(anwser)


t = int(input())
for i in range(t):
	(a, b, c) = sorted(map(int, input().split()))
	print(max(0, abs(a - b) + abs(b - c) + abs(a - c) - 4))


T = int(input())
for t in range(T):
	lst = list(map(int, input().split()))
	lst.sort()
	temp = 2 * (lst[2] - lst[0]) - 4
	if temp >= 0:
		print(temp)
	else:
		print(0)


q = int(input())
for i in range(q):
	lista = list(map(int, input().split(' ')))
	if lista.count(lista[0]) == 3:
		print('0')
		continue
	listaAux = lista.copy()
	listaAux = sorted(listaAux)
	if listaAux[0] != listaAux[1]:
		lista[lista.index(listaAux[0])] += 1
		listaAux[0] += 1
		if lista.count(lista[0]) != 3:
			if listaAux[1] != listaAux[2]:
				lista[lista.index(listaAux[2])] -= 1
				listaAux[2] -= 1
			else:
				for j in range(3):
					if lista[j] == listaAux[2]:
						lista[j] -= 1
	else:
		for j in range(3):
			if lista[j] == listaAux[0]:
				lista[j] += 1
		listaAux[0] += 1
		listaAux[1] += 1
		if listaAux[1] != listaAux[2]:
			lista[lista.index(listaAux[2])] -= 1
	soma = abs(lista[0] - lista[1]) + abs(lista[0] - lista[2]) + abs(lista[1] - lista[2])
	print(soma)


import sys
q = int(sys.stdin.readline())
for t in range(q):
	(a, b, c) = sorted(list(map(int, sys.stdin.readline().split())))
	if a + 1 < c:
		if a + 1 < b:
			if b < c:
				a += 1
				c -= 1
			else:
				a += 1
				b -= 1
				c -= 1
		elif a < b:
			a += 1
			c -= 1
		else:
			a += 1
			b += 1
			c -= 1
	elif a < c:
		if a == b:
			c -= 1
		else:
			a += 1
	print(2 * c - 2 * a)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
tt = int(input())
for y in range(tt):
	(a, b, c) = map(int, input().split())
	m1 = max(a, b, c)
	m2 = min(a, b, c)
	if m1 == m2:
		print(0)
	else:
		if a == m1:
			a -= 1
		if b == m1:
			b -= 1
		if c == m1:
			c -= 1
		m1 -= 1
		if m1 == m2:
			print(0)
		else:
			if a == m2:
				a += 1
			if b == m2:
				b += 1
			if c == m2:
				c += 1
			print(abs(a - b) + abs(b - c) + abs(a - c))


q = int(input())
for I in range(q):
	a = [int(i) for i in input().split()]
	arr = []
	for i in range(3):
		arr.append([a[i] - 1, a[i], a[i] + 1])
	mini = 10 ** 18
	for i in range(3):
		for j in range(3):
			for k in range(3):
				x = arr[0][i]
				y = arr[1][j]
				z = arr[2][k]
				mini = min(mini, abs(x - y) + abs(y - z) + abs(z - x))
	print(mini)


T = int(input())
for i in range(T):
	lst = list(map(int, input().split()))[:3]
	lst.sort()
	summ = sum(lst)
	avg = summ // 3
	newlst = []
	if lst[0] == lst[1] and lst[2] - lst[0] == 2:
		print('0')
	else:
		for j in range(3):
			if avg == lst[j]:
				newlst.append(avg)
			elif avg > lst[j]:
				newlst.append(lst[j] + 1)
			else:
				newlst.append(lst[j] - 1)
		x1 = newlst[1] - newlst[0]
		x2 = newlst[2] - newlst[1]
		x3 = newlst[2] - newlst[0]
		print(x1 + x2 + x3)


x = [0, -1, 1]
for i in range(int(input())):
	bb = []
	(a, b, c) = map(int, input().split())
	for j in range(3):
		for k in range(3):
			for l in range(3):
				z = abs(a + x[j] - b - x[k]) + abs(b + x[k] - c - x[l]) + abs(a + x[j] - c - x[l])
				bb.append(z)
	print(min(bb))


import os
import sys
import bisect
from math import gcd, ceil
from heapq import heapify, heappop, heappush
from io import BytesIO, IOBase
import itertools

def ans(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def main():
	for _ in range(int(input())):
		(a, b, c) = map(int, input().split())
		normal = [a, a - 1, a + 1]
		minus = [b, b - 1, b + 1]
		plus = [c, c - 1, c + 1]
		m = float('inf')
		for x in normal:
			for y in minus:
				for z in plus:
					m = min(m, ans(x, y, z))
		print(m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


def cal(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	(a, b, c) = [i for i in map(int, input().split())]
	ans = cal(a, b, c)
	for a0 in range(-1, 2):
		for a1 in range(-1, 2):
			for a2 in range(-1, 2):
				ans = min(ans, cal(a + a0, b + a1, c + a2))
	print(ans)


t = int(input())
for _ in range(t):
	(xx, yy, zz) = map(int, input().split())
	z = max(xx, yy, zz)
	x = min(xx, yy, zz)
	y = xx + yy + zz - x - z
	if x == y == z:
		print(0)
	elif x == y:
		print(max(0, 2 * abs(x - z) - 4))
	elif x == z:
		print(max(0, 2 * abs(x - y) - 4))
	elif y == z:
		print(max(0, 2 * abs(x - y) - 4))
	else:
		print(abs(x - z) + abs(x - y) + abs(y - z) - 4)


import math
import random

def type1():
	return map(int, input().split())

def type2():
	return list(type1())

def type3():
	return int(input())
for _ in range(type3()):
	(a, b, c) = sorted(type1())
	if b != a:
		a += 1
	elif a + 1 <= c:
		a += 1
		b += 1
	if b != c:
		c -= 1
	elif c - 1 >= a:
		c -= 1
		b -= 1
	if c != b:
		b += 1
	elif a != b:
		b -= 1
	print(abs(a - b) + abs(b - c) + abs(a - c))


def distance(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
tc = int(input())
moves = [-1, 0, 1]
for i in range(tc):
	(a, b, c) = [int(x) for x in input().split()]
	delta = -1
	for xa in moves:
		for xb in moves:
			for xc in moves:
				if delta == -1:
					delta = distance(a + xa, b + xb, c + xc)
				else:
					delta = min(delta, distance(a + xa, b + xb, c + xc))
	print(delta)


q = int(input())
while q:
	(a, b, c) = map(int, input().split())
	if a == b == c:
		print(int('0'))
	else:
		l = [a, b, c]
		l.sort()
		x = l[1] - l[0]
		y = l[2] - l[1]
		z = l[2] - l[0]
		if x < y:
			if l[1] - l[0] == 1 or l[1] - l[0] == 0:
				if l[1] - l[0] == 1 or (l[1] - l[0] == 0 and l[2] - l[1] == 1):
					m = 2 * (y - 1)
				else:
					m = 2 * (y - 2)
			else:
				m = x - 2 + y + z - 2
		if x > y:
			if l[2] - l[1] == 1 or l[2] - l[1] == 0:
				if l[2] - l[1] == 1 or (l[2] - l[1] == 0 and l[1] - l[0] == 1):
					m = 2 * (x - 1)
				else:
					m = 2 * (x - 2)
			else:
				m = y - 2 + x + z - 2
		if x == y:
			if x == y == 1:
				m = 0
			else:
				m = x - 1 + y - 1 + z - 2
		print(m)
	q = q - 1


def pair_dist(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
q = int(input())
for k in range(q):
	(a, b, c) = map(int, input().split())
	min_ans = 1000000000000
	for i in range(-1, 2):
		for j in range(-1, 2):
			for z in range(-1, 2):
				min_ans = min(min_ans, pair_dist(a + i, b + j, c + z))
	print(min_ans)


for i in range(int(input())):
	x = [int(i) for i in input().split()]
	x.sort()
	if max(x) - min(x) < 3:
		print(0)
	else:
		print((max(x) - min(x) - 2) * 2)


q = int(input())
for i in range(0, q):
	(a, b, c) = map(int, input().split())
	ans = 1e+18
	for i1 in range(-1, 2):
		for i2 in range(-1, 2):
			for i3 in range(-1, 2):
				a1 = a + i1
				b1 = b + i2
				c1 = c + i3
				if abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1) < ans:
					ans = abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1)
	print(str(ans))


t = int(input())
for _ in range(t):
	li = list(map(int, input().split()))
	li.sort()
	z = 1
	for i in range(len(li)):
		if i < z:
			if li[2] > li[i]:
				li[i] = li[i] + 1
		elif i > z:
			if li[0] < li[i]:
				li[i] = li[i] - 1
	if li[1] - 1 == li[0] or li[1] - 1 == li[2]:
		li[1] = li[1] - 1
	elif li[1] + 1 == li[2] or li[1] + 1 == li[0]:
		li[1] = li[1] + 1
	print(abs(li[0] - li[1]) + abs(li[1] - li[2]) + abs(li[2] - li[0]))


n = int(input())
for i in range(n):
	inp = list(map(int, input().split()))
	mn = abs(inp[0] - inp[1]) + abs(inp[0] - inp[2]) + abs(inp[1] - inp[2])
	for i in range(3):
		for g in range(3):
			for k in range(3):
				bfinp = [inp[0] + i - 1, inp[1] + g - 1, inp[2] + k - 1]
				mn = min(abs(bfinp[0] - bfinp[1]) + abs(bfinp[0] - bfinp[2]) + abs(bfinp[1] - bfinp[2]), mn)
	print(mn)


for i in range(int(input())):
	x = list(sorted(map(int, input().split())))
	tmp = x[2] - x[1] + (x[1] - x[0]) + (x[2] - x[0])
	if len(set(x)) == 1:
		print(0)
	elif len(set(x)) == 2:
		if tmp >= 4:
			print(tmp - 4)
		else:
			print(tmp - 2)
	else:
		print(tmp - 4)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	a -= 1
	b -= 1
	c -= 1
	minr = float('inf')
	for i in range(3):
		for j in range(3):
			for h in range(3):
				(na, nb, nc) = (a + i, b + j, c + h)
				nminr = abs(na - nb) + abs(nb - nc) + abs(na - nc)
				if nminr < minr:
					minr = nminr
	print(minr)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	m = round((a + b + c) / 3)
	if m > a:
		a += 1
	elif m < a:
		a -= 1
	if m > b:
		b += 1
	elif m < b:
		b -= 1
	if m > c:
		c += 1
	elif m < c:
		c -= 1
	print(abs(a - b) + abs(b - c) + abs(a - c))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split(' '))
	l = [a, b, c]
	l.sort()
	dist = abs(a - b) + abs(a - c) + abs(b - c)
	if l[1] - l[0] >= 2:
		l[0] += 1
		l[1] -= 1
		if l[2] - l[1] > 0:
			l[2] -= 1
	elif l[0] != l[1]:
		l[0] += 1
		if l[2] != l[1]:
			l[2] -= 1
	elif l[2] - l[1] >= 2:
		l[2] -= 1
		l[1] += 1
		l[0] += 1
	elif l[1] != l[2]:
		l[2] -= 1
	dist = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
	l.sort()
	print(dist)


for case in range(int(input())):
	d = list(map(int, input().split()))
	d = sorted(d)
	diff = 0 if d[2] - d[0] < 2 else d[2] - d[0] - 2
	print(diff * 2)


def main():
	for _ in range(int(input())):
		a = list(map(int, input().split()))
		a.sort()
		if set(a).__len__() == 1:
			print(0)
		elif set(a).__len__() == 2:
			t = list(set(a))
			t.sort()
			print(2 * (t[1] - t[0] - 2) if 2 * (t[1] - t[0] - 2) >= 0 else 0)
		else:
			print(a[2] - a[0] + a[1] - a[0] + a[2] - a[1] - 4)
main()


def compute(a, b, c):
	d = abs(a - b) + abs(b - c) + abs(c - a)
	return d

def gather(a, b, c):
	if a == b and b == c:
		return 0
	pair1 = compute(a, b, c)
	pair2 = compute(a - 1, b, c)
	pair3 = compute(a, b - 1, c)
	pair4 = compute(a, b, c - 1)
	pair5 = compute(a - 1, b - 1, c)
	pair6 = compute(a, b - 1, c - 1)
	pair7 = compute(a - 1, b, c - 1)
	pair8 = compute(a - 1, b - 1, c - 1)
	pair9 = compute(a + 1, b, c)
	pair10 = compute(a, b + 1, c)
	pair11 = compute(a, b, c + 1)
	pair12 = compute(a + 1, b + 1, c)
	pair13 = compute(a, b + 1, c + 1)
	pair14 = compute(a + 1, b, c + 1)
	pair15 = compute(a + 1, b + 1, c + 1)
	pair16 = compute(a + 1, b, c - 1)
	pair17 = compute(a + 1, b - 1, c)
	pair18 = compute(a + 1, b - 1, c - 1)
	pair19 = compute(a, b + 1, c - 1)
	pair20 = compute(a - 1, b + 1, c)
	pair21 = compute(a - 1, b + 1, c - 1)
	pair22 = compute(a, b - 1, c + 1)
	pair23 = compute(a - 1, b, c + 1)
	pair24 = compute(a - 1, b - 1, c + 1)
	pair25 = compute(a + 1, b + 1, c - 1)
	pair26 = compute(a + 1, b - 1, c + 1)
	pair27 = compute(a - 1, b + 1, c + 1)
	ans = min(pair1, pair2, pair3, pair4, pair5, pair6, pair7, pair8, pair9, pair10, pair11, pair12, pair13, pair14, pair15, pair16, pair17, pair18, pair19, pair20, pair21, pair22, pair23, pair24, pair25, pair26, pair27)
	return ans
t = int(input())
for _ in range(t):
	ar = list(map(int, input().split()))
	result = gather(ar[0], ar[1], ar[2])
	print(result)


def main():

	def solve():
		aa = [int(a) for a in input().split()]
		aa.sort()
		result = max(2 * (aa[2] - aa[0]) - 4, 0)
		print(result)
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
for i in range(t):
	n = input()
	l = list(map(int, n.split(' ')))
	p = min(l)
	l.sort()
	m = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	for i in range(len(l)):
		if l.count(l[0]) == 3:
			m = 0
			break
		elif l[i] == p:
			l[i] = l[i] + 1
		else:
			l[i] = l[i] - 1
			if abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0]) < m:
				m = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
			else:
				l[i] = l[i] + 1
				m = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	print(m)


from collections import defaultdict
for i in range(int(input())):
	x = sorted(list(map(int, input().split())))
	MySet = list(sorted(set(x)))
	if len(MySet) == 1:
		print(0)
		continue
	if len(MySet) == 2:
		if MySet[1] - MySet[0] == 1:
			print(0)
			continue
		else:
			print(2 * (MySet[1] - MySet[0]) - 4)
			continue
	else:
		x[0] += 1
		x[2] -= 1
		print(abs(x[0] - x[1]) + abs(x[0] - x[2]) + abs(x[1] - x[2]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = 0
	a1 = a + 1
	a2 = a - 1
	b1 = b + 1
	b2 = b - 1
	c1 = c + 1
	c2 = c - 1
	r = abs(a - b) + abs(b - c) + abs(c - a)
	m = r
	r = abs(a - b) + abs(b - c1) + abs(c1 - a)
	if r < m:
		m = r
	r = abs(a - b) + abs(b - c2) + abs(c2 - a)
	if r < m:
		m = r
	r = abs(a - b1) + abs(b1 - c) + abs(c - a)
	if r < m:
		m = r
	r = abs(a - b1) + abs(b1 - c1) + abs(c1 - a)
	if r < m:
		m = r
	r = abs(a - b1) + abs(b1 - c2) + abs(c2 - a)
	if r < m:
		m = r
	r = abs(a - b2) + abs(b2 - c) + abs(c - a)
	if r < m:
		m = r
	r = abs(a - b2) + abs(b2 - c1) + abs(c1 - a)
	if r < m:
		m = r
	r = abs(a - b2) + abs(b2 - c2) + abs(c2 - a)
	if r < m:
		m = r
	r = abs(a1 - b) + abs(b - c) + abs(c - a1)
	if r < m:
		m = r
	r = abs(a1 - b) + abs(b - c1) + abs(c1 - a1)
	if r < m:
		m = r
	r = abs(a1 - b) + abs(b - c2) + abs(c2 - a1)
	if r < m:
		m = r
	r = abs(a1 - b1) + abs(b1 - c) + abs(c - a1)
	if r < m:
		m = r
	r = abs(a1 - b1) + abs(b1 - c1) + abs(c1 - a1)
	if r < m:
		m = r
	r = abs(a1 - b1) + abs(b1 - c2) + abs(c2 - a1)
	if r < m:
		m = r
	r = abs(a1 - b2) + abs(b2 - c) + abs(c - a1)
	if r < m:
		m = r
	r = abs(a1 - b2) + abs(b2 - c1) + abs(c1 - a1)
	if r < m:
		m = r
	r = abs(a1 - b2) + abs(b2 - c2) + abs(c2 - a1)
	if r < m:
		m = r
	r = abs(a2 - b) + abs(b - c) + abs(c - a2)
	if r < m:
		m = r
	r = abs(a2 - b) + abs(b - c1) + abs(c1 - a2)
	if r < m:
		m = r
	r = abs(a2 - b) + abs(b - c2) + abs(c2 - a2)
	if r < m:
		m = r
	r = abs(a2 - b1) + abs(b1 - c) + abs(c - a2)
	if r < m:
		m = r
	r = abs(a2 - b1) + abs(b1 - c1) + abs(c1 - a2)
	if r < m:
		m = r
	r = abs(a2 - b1) + abs(b1 - c2) + abs(c2 - a2)
	if r < m:
		m = r
	r = abs(a2 - b2) + abs(b2 - c) + abs(c - a2)
	if r < m:
		m = r
	r = abs(a2 - b2) + abs(b2 - c1) + abs(c1 - a2)
	if r < m:
		m = r
	r = abs(a2 - b2) + abs(b2 - c2) + abs(c2 - a2)
	if r < m:
		m = r
	print(m)


def main():
	n = list(map(int, input().split()))
	n = sorted(n)
	return max(0, (n[2] - n[0]) * 2 - 4)
t = int(input())
for i in range(t):
	print(main())


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

def main():
	Q = int(input())
	for i in range(Q):
		(a, b, c) = sorted(getlist())
		if c - a <= 2:
			print(0)
		else:
			print((c - a - 2) * 2)
main()


TCs = int(input())
for i in range(TCs):
	arr = [int(x) for x in input().split()]
	arr.sort()
	if arr[0] == arr[1] == arr[2]:
		pass
	elif arr[0] == arr[1]:
		arr[0] = arr[0] + 1
		arr[1] = arr[1] + 1
		if arr[0] < arr[2]:
			arr[2] = arr[2] - 1
	elif arr[1] == arr[2]:
		arr[1] = arr[1] - 1
		arr[2] = arr[2] - 1
		if arr[1] > arr[0]:
			arr[0] = arr[0] + 1
	else:
		arr[0] = arr[0] + 1
		arr[2] = arr[2] - 1
	ans = abs(arr[0] - arr[1]) + abs(arr[2] - arr[1]) + abs(arr[0] - arr[2])
	print(ans)


n = int(input())
for i in range(n):
	(a, b, c) = sorted([int(h) for h in input().split()])
	A = [a - 1, a, a + 1]
	B = [b - 1, b, b + 1]
	C = [c - 1, c, c + 1]
	currMin = float('inf')
	for l in A:
		for j in B:
			for k in C:
				currMin = min(currMin, abs(l - j) + abs(l - k) + abs(j - k))
	print(currMin)


q = int(input())
for l in range(q):
	min_x = 3 * 10 ** 9
	(a, b, c) = map(int, input().split())
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				A = a + i
				B = b + j
				C = c + k
				x = abs(A - B) + abs(A - C) + abs(B - C)
				if x < min_x:
					min_x = x
	print(min_x)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	a1 = [a, a + 1, a - 1]
	b1 = [b, b + 1, b - 1]
	c1 = [c, c + 1, c - 1]
	listy = []
	for i in range(3):
		for j in range(3):
			for k in range(3):
				a2 = a1[i]
				b2 = b1[j]
				c2 = c1[k]
				listy.append(abs(a2 - b2) + abs(c2 - b2) + abs(a2 - c2))
	print(min(listy))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	A = [a, b, c]
	A.sort()
	a = A[0]
	b = A[1]
	c = A[2]
	if a == b == c or (a == b and b == c - 1) or (a + 1 == b and b == c) or (b == a + 1 and c - 1 == b):
		print(0)
	elif a == b and b != c - 1:
		print((c - b) * 2 - 4)
	elif a + 1 != b and b == c:
		print((b - a) * 2 - 4)
	else:
		print(abs(b - a - 1) + abs(c - b - 1) + abs(c - a - 2))


R = lambda : map(int, input().split())
(t,) = R()
for _ in range(t):
	(a, b, c) = sorted(R())
	print(max(0, abs(a - b) + abs(a - c) + abs(b - c) - 4))


def compute_minimum_distance(input_arr):
	for i in range(len(input_arr)):
		input_arr[i] = int(input_arr[i])
	input_arr.sort()
	if input_arr[0] == input_arr[1] and input_arr[1] == input_arr[2]:
		return 0
	if input_arr[2] - input_arr[1] >= 2 and input_arr[0] == input_arr[1]:
		input_arr[2] -= 2
		res = abs(input_arr[2] - input_arr[1]) + abs(input_arr[1] - input_arr[0]) + abs(input_arr[2] - input_arr[0])
		return res
	if input_arr[1] - input_arr[0] >= 2 and input_arr[2] == input_arr[1]:
		input_arr[0] += 2
		res = abs(input_arr[2] - input_arr[1]) + abs(input_arr[1] - input_arr[0]) + abs(input_arr[2] - input_arr[0])
		return res
	if input_arr[0] != input_arr[1]:
		input_arr[0] += 1
	if input_arr[1] != input_arr[2]:
		input_arr[2] -= 1
	res = abs(input_arr[2] - input_arr[1]) + abs(input_arr[1] - input_arr[0]) + abs(input_arr[2] - input_arr[0])
	return res
inputs = []
inputs_num = int(input())
while inputs_num > 0:
	input_data = input().split(' ')
	inputs.append(input_data)
	inputs_num -= 1
for i in inputs:
	print(compute_minimum_distance(i))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split(' '))
	distance = []
	if a == b == c:
		print(0)
	else:
		distance.append(abs(a + 1 - (b + 1)) + abs(a + 1 - (c + 1)) + abs(b + 1 - (c + 1)))
		distance.append(abs(a + 1 - (b + 1)) + abs(a + 1 - (c - 1)) + abs(b + 1 - (c - 1)))
		distance.append(abs(a + 1 - (b - 1)) + abs(a + 1 - (c + 1)) + abs(b - 1 - (c + 1)))
		distance.append(abs(a - 1 - (b + 1)) + abs(a - 1 - (c + 1)) + abs(b + 1 - (c + 1)))
		distance.append(abs(a + 1 - (b + 1)) + abs(a + 1 - c) + abs(b + 1 - c))
		distance.append(abs(a + 1 - b) + abs(a + 1 - (c + 1)) + abs(b - (c + 1)))
		distance.append(abs(a - (b + 1)) + abs(a - (c + 1)) + abs(b + 1 - (c + 1)))
		distance.append(abs(a + 1 - b) + abs(a + 1 - (c - 1)) + abs(b - (c - 1)))
		distance.append(abs(a + 1 - (b - 1)) + abs(a + 1 - c) + abs(b - 1 - c))
		distance.append(abs(a - (b + 1)) + abs(a - (c - 1)) + abs(b + 1 - (c - 1)))
		distance.append(abs(a - 1 - (b + 1)) + abs(a - 1 - c) + abs(b + 1 - c))
		distance.append(abs(a - (b - 1)) + abs(a - (c + 1)) + abs(b - 1 - (c + 1)))
		distance.append(abs(a - 1 - b) + abs(a - 1 - (c + 1)) + abs(b - (c + 1)))
		distance.append(abs(a - 1 - (b - 1)) + abs(a - 1 - (c - 1)) + abs(b - 1 - (c - 1)))
		distance.append(abs(a - 1 - (b - 1)) + abs(a - 1 - (c + 1)) + abs(b - 1 - (c + 1)))
		distance.append(abs(a - 1 - (b + 1)) + abs(a - 1 - (c - 1)) + abs(b + 1 - (c - 1)))
		distance.append(abs(a + 1 - (b - 1)) + abs(a + 1 - (c - 1)) + abs(b - 1 - (c - 1)))
		distance.append(abs(a - 1 - (b - 1)) + abs(a - 1 - c) + abs(b - 1 - c))
		distance.append(abs(a - 1 - b) + abs(a - 1 - (c - 1)) + abs(b - (c - 1)))
		distance.append(abs(a - (b - 1)) + abs(a - (c - 1)) + abs(b - 1 - (c - 1)))
		distance.append(abs(a - b) + abs(a - c) + abs(b - c))
		distance.append(abs(a - b) + abs(a - (c + 1)) + abs(b - (c + 1)))
		distance.append(abs(a - (b + 1)) + abs(a - c) + abs(b + 1 - c))
		distance.append(abs(a + 1 - b) + abs(a + 1 - c) + abs(b - c))
		distance.append(abs(a - b) + abs(a - (c - 1)) + abs(b - (c - 1)))
		distance.append(abs(a - (b - 1)) + abs(a - c) + abs(b - 1 - c))
		distance.append(abs(a - 1 - b) + abs(a - 1 - c) + abs(b - c))
		print(min(distance))


t = int(input())
while t:
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1] == l[2]:
		print(0)
	elif l[0] == l[1]:
		l[1] += 1
		l[0] += 1
		if l[1] == l[2]:
			print(0)
		else:
			l[2] -= 1
			print(2 * (l[2] - l[1]))
	elif l[1] == l[2]:
		l[1] -= 1
		l[2] -= 1
		if l[1] == l[0]:
			print(0)
		else:
			l[0] += 1
			print(2 * (l[2] - l[0]))
	else:
		l[0] += 1
		l[2] -= 1
		print(-l[0] + l[2] - l[0] + l[2])
	t -= 1


for i in range(int(input())):
	a = [int(i) for i in input().split()]
	a.sort()
	if a[1] != a[2] and a[1] != a[0]:
		if a[0] < a[1]:
			a[0] += 1
		if a[2] > a[1]:
			a[2] -= 1
	elif a[1] == a[0]:
		a[0] += 1
		a[1] += 1
		if a[1] != a[2]:
			a[2] -= 1
	else:
		a[2] -= 1
		a[1] -= 1
		if a[0] != a[1]:
			a[0] += 1
	print(max(a[1] - a[0] + a[2] - a[1] + a[2] - a[0], 0))


for q in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	if c - a <= 2:
		ans = 0
	else:
		ans = 2 * (c - 1 - a - 1)
	print(ans)


for _ in range(int(input())):
	a = sorted([int(x) for x in input().split()])
	if a[2] - a[0] <= 2:
		print(0)
	else:
		print(2 * (a[2] - 1) - 2 * (a[0] + 1))


from math import ceil, sqrt, floor
for i in range(int(input())):
	(a, b, c) = sorted(list(map(int, input().split())))
	if c - a > 1:
		a += 1
		c -= 1
		if b < a:
			b += 1
		elif b > c:
			b -= 1
	elif c > b:
		c -= 1
	elif a < b:
		a += 1
	print(abs(a - b) + abs(b - c) + abs(c - a))


for i in range(int(input())):
	arr = sorted(list(map(int, input().split())))
	a = max(arr[1] - arr[0] - 1, 0) + max(arr[2] - 1 - arr[1], 0) + max(arr[2] - arr[0] - 2, 0)
	b = max(arr[1] - arr[0] - 2, 0) + max(arr[2] - arr[1], 0) + max(arr[2] - arr[0] - 2, 0)
	c = max(arr[1] - arr[0], 0) + max(arr[2] - arr[1] - 2, 0) + max(arr[2] - arr[0] - 2, 0)
	print(min(a, b, c))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = 10 ** 13
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				ans = min(ans, abs(i - j) + abs(j - k) + abs(k - i))
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	ar = [a] + [b] + [c]
	ar.sort()
	(x, y, z) = (ar[0], ar[1], ar[2])
	if x == y and y == z and (y == x):
		print(0)
		continue
	if x != y:
		x += 1
	else:
		x += 1
		y += 1
	if x == y and y == z and (y == x):
		print(0)
		continue
	if z != y:
		z -= 1
	else:
		z -= 1
		y -= 1
	print(abs(x - y) + abs(y - z) + abs(x - z))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(a, b, c) = map(int, input().split())
	distance = abs(a - b) + abs(a - c) + abs(b - c)
	if distance >= 4:
		print(distance - 4)
	else:
		print(0)


q = int(input())
out = []
for i in range(q):
	ab = [int(c) for c in input().split()]
	if min(ab) < max(ab) - 1:
		out.append(2 * (max(ab) - min(ab)) - 4)
	else:
		out.append(0)
for i in range(q):
	print(out[i])


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	m = 10000000000000
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				if abs(a + i - (b + j)) + abs(a + i - (c + k)) + abs(b + j - (c + k)) < m:
					m = abs(a + i - (b + j)) + abs(a + i - (c + k)) + abs(b + j - (c + k))
	print(m)


t = int(input())
for c in range(t):
	arr = list(map(int, input().split()))
	arr.sort()
	if arr[0] != arr[1] or arr[1] != arr[2]:
		if arr[0] == arr[1]:
			if arr[1] + 1 < arr[2]:
				arr[2] -= 1
			arr[1] += 1
			arr[0] += 1
		elif arr[1] == arr[2]:
			if arr[0] + 1 < arr[1]:
				arr[0] += 1
			arr[1] -= 1
			arr[2] -= 1
		else:
			arr[0] += 1
			arr[2] -= 1
	print(arr[2] - arr[0] + (arr[2] - arr[1]) + (arr[1] - arr[0]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mn = abs(a - b) + abs(b - c) + abs(c - a)
	val = (a + b + c) // 3
	for i in range(-1, 2):
		v = val + i
		(ta, tb, tc) = (a, b, c)
		if ta > v:
			ta -= 1
		elif ta < v:
			ta += 1
		if tb > v:
			tb -= 1
		elif tb < v:
			tb += 1
		if tc > v:
			tc -= 1
		elif tc < v:
			tc += 1
		mn = min(mn, abs(ta - tb) + abs(tc - tb) + abs(tc - ta))
	print(mn)


for i in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	print(2 * max(c - a, 2) - 4)


q = int(input())
for i in range(q):
	a = list(map(int, input().split()))
	a.sort()
	v = abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]) - 4
	if v < 0:
		v = 0
	print(v)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	d1 = abs(a - b)
	d2 = abs(b - c)
	d3 = abs(c - a)
	l = [d1, d2, d3]
	l.sort()
	if l[0] == 0 and l[1] > 0:
		if d1 + d2 + d3 > 4:
			print(d1 + d2 + d3 - 4)
		else:
			print(0)
	elif d1 + d2 + d3 == 0:
		print(0)
	else:
		print(d1 + d2 + d3 - 4)


from copy import copy

def arr_float_inp():
	return [float(s) for s in input().split()]

def arr_int_inp():
	return [int(s) for s in input().split()]

def int_inp():
	return int(input())

def float_inp():
	return float(input())
for _ in range(int_inp()):
	(c, b, a) = sorted(arr_int_inp())
	if a - c == 0 or a - c <= 2:
		print(0)
	else:
		print(2 * (a - 1 - (c + 1)))


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	mn = min([a, b, c])
	mx = max([a, b, c])
	print(max([mx - mn - 2, 0]) * 2)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = abs(a - b) + abs(a - c) + abs(b - c) - 4
	if ans < 0:
		ans = 0
	print(ans)


def spd(a, b, c, da, db, dc):
	a1 = a + da
	b1 = b + db
	c1 = c + dc
	return abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1)

def task():
	(a, b, c) = map(int, input().split())
	arr = list()
	for da in [-1, 0, 1]:
		for db in [-1, 0, 1]:
			for dc in [-1, 0, 1]:
				d = spd(a, b, c, da, db, dc)
				arr.append(d)
	print(min(arr))

def main(n):
	if n == 'inf':
		while True:
			task()
	else:
		for i in range(n):
			task()
main(int(input()))


def main():
	inps = eval(input())
	count = 0
	nums = []
	while count != inps:
		int_str = input().split()
		int_inp = [int(j) for j in int_str]
		nums.append(int_inp)
		count += 1
	for i in nums:
		dist = None
		a = i[0]
		b = i[1]
		c = i[2]
		check = None
		while check != 'Done':
			if dist is None:
				dist = abs(i[0] - i[1]) + abs(i[0] - i[2]) + abs(i[1] - i[2])
			else:
				for x in range(-1, 2):
					tempa = a + x
					for y in range(-1, 2):
						tempb = b + y
						for z in range(-1, 2):
							tempc = c + z
							dist = compareDist(dist, tempa, tempb, tempc)
				check = 'Done'
		check = None
		print(dist)

def compareDist(dist, a, b, c):
	new_dist = abs(abs(a - b) + abs(a - c) + abs(b - c))
	if dist > new_dist:
		dist = new_dist
	return dist
main()


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split(' '))
	l = []
	for a1 in range(a - 1, a + 2):
		for b1 in range(b - 1, b + 2):
			for c1 in range(c - 1, c + 2):
				x = abs(a1 - b1) + abs(b1 - c1) + abs(c1 - a1)
				l.append(x)
	print(min(l))


for T in range(int(input())):
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	if arr[0] + 2 >= arr[2]:
		print(0)
	else:
		print(2 * (arr[2] - arr[0] - 2))


q = int(input())
for numbers in range(q):
	(a, b, c) = list(map(int, input().split()))
	x = max(a, b, c)
	y = min(a, b, c)
	if x - y <= 2:
		print(0)
	else:
		print(2 * (x - y - 2))


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		(a, b, c) = map(int, input().split())
		ans = float('inf')
		for A in range(a - 1, a + 2):
			for B in range(b - 1, b + 2):
				for C in range(c - 1, c + 2):
					ans = min(ans, abs(A - B) + abs(B - C) + abs(C - A))
		print(ans)
main()


import math
import copy
t = int(input())
for _ in range(t):
	a = [int(i) for i in input().split()]
	a.sort()
	if a[0] == a[1] and a[1] == a[2]:
		print(0)
	elif a[0] == a[1] or a[1] == a[2]:
		if a[0] == a[1]:
			if a[2] == a[0] + 1:
				a[2] -= 1
			else:
				a[2] -= 1
				a[0] += 1
				a[1] += 1
		elif a[1] == a[2]:
			if a[0] == a[1] - 1:
				a[0] += 1
			else:
				a[0] += 1
				a[1] -= 1
				a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	else:
		a[0] += 1
		a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))


q = int(input())
for i in range(q):
	(a, b, c) = [int(i) for i in input().split()]
	minn = abs(a - b) + abs(c - b) + abs(a - c)
	for ai in range(a - 1, a + 2):
		for bi in range(b - 1, b + 2):
			for ci in range(c - 1, c + 2):
				minn = min(minn, abs(ai - bi) + abs(ci - bi) + abs(ai - ci))
	print(minn)


t = int(input())
while t:
	a = input()
	a = a.split()
	a = [int(i) for i in a]
	num = 1
	a.sort()
	if a[0] == a[1] and a[1] == a[2]:
		num = 0
	elif a[0] != a[1] and a[1] == a[2]:
		if a[0] + 1 == a[1] or a[0] + 2 == a[1]:
			num = 0
		else:
			a[0] += 1
			a[2] -= 1
			a[1] -= 1
	elif a[0] == a[1] and a[1] != a[2]:
		if a[0] + 1 == a[2] or a[0] + 2 == a[2]:
			num = 0
		else:
			a[0] += 1
			a[1] += 1
			a[2] -= 1
	elif a[0] != a[1] and a[1] != a[2]:
		a[0] += 1
		a[2] -= 1
	if num:
		num = 0
		num += a[1] - a[0]
		num += a[2] - a[1]
		num += a[2] - a[0]
		print(num)
	else:
		print(0)
	t = t - 1


T = int(input())
while T > 0:
	T -= 1
	a = list(map(int, input().split()))
	a.sort()
	if a[0] < a[2]:
		a[0] += 1
	if a[0] < a[2]:
		a[2] -= 1
	if a[1] < a[0]:
		a[1] += 1
	if a[1] > a[2]:
		a[1] -= 1
	print(2 * (a[2] - a[0]))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	if a == b == c:
		print(0)
	elif a == b or a == c or b == c:
		print(max(0, max(a, b, c) - min(a, b, c) - 2) * 2)
	else:
		a = [a, b, c]
		a.sort()
		print(abs(a[0] - a[1] + 1) + abs(a[1] - a[2] + 1) + abs(a[0] - a[2] + 2))


T = int(input())
for i in range(T):
	(a, b, c) = map(int, input().strip().split())
	p = abs(b - c) + abs(a - b) + abs(a - c)
	for i in (a + 1, a, a - 1):
		for j in (b + 1, b, b - 1):
			for k in (c + 1, c, c - 1):
				m = abs(i - j) + abs(j - k) + abs(i - k)
				if m < p:
					p = m
	print(p)


t = int(input())
for i in range(t):
	d = list(map(int, input().split()))
	d.sort()
	print(max(0, 2 * (d[2] - d[0] - 2)))


n = int(input())
while n:
	a = [int(x) for x in input().split()]
	a.sort()
	pairwise = a[2] - a[0]
	print(max(0, pairwise - 2) * 2)
	n -= 1


q = int(input())
for Q in range(q):
	(a, b, c) = list(map(int, input().split()))
	s = abs(a - b) + abs(b - c) + abs(a - c) - 4
	print(max(s, 0))


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (a, b, c) in Query:
	ans = 10 ** 15
	for n1 in range(a - 1, a + 2):
		for n2 in range(b - 1, b + 2):
			for n3 in range(c - 1, c + 2):
				ans = min(ans, abs(n1 - n2) + abs(n2 - n3) + abs(n3 - n1))
	print(ans)


for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	a1 = [a, a + 1, a - 1]
	a2 = [b, b + 1, b - 1]
	a3 = [c, c + 1, c - 1]
	ans = set()
	for i in a1:
		for j in a2:
			for k in a3:
				x = abs(i - j) + abs(i - k) + abs(j - k)
				ans.add(x)
	print(min(ans))


q = int(input())
k = []
for i in range(q):
	(a, b, c) = [int(x) for x in input().split()]
	k = sorted([a, b, c])
	if k[1] - k[0] < 1 and k[2] - k[1] < 1 or (k[1] - k[0] < 1 and k[2] - k[1] == 1) or (k[1] - k[0] == 1 and k[2] - k[1] < 1):
		print('0')
	elif k[1] - k[0] < 1 and k[2] - k[1] > 1:
		print(abs(k[2] - k[1]) - 2 + abs(k[2] - k[0]) - 2)
	elif k[1] - k[0] > 1 and k[2] - k[1] < 1:
		print(abs(k[1] - k[0]) - 2 + abs(k[2] - k[0]) - 2)
	elif k[1] - k[0] >= 1 and k[2] - k[1] >= 1:
		print(abs(k[1] - k[0]) - 1 + abs(k[2] - k[1]) - 1 + abs(k[2] - k[0]) - 2)


t = int(input())
for nt in range(t):
	(a, b, c) = map(int, input().split())
	print(max(0, abs(a - b) + abs(b - c) + abs(a - c) - 4))


try:
	for _ in range(int(input())):
		l = list(map(int, input().split()))
		x = min(l)
		l.remove(x)
		y = max(l)
		l.remove(y)
		z = l[0]
		if x == y and y == z:
			print('0')
		elif x == z or z == y:
			a = min([x, y, z])
			b = max([x, y, z])
			if b - a == 1:
				print('0')
			else:
				print(2 * abs(a + 1 - (b - 1)))
		else:
			x = x + 1
			y = y - 1
			print(abs(x - y) + abs(x - z) + abs(y - z))
except:
	pass


def solution(a, b, c):
	if a == b == c:
		return 0
	(a, b, c) = sorted([a, b, c])
	if a == b:
		c -= 1
		if a == b == c:
			return 0
		a += 1
		return 2 * abs(c - a)
	elif b == c:
		a += 1
		if a == b == c:
			return 0
		b -= 1
		return 2 * abs(b - a)
	else:
		a += 1
		c -= 1
		return abs(a - b) + abs(c - a) + abs(c - b)
for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	print(solution(a, b, c))


import sys, math, itertools, heapq, collections, bisect, string
inf = float('inf')
mod = 10 ** 9 + 7
ans = inf
count = 0
pro = 1

def solve():
	ans = inf
	(a, b, c) = map(int, input().split())
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				na = a + i
				nb = b + j
				nc = c + k
				ans = min(ans, abs(na - nb) + abs(nc - nb) + abs(na - nc))
	print(ans)
	return
n = int(input())
for i in range(n):
	solve()


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = min(a, b, c)
	M = max(a, b, c)
	if m == a:
		a += 1
	if m == b:
		b += 1
	if m == c:
		c += 1
	if M == a:
		a -= 1
	if M == b:
		b -= 1
	if M == c:
		c -= 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


n = int(input())
while n:
	n -= 1
	x = list(map(int, input().split(' ')))
	x.sort()
	a = x[0]
	b = x[1]
	c = x[2]
	if a == b and b == c:
		print(0)
	else:
		if b == c and b - a >= 1:
			b -= 1
		if b == a and c - b >= 1:
			c -= 1
		if b - a >= 1:
			a += 1
		if c - b >= 1:
			c -= 1
		print(abs(a - b) + abs(a - c) + abs(b - c))


from itertools import product
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	ans = 3000000000.0 + 1
	for (a1, b1, c1) in product(range(-1, 2), range(-1, 2), range(-1, 2)):
		an = a + a1
		bn = b + b1
		cn = c + c1
		ans = min(ans, abs(an - bn) + abs(an - cn) + abs(cn - bn))
	print(int(ans))


import math
tests = int(input())
lisTest = list()
for i in range(tests):
	singleTest = input().split(' ')
	singleTest[0] = int(singleTest[0])
	singleTest[1] = int(singleTest[1])
	singleTest[2] = int(singleTest[2])
	lisTest.append(singleTest)
for k in lisTest:
	distance = []
	x = [k[0], k[0] - 1, k[0] + 1]
	y = [k[1], k[1] - 1, k[1] + 1]
	z = [k[2], k[2] - 1, k[2] + 1]
	for l in range(3):
		for m in range(3):
			for n in range(3):
				tempdis = abs(x[l] - y[m]) + abs(x[l] - z[n]) + abs(y[m] - z[n])
				distance.append(tempdis)
	print(min(distance))


q = int(input())
lis1 = []
ans = 0
while q:
	loc = input().split()
	a = int(loc[0])
	b = int(loc[1])
	c = int(loc[2])
	mi = min(a, b, c)
	ma = max(a, b, c)
	sumi = a + b + c
	tem = sumi - mi - ma
	if a == b == c or ma - mi <= 2:
		lis1.append(0)
	else:
		mi += 1
		ma -= 1
		ans = ma - mi + (ma - tem) + (tem - mi)
		lis1.append(ans)
	q -= 1
for i in range(len(lis1)):
	print(lis1[i])


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	ans = 0
	if a == b and b == c:
		print(0)
		continue
	if a == b or b == c:
		if c == a + 2 or c == a + 1:
			print(0)
		else:
			if a == b:
				print(c - b - 2 + (c - a - 2))
			if b == c:
				print(c - a - 2 + (b - a - 2))
		continue
	if a == b - 1 and c == b + 1:
		print(0)
		continue
	a = a + 1
	c = c - 1
	print(b - a + (c - b) + (c - a))


def findDistance(argument):
	distance = 0
	argument = sorted(argument)
	a = argument[0]
	b = argument[1]
	c = argument[2]
	if a < b and b < c:
		a += 1
		c -= 1
	elif a == b and a != c:
		if c == b + 1:
			c -= 1
		else:
			a += 1
			b += 1
			c -= 1
	elif b == c and a != b:
		if a == b - 1:
			a += 1
		else:
			a += 1
			b -= 1
			c -= 1
	distance = abs(a - b) + abs(b - c) + abs(a - c)
	print(distance)
number = eval(input())
if number > 0:
	for i in range(number):
		argument = []
		temp = input()
		argument1 = temp.split(' ')
		j = 0
		for j in range(3):
			argument.append(eval(argument1[j]))
		findDistance(argument)


for _ in range(int(input())):
	(a, s, flag) = ([0, 0, 0], 0, 0)
	(a[0], a[1], a[2]) = map(int, input().split())
	a.sort()
	if a[0] == a[1] and a[1] != a[2] or (a[1] == a[2] and a[1] != a[0]):
		if a[1] - a[0] >= 2 or a[2] - a[1] >= 2:
			flag = 1
	a[0] -= a[1]
	a[2] -= a[1]
	a[1] = 0
	if a[0] < 0:
		a[0] += 1
	if a[2] > 0:
		a[2] -= 1
	for i in a:
		s += abs(i)
	if flag == 1:
		print(2 * s - 2)
		continue
	print(2 * s)


N = int(input())
for _ in range(N):
	nums = list(map(int, input().split(' ')))
	(mi, ma) = (min(nums), max(nums))
	if ma - mi > 2:
		print(2 * (ma - mi - 2))
	else:
		print(0)


def foo():
	l = [int(x) for x in input().split()]
	l.sort()
	s = l[1] - l[0] + (l[2] - l[1])
	if s < 3:
		print(0)
	else:
		print((s - 2) * 2)
for _ in range(int(input())):
	foo()


a = int(input())
q = []
min1 = 1000000000566666666666666
for i in range(a):
	(a, b, c) = map(int, input().split())
	(a1, b1, c1) = (a, b, c)
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a += 1
	b += 1
	c += 1
	a += 1
	b += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a -= 2
	b += 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a += 1
	b += 1
	a += 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a -= 2
	c += 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a += 1
	c += 1
	b += 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b -= 2
	c += 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	c -= 2
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	b += 1
	c += 1
	if b == c:
		a += 1
		b -= 1
		c -= 1
		q.append(abs(a - b) + abs(a - c) + abs(b - c))
	a -= 1
	b += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a -= 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	b -= 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a += 1
	b += 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a += 1
	b += 1
	c -= 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a += 1
	b -= 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a += 1
	b -= 1
	c -= 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a -= 1
	b += 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a -= 1
	b += 1
	c -= 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a -= 1
	b -= 1
	c += 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	a -= 1
	b -= 1
	c -= 1
	q.append(abs(a - b) + abs(a - c) + abs(b - c))
	(a, b, c) = (a1, b1, c1)
	ans = min(q)
	print(ans)
	q = []


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def rec(a, b, i):
	if a == b:
		return 0
	return min(rec(a + i, b, i + 1), rec(a, b + i, i + 1))

def solve():
	(a, b, c) = sep()
	l = []
	for i in range(0, 3):
		l.append(a - 1 + i)
	for i in range(0, 3):
		l.append(b - 1 + i)
	for i in range(0, 3):
		l.append(c - 1 + i)
	ans = 10 ** 12
	for i in range(0, 3):
		for j in range(3, 6):
			for k in range(6, 9):
				ans = min(ans, abs(l[i] - l[j]) + abs(l[i] - l[k]) + abs(l[j] - l[k]))
	print(ans)
testcase(int(inp()))


def solve(pos1, pos2, pos3):
	dis = 10000000000
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				newPos1 = pos1 + i
				newPos2 = pos2 + j
				newPos3 = pos3 + k
				newdis = abs(newPos1 - newPos2) + abs(newPos1 - newPos3) + abs(newPos2 - newPos3)
				if newdis < dis:
					dis = newdis
	return dis
N = eval(input())
for i in range(N):
	lst = list(map(int, input().split(' ')))
	print(solve(lst[0], lst[1], lst[2]))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split(' '))
	l = [a, b, c]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if a == b == c:
		s = 0
	elif a == b:
		if c == a + 1:
			c = c - 1
		else:
			a = a + 1
			b = b + 1
			c = c - 1
	elif b == c:
		if b == a + 1:
			a = a + 1
		else:
			a = a + 1
			b = b - 1
			c = c - 1
	else:
		a = a + 1
		c = c - 1
	s = b - a + c - b + c - a
	print(s)


MAXN = 10 ** 18

def value(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)

def solve():
	(a, b, c) = map(int, input().split())
	min_value = MAXN
	for aa in range(a - 1, a + 2):
		for bb in range(b - 1, b + 2):
			for cc in range(c - 1, c + 2):
				min_value = min(min_value, value(aa, bb, cc))
	print(min_value)

def main():
	q = int(input())
	for _ in range(q):
		solve()
main()


a = int(input())

def c(g):
	g = int(g)
	return g

def f(d):
	if d[0] == d[1] == d[2]:
		return 0
	d.sort()
	if d[0] == d[1]:
		if d[2] - d[1] == 1:
			return 0
		else:
			return (d[2] - d[1] - 2) * 2
	elif d[1] == d[2]:
		if d[2] - d[0] == 1:
			return 0
		else:
			return (d[2] - d[0] - 2) * 2
	else:
		if d[1] - d[0] != 0:
			d[0] += 1
		if d[2] - d[1] != 0:
			d[2] -= 1
		return (d[2] - d[0]) * 2
for i in range(a):
	d = str(input())
	x = map(c, d.split())
	print(f(list(x)))


for case in range(int(input())):
	(a, b, c) = sorted([int(i) for i in input().split()])
	a = a + 1 if a != c else a
	c = c - 1 if a != c else c
	print(2 * (c - a))


def program():
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	x = abs(a - b) + abs(b - c) + abs(c - a) - 4
	if x > 0:
		print(x)
	else:
		print('0')
t = int(input())
for x in range(t):
	program()


q = int(input())
i = 0
while i < q:
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] == a[2] or (a[0] == a[1] and a[2] - a[1] == 1) or (a[1] == a[2] and a[1] - a[0] == 1):
		print('0')
	else:
		a[0] = a[0] + 1
		a[2] = a[2] - 1
		print(a[2] * 2 - 2 * a[0])
	i += 1


testes = int(input())
for t in range(testes):
	ent = input().split(' ')
	ent[0] = int(ent[0])
	ent[1] = int(ent[1])
	ent[2] = int(ent[2])
	ent.sort()
	x = ent[0]
	y = ent[1]
	z = ent[2]
	d1 = ent[1] - ent[0]
	d2 = ent[2] - ent[1]
	if d1 != 0:
		d1 -= 1
	if d1 != 0:
		d1 -= 1
		d2 += 1
	if d2 != 0:
		d2 -= 1
	result1 = d1 + d2 + (d1 + d2)
	d1 = ent[1] - ent[0]
	d2 = ent[2] - ent[1]
	if d2 != 0:
		d2 -= 1
	if d2 != 0:
		d1 += 1
		d2 -= 1
	if d1 != 0:
		d1 -= 1
	result2 = d1 + d2 + (d1 + d2)
	if result1 <= result2:
		print(result1)
	else:
		print(result2)


def main():
	(a, b, c) = map(int, input().split())
	mx = max(a, max(b, c))
	mn = min(a, min(b, c))
	if abs(mx - mn) <= 2:
		print(0)
	else:
		print((abs(mx - mn) - 2) * 2)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


for i in range(int(input())):
	l = [int(x) for x in input().split()]
	(a, b, c) = (l[0], l[1], l[2])
	na_ = [a - 1, a, a + 1]
	nb_ = [b - 1, b, b + 1]
	nc_ = [c - 1, c, c + 1]
	ans = 10000000000
	for na in na_:
		for nb in nb_:
			for nc in nc_:
				ans = min(ans, abs(na - nb) + abs(na - nc) + abs(nc - nb))
	print(ans)


tc = input()
tc = int(tc, 10)
while tc > 0:
	a = list(map(int, input().strip().split()))
	a.sort()
	if a[1] == a[2] and a[2] > a[0]:
		a[2] -= 1
		a[1] -= 1
	if a[1] == a[0] and a[2] > a[0]:
		a[1] += 1
		a[0] += 1
	a[0] += min(1, a[1] - a[0])
	a[2] -= min(1, a[2] - a[1])
	ans = 2 * (a[2] - a[0])
	print(ans)
	tc -= 1


t = int(input())
s = []
for ikofk in range(0, t):
	x = input()
	xx = x.split()
	for i in range(0, 3):
		xx[i] = int(xx[i])
	xx.sort()
	a = xx[0]
	b = xx[1]
	c = xx[2]
	if c - a == 0 or c - a == 1 or c - a == 2:
		s.append(0)
	else:
		d = c - a + (c - b) + (b - a) - 4
		s.append(d)
for i in s:
	print(i)


n = int(input())
for _ in range(n):
	(a, b, c) = map(int, input().split())
	A = [a + 1, a, a - 1]
	B = [b + 1, b, b - 1]
	C = [c + 1, c, c - 1]
	ans = 10 ** 9 * 3
	for x in A:
		for y in B:
			for z in C:
				ans = min(ans, abs(x - y) + abs(y - z) + abs(x - z))
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = float('inf')
	moves = [-1, 0, 1]
	for x1 in moves:
		ap = a + x1
		for x2 in moves:
			bp = b + x2
			for x3 in moves:
				cp = c + x3
				ans = min(ans, abs(ap - bp) + abs(ap - cp) + abs(bp - cp))
	print(ans)


local = False
if local:
	file = open('A.txt', 'r')

def IN():
	if local:
		return file.readline()
	else:
		return input()

def solve(a, b, c):
	(a, b, c) = sorted([a, b, c])
	if a == b:
		if b == c:
			return 0
		else:
			return max(0, abs(a - c) - 2) + max(0, abs(b - c) - 2)
	elif b == c:
		return max(0, abs(a - b) - 2) + max(0, abs(a - c) - 2)
	else:
		return max(0, abs(a - c) - 2) + max(0, abs(a - b) - 1) + max(0, abs(b - c) - 1)
t = int(IN())
for i in range(t):
	(a, b, c) = [int(n) for n in IN().split()]
	print(solve(a, b, c))


def s(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
q = int(input())
d = [-1, 0, 1]
s1 = 0
for i in range(q):
	(a, b, c) = map(int, input().split())
	print(min(s(a, b, c), s(a, b, c - 1), s(a, b, c + 1), s(a, b - 1, c), s(a, b - 1, c - 1), s(a, b - 1, c + 1), s(a, b + 1, c), s(a, b + 1, c - 1), s(a, b + 1, c + 1), s(a + 1, b, c), s(a + 1, b, c - 1), s(a + 1, b, c + 1), s(a + 1, b - 1, c), s(a + 1, b - 1, c - 1), s(a + 1, b - 1, c + 1), s(a + 1, b + 1, c), s(a + 1, b + 1, c - 1), s(a + 1, b + 1, c + 1), s(a - 1, b, c), s(a - 1, b, c - 1), s(a - 1, b, c + 1), s(a - 1, b - 1, c), s(a - 1, b - 1, c - 1), s(a - 1, b - 1, c + 1), s(a - 1, b + 1, c), s(a - 1, b + 1, c - 1), s(a - 1, b + 1, c + 1)))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print(0)
	else:
		x = abs(a - b) + abs(b - c) + abs(c - a) - 4
		print(max(0, x))


from itertools import product
all_possible_subsets = list(map(tuple, product(range(-1, 2), repeat=3)))

def solve(l):
	(x, y, z) = l
	return abs(x - y) + abs(y - z) + abs(x - z)
t = int(input())
while t > 0:
	l = list(map(int, input().split()))
	l2 = list((solve(map(sum, zip(l, i))) for i in all_possible_subsets))
	print(min(l2))
	t -= 1


def mod(a):
	return a if a > 0 else -1 * a

def diff(a, b, c):
	return mod(a - b) + mod(b - c) + mod(c - a)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				d.append(diff(a + i, b + j, c + k))
	print(min(d))


import sys, itertools, math
T = int(sys.stdin.readline())
for _ in range(T):
	(a, b, c) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
	md = 10000000000000
	for a2 in range(a - 1, a + 2):
		for b2 in range(b - 1, b + 2):
			for c2 in range(c - 1, c + 2):
				md = min(md, abs(a2 - b2) + abs(a2 - c2) + abs(b2 - c2))
	print(md)


q = int(input())
ans_arr = []
for i in range(q):
	[a, b, c] = [int(j) for j in input().split()]
	arr = [a, b, c]
	if a == b and b == c:
		ans_arr.append(str(0))
	else:
		arr.sort()
		if arr[0] == arr[1]:
			if arr[2] - arr[1] == 1:
				arr[2] -= 1
			else:
				arr[2] -= 1
				arr[0] += 1
				arr[1] += 1
		elif arr[1] == arr[2]:
			if arr[1] - arr[0] == 1:
				arr[0] += 1
			else:
				arr[0] += 1
				arr[1] -= 1
				arr[2] -= 1
		elif arr[1] - arr[0] == 1 or arr[2] - arr[1] == 1:
			arr[0] += 1
			arr[2] -= 1
		else:
			arr[0] += 1
			arr[1] -= 1
			arr[2] -= 1
		ans_arr.append(str(abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[2] - arr[0])))
print('\n'.join(ans_arr))


a = int(input())
min1 = 1212121212197895578934589578934578975893457893475893475893475893478934
q = []
for i in range(a):
	(a, b, c) = map(int, input().split())
	for an in range(-1, 2):
		for bn in range(-1, 2):
			for cn in range(-1, 2):
				ah = a + an
				bh = b + bn
				ch = c + cn
				ans = min(min1, abs(ah - bh) + abs(ah - ch) + abs(bh - ch))
				q.append(ans)
	print(min(q))
	q = []


n = int(input())
for i in range(n):
	k = input()
	arr1 = k.split()
	arr = []
	for i in arr1:
		arr.append(int(i))
	count = 0
	mins = 0
	arr = sorted(arr)
	if arr[1] > arr[0] and arr[1] - arr[0] > 1:
		arr[0] = arr[0] + 1
		arr[1] = arr[1] - 1
		arr[2] = arr[2] - 1
	elif arr[1] == arr[0] and arr[1] != arr[2] and (arr[2] - arr[1] == 1):
		arr[2] -= 1
	elif arr[1] > arr[0] and arr[1] - arr[0] == 1 and (arr[1] != arr[2]):
		arr[0] = arr[0] + 1
		arr[2] = arr[2] - 1
	elif arr[1] > arr[0] and arr[1] - arr[0] == 1 and (arr[1] == arr[2]):
		arr[0] = arr[0] + 1
	elif arr[1] == arr[0] and arr[1] != arr[2] and (arr[2] - arr[1] > 1):
		arr[2] -= 1
		arr[0] += 1
		arr[1] += 1
	ans = abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
	print(ans)


INF = 10 ** 18
t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	a = sorted(a)
	if a[0] == a[2] or a[0] + 1 == a[2]:
		print(0)
		continue
	a[0] += 1
	a[2] -= 1
	a[1] = a[0]
	ans = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0])
	print(ans)


import sys
t = int(sys.stdin.readline().strip())
for i in range(t):
	a = list(map(int, sys.stdin.readline().strip().split()))
	a.sort()
	if a[0] == a[1] and a[1] < a[2]:
		a[0] += 1
		a[1] += 1
		if a[1] < a[2]:
			a[2] -= 1
	elif a[1] == a[2] and a[0] < a[2]:
		a[1] -= 1
		a[2] -= 1
		if a[0] < a[1]:
			a[0] += 1
	else:
		if a[0] < a[1]:
			a[0] += 1
		if a[2] > a[1]:
			a[2] -= 1
	print(abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2]))


def distance():
	t = int(input())
	if not 1 <= t <= 1000:
		return
	for i in range(t):
		pos = list(map(int, input().split()))
		for j in pos:
			if not 1 <= j <= 10 ** 9:
				return
		pos.sort()
		(a, b, c) = (pos[0], pos[1], pos[2])
		if a == b == c:
			a = a
			b = b
			c = c
		elif a == b:
			if c > a + 1:
				a += 1
				b += 1
				c -= 1
			elif c == a + 1:
				c -= 1
		elif b == c:
			if a == c - 1:
				a += 1
			elif a < c - 1:
				b -= 1
				c -= 1
				a += 1
		else:
			a += 1
			c -= 1
		ans = 2 * (c - a)
		print(ans)
distance()


t = int(input())
for i in range(t):
	d = list(map(int, input().split()))
	d.sort()
	if d[0] == d[1] and d[1] == d[2]:
		print(0)
	else:
		print(max(0, 2 * (d[2] - d[0] - 2)))


import sys
import math
import re
import io

def query_value(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)

def solve(a, b, c):
	min_val = 10 ** 18
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				val = query_value(i, j, k)
				min_val = min(min_val, val)
	return min_val

def main():
	for _ in range(int(input())):
		(a, b, c) = map(int, input().split())
		print(solve(a, b, c))
main()


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	a = [x, x - 1, x + 1]
	b = [y, y - 1, y + 1]
	c = [z, z - 1, z + 1]
	min = abs(x - y) + abs(x - z) + abs(y - z)
	for i in a:
		for j in b:
			for k in c:
				m = abs(i - j) + abs(j - k) + abs(i - k)
				min = m if m < min else min
	print(min)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	f = sorted(list(map(int, sys.stdin.readline().split())))
	if f[0] < f[2]:
		f[0] += 1
	if f[0] < f[2]:
		f[2] -= 1
	print((f[2] - f[0]) * 2)


q = int(input())
while q > 0:
	a = [int(x) for x in input().split()]
	a.sort()
	ans = 0
	uniq = len(list(dict.fromkeys(a)))
	if uniq == 2:
		if a[0] == a[1]:
			a[0] += 1
			a[1] += 1
			a[2] -= 1
		elif a[1] == a[2]:
			a[0] += 1
			a[1] -= 1
			a[2] -= 1
	elif uniq == 3:
		a[0] += 1
		a[2] -= 1
	for i in range(1, 3):
		ans += a[i] - a[i - 1]
	ans += a[2] - a[0]
	if ans < 0:
		ans = 0
	print(ans)
	q -= 1


from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for i in range(t):
	a = iia()
	a.sort()
	if a[0] == a[1] and a[2] > a[1]:
		a[0] += 1
		a[1] += 1
	elif a[1] > a[0]:
		a[0] += 1
	if a[1] == a[2] and a[0] < a[1]:
		a[1] -= 1
		a[2] -= 1
	elif a[1] < a[2]:
		a[2] -= 1
	print(abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2]))


t = int(input())
for q in range(t):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] == a[2]:
		ans = 0
	elif a[0] == a[1]:
		if a[2] - a[1] == 1:
			ans = 0
		else:
			ans = 2 * (a[2] - a[0] - 2)
	elif a[1] == a[2]:
		if a[1] - a[0] == 1:
			ans = 0
		else:
			ans = 2 * (a[2] - a[0] - 2)
	elif a[1] - a[0] == 1 and a[2] - a[1] == 1:
		ans = 0
	elif a[1] - a[0] == 1:
		ans = 2 * (a[2] - a[1] - 1)
	elif a[2] - a[1] == 1:
		ans = 2 * (a[1] - a[0] - 1)
	else:
		ans = a[1] - a[0] + (a[2] - a[0] - 2) + (a[2] - a[1] - 2)
	print(ans)


for _ in range(int(input())):
	l = [int(i) for i in input().split()]
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if a == b and b == c:
		print(0)
	elif a == b:
		a += 1
		b += 1
		if a == c:
			print(0)
		else:
			c -= 1
			print(2 * (c - a))
	elif b == c:
		b -= 1
		c -= 1
		if a == c:
			print(0)
		else:
			a += 1
			print(2 * (c - a))
	else:
		a += 1
		c -= 1
		print(2 * (c - a))


test = eval(input())
words = []
for i in range(test):
	word = input()
	words.append(word)
ans = []
for word in words:
	lst = word.split(' ')
	a = abs(int(lst[0]) - int(lst[1]))
	b = abs(int(lst[0]) - int(lst[2]))
	c = abs(int(lst[1]) - int(lst[2]))
	s = a + b + c
	if s < 4:
		s = 0
	else:
		s = s - 4
	ans.append(s)
for i in ans:
	print(i)


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(a, b, c) = map(int, ip().split())
	(a, b, c) = sorted([a, b, c])
	if a == b == c or (a == b - 1 and a == c - 2):
		print(0)
	else:
		(x, y, z) = (a, b, c)
		ans = float('inf')
		for i in [-1, 0, 1]:
			x = a + i
			for j in [-1, 0, 1]:
				y = j + b
				for k in [-1, 0, 1]:
					z = c + k
					ans = min(ans, abs(x - y) + abs(y - z) + abs(z - x))
		print(ans)


for _ in ' ' * int(input()):
	a = list(map(int, input().split()))
	print(max(0, 2 * (max(a) - min(a) - 2)))


from collections import Counter

def get_min(a):
	ans = 1000000000000000
	for i in (0, 1, -1):
		for j in (0, 1, -1):
			for k in (0, 1, -1):
				p = a[0] + i
				q = a[1] + j
				r = a[2] + k
				dist = abs(p - q) + abs(p - r) + abs(q - r)
				ans = min(ans, dist)
	return ans
ntest = int(input())
ans = []
for test in range(ntest):
	A = list(map(int, input().split()))
	ans.append(get_min(A))
for res in ans:
	print(res)


t = int(input())
for t in range(0, t):
	x = [int(x) for x in input().split()]
	x.sort(reverse=True)
	(a, b, c) = [int(x) for x in x]
	d = a - c
	if d < 2:
		print(0)
	else:
		print(2 * (d - 2))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mini = abs(a - b) + abs(b - c) + abs(c - a)
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				mini = min(mini, abs(i - j) + abs(j - k) + abs(i - k))
	print(int(mini))


for _ in range(int(input())):
	p = list(map(int, input().split()))
	p.sort()
	a = p[0]
	b = p[1]
	c = p[2]
	k = abs(a - b) + abs(a - c) + abs(b - c)
	k1 = abs(a + 1 - b) + abs(a + 1 - c) + abs(b - c)
	k2 = abs(a - b) + abs(a - c + 1) + abs(b - c + 1)
	k3 = abs(a + 1 - b) + abs(a - c + 2) + abs(b - c + 1)
	k4 = abs(a + 1 - b + 1) + abs(a - c + 2) + abs(b - c)
	k5 = abs(a + 1 - b - 1) + abs(a + 1 - c + 1) + abs(b + 1 - c + 1)
	l = [k, k2, k3, k1, k4, k5]
	print(min(l))


n = int(input())
resultados = ''

def get_saltos(minimo, medio, maximo):
	global resultados
	total = 0
	if minimo == medio or maximo == medio:
		if maximo - medio == 1 or minimo - medio == -1:
			resultados += '0 '
		else:
			maximo -= 1
			minimo += 1
			resultados += str(maximo - minimo + maximo - medio + medio - minimo) + ' '
	elif medio - minimo == 1 and maximo - medio == 1:
		resultados += '0 '
	else:
		maximo -= 1
		minimo += 1
		resultados += str(maximo - minimo + maximo - medio + medio - minimo) + ' '
for i in range(n):
	numeros = input().split()
	maximo = 0
	minimo = 10000000000000000000000000000000000000000000000000
	medio = 0
	if numeros[0] == numeros[1] and numeros[2] == numeros[1]:
		resultados += '0 '
	else:
		a = int(numeros[0])
		b = int(numeros[1])
		c = int(numeros[2])
		if a >= b and a <= c:
			get_saltos(b, a, c)
		elif a >= c and a <= b:
			get_saltos(c, a, b)
		elif b >= a and b <= c:
			get_saltos(a, b, c)
		elif b >= c and b <= a:
			get_saltos(c, b, a)
		elif c >= a and c <= b:
			get_saltos(a, c, b)
		else:
			get_saltos(b, c, a)
for i in range(n):
	print(resultados.split()[i])


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	all_three = rl()
	(a, b, c) = all_three
	mini = min(a, b, c)
	maxi = max(a, b, c)
	if maxi - mini <= 1:
		print(0)
	else:
		all_three.remove(mini)
		all_three.remove(maxi)
		last = mini + 1
		ans = abs(mini + 1 - last) + abs(maxi - 1 - last) + abs(maxi - mini - 2)
		print(ans)


n = int(input())
t = []
for i in range(n):
	l = list(map(int, input().split(' ')))
	t.append(max(2 * (max(l) - min(l)) - 4, 0))
for i in range(n):
	print(t[i])


q = int(input())
answers = []
for i in range(q):
	s = input()
	l = list(map(int, s.split()))
	l.sort()
	(a, b, c) = (l[0], l[1], l[2])
	mn = abs(a - b) + abs(a - c) + abs(b - c)
	current = abs(a + 1 - b) + abs(a + 1 - (c - 1)) + abs(b - (c - 1))
	if current < mn:
		mn = current
	current = abs(a + 1 - b) + abs(a + 1 - c) + abs(b - c)
	if current < mn:
		mn = current
	current = abs(a - b) + abs(a - (c - 1)) + abs(b - (c - 1))
	if current < mn:
		mn = current
	if a == b and b != c:
		current = abs(a + 1 - (b + 1)) + abs(a + 1 - (c - 1)) + abs(b + 1 - (c - 1))
	if current < mn:
		mn = current
	if b == c and b != a:
		current = abs(a + 1 - (b - 1)) + abs(a + 1 - (c - 1)) + abs(b - 1 - (c - 1))
	if current < mn:
		mn = current
	answers.append(mn)
for i in range(len(answers)):
	print(answers[i])


import sys
import bisect as bi
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(a, b, c) = cin()
	a1 = [a, a - 1, a + 1]
	b1 = [b - 1, b, b + 1]
	c1 = [c, c - 1, c + 1]
	ans = 99999999999999
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ans = min(abs(c1[k] - a1[i]) + abs(c1[k] - b1[j]) + abs(a1[i] - b1[j]), ans)
	print(ans)


def main():
	Q = int(input())
	for _ in range(Q):
		res = solve()
		print(res)

def get_dist(nums):

	def get_dist_one(nums, i):
		return sum((abs(nums[j] - nums[i]) for (j, _) in enumerate(nums) if j > i))
	return sum((get_dist_one(nums, i) for (i, _) in enumerate(nums)))

def all_perm(nums, i):
	if i >= len(nums):
		yield get_dist(nums)
	else:
		for d in (-1, 0, 1):
			nums[i] += d
			for x in all_perm(nums, i + 1):
				yield x
			nums[i] -= d

def solve():
	nums = [int(x) for x in input().split()]
	return min(all_perm(nums, 0))
main()


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = max(a, b, c)
	e = min(a, b, c)
	if d - e >= 2:
		print(2 * (d - e) - 4)
	else:
		print(0)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	l = [[a - 1, b - 1, c - 1], [a - 1, b - 1, c], [a - 1, b, c - 1], [a - 1, b, c], [a, b - 1, c - 1], [a, b - 1, c], [a, b, c - 1], [a, b, c], [a + 1, b + 1, c + 1], [a + 1, b + 1, c], [a + 1, b, c + 1], [a + 1, b, c], [a, b + 1, c + 1], [a, b + 1, c], [a, b, c + 1], [a + 1, b + 1, c + 1], [a - 1, b - 1, c + 1], [a - 1, b + 1, c - 1], [a - 1, b + 1, c + 1], [a + 1, b - 1, c - 1], [a + 1, b - 1, c + 1], [a, b + 1, c - 1], [a - 1, b, c + 1], [a - 1, b + 1, c], [a, b + 1, c + 1], [a + 1, b, c - 1], [a + 1, b - 1, c], [a, b + 1, c - 1], [a + 1, b, c + 1], [a - 1, b - 1, c], [a, b - 1, c + 1], [a + 1, b - 1, c - 1], [a + 1, b - 1, c], [a + 1, b + 1, c - 1], [a + 1, b, c + 1], [a - 1, b + 1, c], [a, b - 1, c + 1], [a + 1, b - 1, c - 1], [a + 1, b - 1, c], [a, b + 1, c - 1]]
	res = 10000000000
	for i in range(len(l)):
		a = l[i][0]
		b = l[i][1]
		c = l[i][2]
		res1 = abs(a - b) + abs(a - c) + abs(b - c)
		if res1 < res:
			res = res1
	print(res)


n = int(input())
for i in range(n):
	v = list(map(int, input().split()))
	v.sort()
	if v[0] == v[1] and v[1] == v[2]:
		print('0')
		continue
	elif v[0] == v[1]:
		if v[1] + 1 < v[2]:
			v[2] = v[2] - 1
		v[0] = v[0] + 1
		v[1] = v[1] + 1
	elif v[1] == v[2]:
		if v[0] + 1 < v[1]:
			v[0] = v[0] + 1
		v[1] -= 1
		v[2] -= 1
	else:
		v[0] += 1
		v[2] -= 1
	s = 2 * v[2] - 2 * v[0]
	print(s)


def geta(l):
	return abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])

def getans(a, b, c, chka, chkb, chkc, ans):
	if chka == chkb == chkc == 1:
		ans.append(geta([a, b, c]))
		return
	else:
		if chka != 1:
			t = a
			p = a
			t = t - 1
			p = p + 1
			ans.append(geta([p, b, c]))
			ans.append(geta([t, b, c]))
			getans(t, b, c, 1, chkb, chkc, ans)
			getans(p, b, c, 1, chkb, chkc, ans)
		if chkb != 1:
			t = b
			p = b
			t = t - 1
			p = p + 1
			ans.append(geta([a, t, c]))
			ans.append(geta([a, p, c]))
			getans(a, t, c, chka, 1, chkc, ans)
			getans(a, p, c, chka, 1, chkc, ans)
		if chkc != 1:
			t = c
			p = c
			t = t - 1
			p = p + 1
			ans.append(geta([a, b, p]))
			ans.append(geta([a, b, t]))
			getans(a, b, t, chka, chkb, 1, ans)
			getans(a, b, p, chka, chkb, 1, ans)
q = int(input())
for _ in range(q):
	(a, b, c) = list(map(int, input().split(' ')))
	ans = []
	getans(a, b, c, 0, 0, 0, ans)
	print(min(ans))


def main():
	q = int(input())
	for i in range(int(q)):
		(a, b, c) = input().split(' ')
		a = int(a)
		b = int(b)
		c = int(c)
		pos = [a, b, c]
		pos.sort()
		if pos[2] - pos[0] > 2:
			ans = (pos[2] - pos[0] - 2) * 2
		else:
			ans = 0
		print(ans)
main()


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	dis = abs(a - b) + abs(a - c) + abs(b - c)
	if a == b == c:
		print(dis)
	else:
		print(max(0, dis - 4))


a = [[int(j) for j in input().split()] for i in range(int(input()))]
for i in range(len(a)):
	a[i] = sorted(a[i])
for i in a:
	if abs(i[0] - i[1]) + abs(i[0] - i[2]) + abs(i[1] - i[2]) <= 4:
		print(0)
	else:
		print(abs(i[0] - i[1]) + abs(i[0] - i[2]) + abs(i[1] - i[2]) - 4)


t = int(input())
for _ in range(t):
	x = list(map(int, input().split()))
	res = 2000000000.0
	for i1 in [-1, 0, 1]:
		for i2 in [-1, 0, 1]:
			for i3 in [-1, 0, 1]:
				tmp = [x[0] + i1, x[1] + i2, x[2] + i3]
				res = min(res, abs(tmp[0] - tmp[1]) + abs(tmp[0] - tmp[2]) + abs(tmp[1] - tmp[2]))
	print(res)


i = int(input())
for x in range(i):
	(a, b, c) = map(int, input().split())
	t = []
	for i in range(-1, 2):
		for ii in range(-1, 2):
			for iii in range(-1, 2):
				t.append(abs(a + i - b - ii) + abs(c + iii - b - ii) + abs(a + i - c - iii))
	print(min(t))


Q = int(input())
for q in range(0, Q):
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print(0)
	else:
		A = []
		if a > b:
			A.append(a - b)
		else:
			A.append(b - a)
		if b > c:
			A.append(b - c)
		else:
			A.append(c - b)
		if c > a:
			A.append(c - a)
		else:
			A.append(a - c)
		s = sum(A)
		if s <= 4:
			print(0)
		else:
			print(s - 4)


import math
t = int(input())
for w in range(t):
	(a, b, c) = sorted((int(i) for i in input().split()))
	if a == b and b == c:
		print(0)
	elif a == b and b != c:
		c -= 1
		if b != c:
			a += 1
			b += 1
		print(2 * (c - a))
	elif b == c and a != b:
		a += 1
		if a != b:
			b -= 1
			c -= 1
		print(2 * (c - a))
	else:
		a += 1
		c -= 1
		print(2 * (c - a))


t = int(input())
for _ in range(t):
	a = [int(s) for s in input().split()]
	x = max(a) - min(a)
	if x <= 2:
		print(0)
	else:
		x -= 2
		print(2 * x)


q = int(input())
for f in range(q):
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[1] and a[1] != a[2]:
		a[0] += 1
		a[1] += 1
	elif a[0] != a[1] and a[1] == a[2]:
		a[1] -= 1
		a[2] -= 1
	if a[0] != a[1]:
		a[0] += 1
	if a[2] != a[1]:
		a[2] += -1
	ans = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[0] - a[2])
	print(ans)


col = int(input())
for _ in range(col):
	L = sorted(list(map(int, input().split())))
	R = 2 * (L[2] - L[0])
	if R <= 4:
		print(0)
	if R >= 6:
		print(R - 4)


q = int(input())
for _ in range(q):
	p = list(map(int, input().split()))
	p.sort()
	d01 = abs(p[0] - p[1])
	d12 = abs(p[1] - p[2])
	if d01 > 0:
		p[0] += 1
	elif d01 == 0 and d12 > 0:
		p[0] += 1
		p[1] += 1
	d01 = abs(p[0] - p[1])
	d12 = abs(p[1] - p[2])
	if d12 > 0:
		p[2] -= 1
	elif d12 == 0 and d01 > 0:
		p[2] -= 1
		p[1] -= 1
	print(abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2]))


x = int(input())
tc = []
result = []

def calc(ctc1, ctc2):
	a = abs(ctc1[0] - ctc1[1])
	b = abs(ctc1[0] - ctc1[2])
	c = abs(ctc1[1] - ctc1[2])
	mi1 = a + b + c
	a = abs(ctc2[0] - ctc2[1])
	b = abs(ctc2[0] - ctc2[2])
	c = abs(ctc2[1] - ctc2[2])
	mi2 = a + b + c
	return min(mi1, mi2)

def actual(ctc):
	mi = calc(ctc, ctc)
	for i in range(3):
		ctcp1 = ctc
		ctcp1[i] += 1
		ctcs1 = ctc
		ctcs1[i] -= 1
		mi = min(mi, calc(ctcp1, ctcs1))
	ctcp1 = ctc
	ctcp1[0] += 1
	ctcp1[2] -= 1
	ctcs1 = ctc
	ctcs1[0] -= 1
	ctcs1[2] += 1
	mi = min(mi, calc(ctcp1, ctcs1))
	ctcp1 = ctc
	ctcp1[0] += 1
	ctcp1[2] += 1
	ctcs1 = ctc
	ctcs1[0] -= 1
	ctcs1[2] -= 1
	mi = min(mi, calc(ctcp1, ctcs1))
	ctcp1 = ctc
	ctcp1[1] += 1
	ctcp1[2] += 1
	ctcs1 = ctc
	ctcs1[1] -= 1
	ctcs1[2] -= 1
	mi = min(mi, calc(ctcp1, ctcs1))
	ctcp1 = ctc
	ctcp1[2] += 1
	ctcs1 = ctc
	ctcs1[2] -= 1
	mi = min(mi, calc(ctcp1, ctcs1))
	return mi

def mushkil(ctc):
	if ctc[0] == ctc[1] or ctc[2] == ctc[1] or ctc[0] == ctc[2]:
		if ctc[2] - ctc[1] == 1 or ctc[1] - ctc[2] == 1 or ctc[0] - ctc[2] == 1 or (ctc[2] - ctc[0] == 1):
			mi = 0
		else:
			mi = actual(ctc)
	else:
		mi = actual(ctc)
	return mi
for i in range(x):
	t = input()
	t = [int(q) for q in t.split(' ')]
	tc.append(t)
for i in range(x):
	ctc = tc[i]
	if ctc[0] == ctc[1] == ctc[2]:
		mi = 0
	elif max(tc[i]) - min(tc[i]) == 2:
		ma = ctc.index(max(tc[i]))
		ctc[ma] -= 1
		mi = mushkil(ctc)
	else:
		mi = mushkil(ctc)
	if mi == 0:
		result.append(mi)
	else:
		result.append(mi - 4)
for i in result:
	print(i)


for _ in range(int(input())):
	arr = [int(i) for i in input().split()]
	print(max(0, 2 * (max(arr) - min(arr)) - 4))


t = int(input())
for i in range(0, t):
	a = list(map(int, input().split()))
	a.sort()
	f = 1
	for j in range(0, len(a) - 1):
		if a[j + 1] - a[j] != 0 and a[j + 1] - a[j] != 1:
			f = 0
			break
	if f == 0:
		a[0] = a[0] + 1
		a[2] = a[2] - 1
		s = a[2] - a[1] + a[1] - a[0] + a[2] - a[0]
		print(s)
	else:
		print(0)


import sys
input = sys.stdin.readline
N = int(input())
for _ in range(N):
	(a, b, c) = map(int, input().split())
	res = float('inf')
	for i in range(3):
		x = a + (i - 1)
		y = b + 0
		z = c + 0
		for j in range(3):
			y = b + (j - 1)
			for k in range(3):
				z = c + (k - 1)
				res = min(res, abs(x - y) + abs(y - z) + abs(z - x))
	print(res)


import math
n = int(input())
for i in range(n):
	(a, b, c) = sorted(list(map(int, input().split())))
	t = math.floor((a + c) / 2)
	if t > a:
		a += 1
	elif t < a:
		a -= 1
	if t > b:
		b += 1
	elif t < b:
		b -= 1
	if t > c:
		c += 1
	elif t < c:
		c -= 1
	print(b - a + (c - b) + (c - a))


from math import *
for _ in range(int(input())):
	s = [int(a) for a in input().split()]
	y = abs(s[0] - s[1]) + abs(s[1] - s[2]) + abs(s[2] - s[0])
	if y - 4 > 0:
		print(y - 4)
	else:
		print(0)


q = int(input())
for i in range(q):
	abc = list(map(int, input().split()))
	abc = sorted(abc)
	a = abc[0]
	b = abc[1]
	c = abc[2]
	s = 0
	s += b - a
	s += c - b
	s += c - a
	if s <= 4:
		print(0)
	else:
		print(s - 4)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def list_input():
	return list(map(int, input().split()))

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	l = list_input()
	s = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[2] - l[1])
	print(max(0, s - 4))


def valueABC(ap, bp, cp):
	return abs(ap - bp) + abs(ap - cp) + abs(bp - cp)

def counting(a, b, c):
	distanceMax = c - a
	if distanceMax <= 2:
		return 0
	a = a + 1
	c = c - 1
	caseOne = valueABC(a, b - 1, c)
	caseTwo = valueABC(a, b, c)
	caseThree = valueABC(a, b + 1, c)
	minimum = min(caseOne, caseTwo, caseThree)
	return minimum
n = int(input())
for i in range(0, n):
	tableABC = list(map(int, input().split()))
	tableABC.sort()
	print(counting(tableABC[0], tableABC[1], tableABC[2]))


from sys import stdin
read = stdin.readline

def main():
	cases = int(read())
	for case in range(cases):
		nums = list(map(int, read().strip().split()))
		x = sum(nums) / 3
		for i in range(len(nums)):
			num = nums[i]
			if abs(num + 1 - x) < abs(num - x):
				nums[i] += 1
			elif abs(num - 1 - x) < abs(num - x):
				nums[i] -= 1
		print(abs(nums[0] - nums[1]) + abs(nums[0] - nums[2]) + abs(nums[1] - nums[2]))
main()


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	mins = abs(a - b) + abs(a - c) + abs(c - b)
	ar_a = [a - 1, a, a + 1]
	ar_b = [b - 1, b, b + 1]
	ar_c = [c - 1, c, c + 1]
	for i in ar_a:
		for j in ar_b:
			for k in ar_c:
				if abs(i - j) + abs(i - k) + abs(k - j) < mins:
					mins = abs(i - j) + abs(i - k) + abs(k - j)
	print(mins)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	(a, b, c) = l
	print(max((c - a - 2) * 2, 0))


q = int(input())
for test in range(q):
	(a, b, c) = map(int, input().split())
	ans = abs(a - b) + abs(b - c) + abs(a - c)
	for da in (-1, 1, 0):
		for db in (-1, 1, 0):
			for dc in (-1, 1, 0):
				ans = min(ans, abs(a + da - b - db) + abs(b + db - c - dc) + abs(a + da - c - dc))
	print(ans)


q = int(input())
for _ in range(q):
	(a, b, c) = [int(x) for x in input().split()]
	(a, b, c) = sorted([a, b, c])
	d = abs(a - b) + abs(b - c) + abs(a - c - 1)
	print(max(d - 5, 0))


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
T = int(input())

def solve(a: int, b: int, c: int) -> int:
	curr_min = float('inf')
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				first = abs(a + i - (b + j))
				second = abs(a + i - (c + k))
				third = abs(b + j - (c + k))
				total = first + second + third
				if curr_min > total:
					curr_min = total
	return curr_min
for test in range(T):
	(a, b, c) = read_ints()
	min_diff = solve(a, b, c)
	print(min_diff)


t = int(input())
for i in range(t):
	l = [int(x) for x in input().split()]
	l1 = l.copy()
	l1.sort()
	for j in range(2):
		if j == 0 and (l1[0] != l1[1] or l1[0] != l1[2]):
			l1[0] = l1[0] + 1
		elif j == 1 and (l1[2] != l1[0] or l1[2] != l1[1]):
			l1[2] = l1[2] - 1
	a = l1[1] - l1[0] + (l1[2] - l1[1]) + (l1[2] - l1[0])
	print(a) if a >= 0 else print(0)


for _ in range(int(input())):
	(a, b, c) = list((int(i) for i in input().split()))
	A = []
	A.append(a)
	A.append(b)
	A.append(c)
	A.sort()
	a = A[0]
	b = A[1]
	c = A[2]
	ans = -1
	if a == c:
		ans = 0
	elif a == b:
		if c - a == 1:
			c -= 1
		else:
			a += 1
			b += 1
			c -= 1
	elif b == c:
		if b - a == 1:
			a += 1
		else:
			a += 1
			b -= 1
			c -= 1
	else:
		a += 1
		c -= 1
	if ans != 0:
		print(abs(a - b) + abs(b - c) + abs(a - c))
	else:
		print(0)


q = int(input())
const = 10 ** 10
for i in range(q):
	(a, b, c) = map(int, input().split())
	a = [a - 1, a, a + 1]
	b = [b - 1, b, b + 1]
	c = [c - 1, c, c + 1]
	ans = const
	for elem1 in a:
		for elem2 in b:
			for elem3 in c:
				ans = min(ans, abs(elem1 - elem2) + abs(elem2 - elem3) + abs(elem3 - elem1))
	print(ans)


def main():
	Q = int(input())
	for _ in range(Q):
		res = solve()
		print(res)

def solve():
	nums = sorted((int(x) for x in input().split()))
	diffs = [a - b for (a, b) in zip(nums[1:], nums[:-1])]
	res = 2 * sum(diffs)
	if any((d >= 2 for d in diffs)):
		return res - 4
	for d in diffs:
		if d >= 1:
			res -= 2
	return res
main()


def dist_cal(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
tc = int(input())
for _ in range(tc):
	(a, b, c) = map(int, input().split())
	ans = []
	a = [a - 1, a, a + 1]
	b = [b - 1, b, b + 1]
	c = [c - 1, c, c + 1]
	for i in a:
		for j in b:
			for k in c:
				ans.append(dist_cal(i, j, k))
	print(min(ans))


x = int(input())
for i in range(x):
	(a, b, c) = list(map(int, input().split()))
	s = abs(a - b) + abs(b - c) + abs(a - c) - 4
	print(max(s, 0))


n = int(input())
for i in range(n):
	(a1, b1, c1) = map(int, input().split())
	res = 9999999999
	for a in range(-1, 2):
		for b in range(-1, 2):
			for c in range(-1, 2):
				res = min(res, abs(a1 + a - (b1 + b)) + abs(c1 + c - (b1 + b)) + abs(a1 + a - (c1 + c)))
	print(res)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : map(int, rr().split())

def solve(a, b, c):
	mi = min(a, b, c)
	mi += 1
	ma = max(a, b, c)
	ma -= 1
	if ma - mi >= 0:
		return 2 * (ma - mi)
	else:
		return 0
T = rri()
for i in range(T):
	(a, b, c) = rrm()
	ans = solve(a, b, c)
	print(ans)


for x in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	if len(set(l)) == 1:
		pass
	elif l[1] == l[0]:
		if l[2] == l[1] + 1:
			l[2] = l[2] - 1
		else:
			l[1] += 1
			l[0] += 1
			l[2] -= 1
	elif l[1] == l[2]:
		if l[0] + 1 == l[1]:
			l[0] = l[0] + 1
		else:
			l[1] -= 1
			l[0] += 1
			l[2] -= 1
	elif l[0] + 1 == l[1] and l[1] + 1 == l[2]:
		l[0] += 1
		l[2] -= 1
	else:
		l[0] += 1
		l[2] -= 1
	print(abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[2] - l[1]))


def solve():
	(a, b, c) = sorted(map(int, input().split()))
	if a >= c - 2:
		return 0
	else:
		return (c - a - 2) * 2
t = int(input())
for _ in range(t):
	print(solve())


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = abs(a - b) + abs(a - c) + abs(b - c)
	for a_ in (a - 1, a, a + 1):
		for b_ in (b - 1, b, b + 1):
			for c_ in (c - 1, c, c + 1):
				x = min(x, abs(a_ - b_) + abs(a_ - c_) + abs(b_ - c_))
	print(x)


q = int(input())
for z in range(q):
	arr = list(map(int, input().split()))
	arr.sort()
	s = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2])
	if s <= 4:
		print(0)
	else:
		print(s - 4)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for _ in range(int(input())):
	friends = [int(x) for x in input().split()]
	friends.sort()
	print(max(0, abs(friends[0] - friends[-1]) - 2) * 2)


for _ in range(int(input())):
	n = sorted(list(map(int, input().split())))
	if n[0] == n[1] == n[2]:
		print(0)
	elif n[0] == n[1]:
		if n[2] - n[1] == 1:
			print(0)
		else:
			print(2 * (n[2] - n[1] - 2))
	elif n[1] == n[2]:
		if n[1] - n[0] == 1:
			print(0)
		else:
			print(2 * (n[1] - n[0] - 2))
	else:
		n[0] += 1
		n[2] -= 1
		print(n[1] - n[0] + (n[2] - n[1]) + (n[2] - n[0]))


q = int(input())
while q:
	l = list(map(int, input().split(' ')))
	l.sort()
	(a, b, c) = l
	if a == b and b == c:
		pass
	elif a == b:
		c -= 1
		if c > b:
			a += 1
			b += 1
	elif b == c:
		a += 1
		if a < b:
			b -= 1
			c -= 1
	else:
		a += 1
		c -= 1
	print(abs(a - b) + abs(a - c) + abs(b - c))
	q -= 1


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = float('inf')
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				aa = a + i
				bb = b + j
				cc = c + k
				cur = abs(aa - bb) + abs(aa - cc) + abs(bb - cc)
				ans = min(ans, cur)
	print(ans)


for i in range(int(input())):
	l = sorted(list(map(int, input().split())))
	y = set(l)
	a = abs(l[0] - l[1]) + abs(l[2] - l[1]) + abs(l[0] - l[2])
	k = a - 4
	if len(y) == 1:
		print(0)
	elif len(y) != 1 and k >= 0:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c) = list(map(int, input().split()))
	print(max(0, 2 * (max(a, b, c) - min(a, b, c) - 2)))


from math import *

def f(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = [-1, -1, -1]
	m = f(a, b, c)
	while x[2] <= 1:
		m = min(f(a + x[0], b + x[1], c + x[2]), m)
		i = 0
		while i < 2 and x[i] == 1:
			x[i] = -1
			i += 1
		x[i] += 1
	print(m)


tc = int(input().strip())
for t in range(tc):
	(a, b, c) = map(int, input().strip().split())
	ans = 9999999999
	for i in [-1, 0, 1]:
		na = a + i
		for j in [-1, 0, 1]:
			nb = b + j
			for k in [-1, 0, 1]:
				nc = c + k
				td = abs(na - nb) + abs(nb - nc) + abs(nc - na)
				ans = min([ans, td])
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = list(map(int, input().split()))
	varios_list = []
	for q in [1, 0, -1]:
		for w in [1, 0, -1]:
			for e in [1, 0, -1]:
				varios_list.append(sum([abs(a + q - (b + w)), abs(a + q - (c + e)), abs(b + w - (c + e))]))
	if min(varios_list) <= 0:
		print(0)
	else:
		print(min(varios_list))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print('0')
	elif max(a, b, c) - 1 == min(a, b, c):
		print('0')
	elif max(a, b, c) - 1 == min(a, b, c) + 1:
		print('0')
	else:
		x = max(a, b, c) - 1 - (min(a, b, c) + 1)
		print(2 * x)


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	minimum = 9000000000
	for ar in range(a - 1, a + 2):
		for br in range(b - 1, b + 2):
			for cr in range(c - 1, c + 2):
				distance = abs(ar - br) + abs(ar - cr) + abs(br - cr)
				minimum = min(minimum, distance)
	print(minimum)


test = int(input())
for temp in range(test):
	(a, b, c) = map(int, input().split())
	if a > b:
		t = a
		a = b
		b = t
	if b > c:
		t = b
		b = c
		c = t
	if a > b:
		t = a
		a = b
		b = t
	if a != b and b != c:
		a += 1
		c -= 1
	elif a == b and b != c:
		a += 1
		b += 1
		if b != c:
			c -= 1
	elif b == c and b != a:
		b -= 1
		c -= 1
		if a != b:
			a += 1
	print(b - a + (c - a) + (c - b))


for _ in range(int(input())):
	l = sorted(list(map(int, input().split())))
	if l[0] == l[1] == l[2]:
		print(0)
	elif l[0] == l[1]:
		k = l[2] - l[1]
		if k == 1:
			print(0)
		else:
			print(2 * (l[2] - l[0] - 2))
	elif l[1] == l[2]:
		k = l[1] - l[0]
		if k == 1:
			print(0)
		else:
			print(2 * (l[2] - l[0] - 2))
	else:
		l[0] += 1
		l[2] -= 1
		print(2 * (max(l) - min(l)))


a = int(input())
for i in range(a):
	b = [int(i) for i in input().split()]
	maxx = max(b)
	minn = min(b)
	aver = sum(b) - maxx - minn
	if maxx - aver >= 1 and aver - minn >= 1:
		maxx = maxx - 1
		minn = minn + 1
	elif maxx - aver == 0 and aver - minn > 1:
		minn = minn + 1
		aver = aver - 1
		maxx = maxx - 1
	elif maxx - aver > 1 and aver - minn == 0:
		maxx = maxx - 1
		aver = aver + 1
		minn = minn + 1
	elif maxx - aver == 0 and aver - minn == 1:
		minn = minn + 1
	elif maxx - aver == 1 and aver - minn == 0:
		maxx = maxx - 1
	print(maxx - aver + maxx - minn + aver - minn)


q = int(input())
for _ in range(q):
	ans = 10 ** 10
	(a, b, c) = list(map(int, input().split()))
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				(x, y, z) = (a + i, b + j, c + k)
				t = abs(x - z) + abs(y - z) + abs(x - y)
				if t < ans:
					ans = t
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush, heappop
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()

def solve(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
t = ip()
for _ in range(t):
	(a, b, c) = inp()
	ch = [a, b, c]
	ch.sort()
	(a, b, c) = ch
	if len(set(ch)) == 1:
		ans = 0
	elif a == b:
		ans = min(solve(a + 1, b + 1, c - 1), solve(a + 1, b + 1, c))
	elif b == c:
		ans = min(solve(a + 1, b - 1, c - 1), solve(a, b - 1, c - 1))
	else:
		ans = solve(a + 1, b, c - 1)
	print(ans)


def main():
	(a, b, c) = map(int, input().split())
	ans = 3 * 10 ** 9
	for i in [1, 0, -1]:
		for j in [1, 0, -1]:
			for k in [1, 0, -1]:
				ans = min(ans, abs(a + i - b - j) + abs(a + i - c - k) + abs(b + j - c - k))
	print(ans)
q = int(input())
for i in range(q):
	main()


def f(x, y, z):
	return abs(x - y) + abs(y - z) + abs(z - x)
n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().strip().split())
	A = [a, a - 1, a + 1]
	B = [b, b - 1, b + 1]
	C = [c, c - 1, c + 1]
	m = f(a, b, c)
	for i in A:
		for j in B:
			for k in C:
				if m > f(i, j, k):
					m = f(i, j, k)
	print(m)


k = int(input())
for j in range(k):
	p = [int(i) for i in input().split()]
	ds = abs(p[2] - p[0]) + abs(p[2] - p[1]) + abs(p[1] - p[0])
	if max(p[2], p[0], p[1]) - min(p[2], p[0], p[1]) < 3:
		print(0)
	else:
		print(ds - 4)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	a = sorted(inpl())
	(a, b, c) = a
	res = b - a + c - a + c - b
	print(max(0, res - 4))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = max(abs(a - b), abs(a - c), abs(b - c))
	print(max(0, m - 2) * 2)


for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	l.sort()
	(a, b) = (l[0], l[-1])
	res = 2 * (b - a)
	for x in range(a - 1, a + 2):
		for y in range(b - 1, b + 2):
			if 0 <= 2 * (y - x) < res:
				res = 2 * (y - x)
	print(res)


a = int(input())
for _ in range(a):
	b = input().split()
	c = int(b[0])
	d = int(b[1])
	e = int(b[2])
	f = max(c, d, e) - min(c, d, e)
	print(max(f - 2, 0) * 2)


q = int(input())
for _ in range(q):
	(a, b, c) = [int(i) for i in input().split()]
	t = abs(a - b) + abs(a - c) + abs(b - c)
	if t - 4 < 0:
		t = 0
	else:
		t -= 4
	print(t)


for _ in range(int(input())):
	arr = [int(i) for i in input().split()]
	arr.sort()
	(a, b, c) = arr
	diff = b - a + (c - a) + (c - b)
	if diff > 4:
		print(diff - 4)
	else:
		print(0)


def solve(a, b, c):
	res = float('inf')
	for i in (a - 1, a, a + 1):
		for j in (b - 1, b, b + 1):
			for k in (c - 1, c, c + 1):
				d = abs(i - j) + abs(i - k) + abs(j - k)
				res = min(res, d)
	return res
tc = int(input())
for _ in range(tc):
	(a, b, c) = map(int, input().strip().split())
	print(solve(a, b, c))


n = int(input())
for i in range(n):
	s = list(map(int, input().split()))
	s.sort()
	a = s[0]
	b = s[1]
	c = s[2]
	if b - a >= 2:
		disdance1 = b - a - 2
		disdance2 = c - b
		disdance3 = c - a
		print(disdance1 + disdance2 + disdance3 - 2)
	elif c - b >= 2:
		disdance1 = c - b - 2
		disdance2 = b - a
		disdance3 = c - a
		print(disdance1 + disdance2 + disdance3 - 2)
	else:
		print(0)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	answer = abs(a - b) + abs(a - c) + abs(b - c)
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				ai = a + i
				bi = b + j
				ci = c + k
				answer = min(answer, abs(ai - bi) + abs(ai - ci) + abs(bi - ci))
	print(answer)


import sys
r_input = sys.stdin.readline
q = int(r_input())
for _ in range(q):
	(a, b, c) = map(int, r_input().split())
	l = []
	for a1 in [a - 1, a, a + 1]:
		for b1 in [b - 1, b, b + 1]:
			for c1 in [c - 1, c, c + 1]:
				l.append(abs(a1 - b1) + abs(a1 - c1) + abs(c1 - b1))
	print(min(l))


n = int(input())
for _ in range(n):
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if a == b == c:
		print(0)
	elif a != b != c:
		if a + 1 == b == c - 1:
			print(0)
		else:
			a += 1
			c -= 1
			print(abs(a - b) + abs(a - c) + abs(b - c))
	elif a == b != c:
		if c - 1 == b or c - 1 == b + 1:
			print(0)
		else:
			c -= 1
			print(min(abs(a + 1 - b + 1) + abs(a + 1 - c + 1) + abs(b + 1 - c + 1), abs(a - b) + abs(a - c) + abs(b - c)))
	elif a + 1 == b or a + 1 == b - 1:
		print(0)
	else:
		a += 1
		b -= 1
		c -= 1
		print(abs(a - b) + abs(a - c) + abs(b - c))


for _ in range(int(input())):
	value = []
	case = input('')
	value.append(case.split(' '))
	value[0] = list(map(int, value[0]))
	a = value[0][0]
	b = value[0][1]
	c = value[0][2]
	tpd = abs(a - b) + abs(a - c) + abs(c - b)
	if tpd - 4 <= 0:
		ans = 0
	else:
		ans = tpd - 4
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	Max = max(a, b, c)
	Min = min(a, b, c)
	if Min == Max:
		print(0)
	else:
		Max -= 1
		Min += 1
		if Max - Min >= 0:
			print(2 * (Max - Min))
		else:
			print(0)


def main():

	def abs(a):
		if a >= 0:
			return int(a)
		else:
			return int(-a)

	def minimum_transformation(a, b, c):
		a = int(a)
		b = int(b)
		c = int(c)
		min = -1
		for k in [-1, 0, 1]:
			for j in [-1, 0, 1]:
				for l in [-1, 0, 1]:
					if abs(a + k - b - j) + abs(b + j - c - l) + abs(c + l - a - k) <= min or min < 0:
						min = abs(a + k - b - j) + abs(b + j - c - l) + abs(c + l - a - k)
		return min
	q = int(input())
	for k in range(q):
		donnees = input().split(' ')
		x = donnees[0]
		y = donnees[1]
		z = donnees[2]
		print(minimum_transformation(x, y, z))
main()


def ravnull(arr):
	if arr[0] == arr[1] == arr[2]:
		print(0)
		return 1
	else:
		return 0
for _ in [0] * int(input()):
	a = sorted(list(map(int, input().split())))
	if ravnull(a):
		continue
	if a[0] == a[1]:
		a[0] += 1
		a[1] += 1
	elif a[0] < a[1]:
		a[0] += 1
	if ravnull(a):
		continue
	if a[1] == a[2]:
		a[1] -= 1
		a[2] -= 1
	elif a[1] < a[2]:
		a[2] -= 1
	if ravnull(a):
		continue
	print(a[1] - a[0] + a[2] - a[0] + a[2] - a[1])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(l()[0]):
	(x, y, z) = l()
	X = [x - 1, x, x + 1]
	Y = [y - 1, y, y + 1]
	Z = [z - 1, z, z + 1]
	m = 10 ** 10
	for i in X:
		for j in Y:
			for k in Z:
				m = min(m, abs(i - j) + abs(j - k) + abs(k - i))
	print(m)


t = int(input())
i = 0
while i < t:
	(a, b, c) = map(int, input().split())
	diff = []
	diff.append(abs(a - b))
	diff.append(abs(b - c))
	diff.append(abs(a - c))
	s = sum(diff)
	if s - 4 <= 0:
		print(0)
	else:
		print(s - 4)
	i = i + 1


t = int(input())
while t != 0:
	t -= 1
	(a, b, c) = [int(x) for x in input().split()]
	if a == b and b == c:
		print(0)
	else:
		x = []
		x.append(a)
		x.append(b)
		x.append(c)
		x.sort()
		if x[0] == x[1] or x[1] == x[2]:
			if x[0] == x[1]:
				if x[2] - x[1] == 1:
					print(0)
				else:
					print(abs(x[2] - x[1] - 2) * 2)
			elif x[1] - x[0] == 1:
				print(0)
			else:
				print(abs(x[1] - x[0] - 2) * 2)
		elif abs(x[1] - x[0]) == 1 or abs(x[2] - x[1]) == 1:
			if abs(x[1] - x[0]) == 1:
				print((x[2] - x[1] - 1) * 2)
			else:
				print((x[1] - x[0] - 1) * 2)
		else:
			print(2 * x[2] - 2 * x[0] - 4)


from sys import stdin
q = int(stdin.readline().strip())
for _ in range(q):
	cood = list(map(int, stdin.readline().split()))
	cood.sort()
	(a, b, c) = cood
	if c - a >= 2:
		a += 1
		c -= 1
		if b < a:
			b += 1
		elif b > c:
			b -= 1
	else:
		if a < c:
			a += 1
		if b < a:
			b += 1
		elif b > c:
			b -= 1
	print(abs(b - a) + abs(c - a) + abs(c - b))


x = int(input())
for _ in range(x):
	inp = sorted(map(int, input().split()))
	x = inp[0]
	y = inp[1]
	z = inp[2]
	f = abs(y - x) + abs(z - y) + abs(z - x)
	if f <= 4:
		print(0)
	else:
		if x == y != z:
			print(f - 4)
		if y == z and y != x:
			print(f - 4)
		if x != y != z:
			print(abs(y - (x + 1)) + abs(z - 1 - y) + abs(z - 1 - (x + 1)))


def distance(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def main():
	q = eval(input())
	count = 0
	while count < q:
		user_input = input().split()
		a = int(user_input[0])
		b = int(user_input[1])
		c = int(user_input[2])
		result = distance(a, b, c)
		for i in range(-1, 2):
			for j in range(-1, 2):
				for k in range(-1, 2):
					temp_result = distance(a + i, b + j, c + k)
					if temp_result < result:
						result = temp_result
		print(result)
		count += 1
main()


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = ii()
for _ in range(t):
	(a, b, c) = ml()
	d = [a, b, c]
	d.sort()
	if d[0] != d[1] and d[1] != d[2]:
		d[0] += 1
		d[2] -= 1
	elif d[0] == d[1] and d[2] != d[1]:
		d[0] += 1
		d[1] += 1
		if d[2] != d[1]:
			d[2] -= 1
	elif d[0] != d[1] and d[1] == d[2]:
		d[1] -= 1
		d[2] -= 1
		if d[1] != d[0]:
			d[0] += 1
	print(d[2] - d[0] + d[2] - d[1] + d[1] - d[0])


def calculate(a, b, c):
	return abs(a - c) + abs(a - b) + abs(b - c)

def solve(a, b, c):
	ans = calculate(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				a1 = a + i
				b1 = b + j
				c1 = c + k
				ans = min(ans, calculate(a1, b1, c1))
	return ans
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	print(solve(a, b, c))


def diff(x, y, z):
	return abs(x - y) + abs(y - z) + abs(x - z)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	res = diff(a, b, c)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				na = a + i
				nb = b + j
				nc = c + k
				res = min(res, diff(na, nb, nc))
	print(res)


t = int(input())
l = []
solution = []
b = 0

def abc(a, b, c):
	p = []
	(x, y, z) = (0, 0, 0)
	total = a + b + c
	mi = min(a, b, c)
	mx = max(a, b, c)
	md = total - mx - mi
	p.append(md + 1)
	p.append(md)
	p.append(md - 1)
	p.append(mi + 1)
	p.append(mi)
	p.append(mi - 1)
	p.append(mx + 1)
	p.append(mx)
	p.append(mx - 1)
	x = p[0]
	y = p[0] - min(abs(p[0] - p[3]), abs(p[0] - p[4]), abs(p[0] - p[5]))
	z = abs(p[0] - min(abs(p[0] + p[6]), abs(p[0] + p[7]), abs(p[0] + p[8])))
	final1 = abs(x - y) + abs(y - z) + abs(z - x)
	x = p[1]
	y = p[1] - min(abs(p[1] - p[3]), abs(p[1] - p[4]), abs(p[1] - p[5]))
	z = abs(p[1] - min(abs(p[1] + p[6]), abs(p[1] + p[7]), abs(p[1] + p[8])))
	final2 = abs(x - y) + abs(y - z) + abs(z - x)
	x = p[2]
	y = p[2] - min(abs(p[2] - p[3]), abs(p[2] - p[4]), abs(p[2] - p[5]))
	z = abs(p[2] - min(abs(p[2] + p[6]), abs(p[2] + p[7]), abs(p[2] + p[8])))
	final3 = abs(x - y) + abs(y - z) + abs(z - x)
	if final1 > final2:
		if final3 > final2:
			return final2
		else:
			return final3
	elif final3 > final1:
		return final1
	else:
		return final3
for z in range(t):
	l = list(map(int, input().split()))
	(a, b, c) = (l[0], l[1], l[2])
	(final1, final2, final3) = (0, 0, 0)
	solution.append(abc(a, b, c))
for i in range(len(solution)):
	print(solution[i])


casos = int(input())
for i in range(casos):
	numeros = [int(x) for x in input().split()]
	numeros.sort()
	(a, b, c) = numeros
	if a != b and b != c:
		if b - a > 1:
			b -= 1
		if c - a > 1:
			c -= 1
		a += 1
	elif a == b and b != c:
		if c - b > 1:
			c -= 1
		a += 1
		b += 1
	elif b == c and a != b:
		if b - a > 1:
			a += 1
		c -= 1
		b -= 1
	print(abs(a - b) + abs(a - c) + abs(b - c))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	s = list(set(l))
	if len(s) == 1:
		print(0)
	if len(s) >= 2:
		print(max(0, l[2] - l[0] - 2) * 2)


n = int(input())
for i in range(n):
	lists = [int(x) for x in input().split()]
	lists.sort()
	xx = lists[2] - lists[0]
	if xx <= 2:
		print(0)
	else:
		print(2 * (xx - 2))


N = int(input())
for _ in range(N):
	(a, b, c) = sorted(map(int, input().split()))
	if a == b and a < c:
		a += 1
		b += 1
		if a != c:
			c -= 1
		print(abs(a - c) + abs(a - b) + abs(b - c))
		continue
	if a < b:
		a += 1
	if c >= b and c != a:
		c -= 1
	if b != c and b != a:
		b -= 1
	print(abs(a - c) + abs(a - b) + abs(b - c))


for _ in range(int(input())):
	A = list(map(int, input().split()))
	A.sort()
	if A[1] == A[0] and A[1] == A[2]:
		print(0)
	elif A[1] == A[0]:
		if A[2] - A[0] > 1:
			print(2 * (A[2] - A[1] - 2))
		else:
			print(0)
	elif A[1] == A[2]:
		if A[2] - A[0] > 1:
			print(2 * (A[1] - A[0] - 2))
		else:
			print(0)
	else:
		print(A[2] - A[0] - 2 + A[1] - A[0] - 1 + A[2] - A[1] - 1)


q = int(input())
while q > 0:
	p = [int(ele) for ele in input().split()]
	p.sort()
	if p[0] == p[1] and p[1] == p[2]:
		print(0)
	elif p[0] == p[1] and p[2] - p[1] == 1:
		p[2] -= 1
		print(abs(p[0] - p[2]) + abs(p[1] - p[2]))
	elif p[0] == p[1]:
		p[2] -= 1
		p[0] += 1
		p[1] += 1
		print(abs(p[0] - p[2]) + abs(p[1] - p[2]))
	elif p[1] == p[2] and p[1] - p[0] == 1:
		p[0] += 1
		print(abs(p[0] - p[1]) + abs(p[0] - p[2]))
	elif p[1] == p[2]:
		p[0] += 1
		p[1] -= 1
		p[2] -= 1
		print(abs(p[0] - p[1]) + abs(p[0] - p[2]))
	else:
		p[0] += 1
		p[2] -= 1
		print(abs(p[0] - p[1]) + abs(p[0] - p[2]) + abs(p[1] - p[2]))
	q -= 1


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	listy = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				listy.append(abs(a + i - b - j) + abs(c + k - b - j) + abs(a + i - c - k))
	print(min(listy))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	h = max(a, b, c) - min(a, b, c) - 2
	if h > 0:
		print(2 * h)
	else:
		print(0)


for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	m = max(a, b, c) - min(a, b, c)
	if m > 1:
		print((m - 2) * 2)
	else:
		print('0')


for _ in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	k = l[2] - l[1] + l[2] - l[0] + l[1] - l[0]
	print(max(0, k - 4))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split(' '))
	y = [a, b, c]
	y = sorted(y)
	if y[1] - y[0] == 0:
		if y[2] - y[1] <= 1:
			print(0)
		else:
			y[2] -= 1
			y[1] += 1
			y[0] += 1
			print(y[2] - y[0] + y[2] - y[1])
	elif y[2] - y[1] == 0:
		if y[1] - y[0] <= 1:
			print(0)
		else:
			y[0] += 1
			y[2] -= 1
			y[1] -= 1
			print(y[1] - y[0] + y[2] - y[0])
	else:
		y[0] = y[0] + 1
		y[2] -= 1
		print(y[1] - y[0] + y[2] - y[1] + y[2] - y[0])


def dis(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = []
	ans.append(dis(a, b, c))
	ans.append(dis(a, b + 1, c))
	ans.append(dis(a, b - 1, c))
	ans.append(dis(a, b, c + 1))
	ans.append(dis(a, b, c - 1))
	ans.append(dis(a, b + 1, c + 1))
	ans.append(dis(a, b + 1, c - 1))
	ans.append(dis(a, b - 1, c + 1))
	ans.append(dis(a, b - 1, c - 1))
	ans.append(dis(a + 1, b + 1, c))
	ans.append(dis(a + 1, b - 1, c))
	ans.append(dis(a + 1, b, c + 1))
	ans.append(dis(a + 1, b, c - 1))
	ans.append(dis(a + 1, b + 1, c + 1))
	ans.append(dis(a + 1, b + 1, c - 1))
	ans.append(dis(a + 1, b - 1, c + 1))
	ans.append(dis(a + 1, b - 1, c - 1))
	ans.append(dis(a - 1, b + 1, c))
	ans.append(dis(a - 1, b - 1, c))
	ans.append(dis(a - 1, b, c + 1))
	ans.append(dis(a - 1, b, c - 1))
	ans.append(dis(a - 1, b + 1, c + 1))
	ans.append(dis(a - 1, b + 1, c - 1))
	ans.append(dis(a - 1, b - 1, c + 1))
	ans.append(dis(a - 1, b - 1, c - 1))
	print(min(ans))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	arr = [0, -1, 1]
	mn = 10 ** 15 + 7
	for i in arr:
		for j in arr:
			for k in arr:
				s = abs(a + i - b - j) + abs(a + i - c - k) + abs(b + j - c - k)
				if s < mn:
					mn = s
	print(mn)


q = int(input())
for x in range(0, q):
	a = list(map(int, input().split()))
	a.sort()
	l = a[2] - a[1] + a[1] - a[0] + a[2] - a[0]
	l -= 4
	if l < 0:
		l = 0
	print(l)


t = int(input())
for f in range(t):
	(a, b, c) = map(int, input().split())
	res = []
	A = [a, a + 1, a - 1]
	B = [b, b + 1, b - 1]
	C = [c, c + 1, c - 1]
	for i in range(3):
		for j in range(3):
			for k in range(3):
				res.append(abs(A[i] - B[j]) + abs(A[i] - C[k]) + abs(B[j] - C[k]))
	print(min(res))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	list1 = [a - 1, a, a + 1]
	list2 = [b - 1, b, b + 1]
	list3 = [c - 1, c, c + 1]
	mini = 2000000002
	for i in range(3):
		for j in range(3):
			for k in range(3):
				if abs(list1[i] - list2[j]) + abs(list1[i] - list3[k]) + abs(list2[j] - list3[k]) < mini:
					mini = abs(list1[i] - list2[j]) + abs(list1[i] - list3[k]) + abs(list2[j] - list3[k])
	print(mini)


from math import floor, ceil
t = int(input())
for _ in range(t):
	(a, b, c) = sorted(list(map(int, input().split())))
	print(max(2 * (c - a - 2), 0))


def sortNumbers(a1, b1, c1):
	a = min(a1, b1, c1)
	c = max(a1, b1, c1)
	b = a1 + b1 + c1 - a - c
	return (a, b, c)

def threeFriends(givenInput):
	input = givenInput.split('\n')
	input = input[1:]
	result = ''
	for i in range(len(input)):
		singleLine = input[i]
		singleLine = singleLine.split()
		a = singleLine[0]
		b = singleLine[1]
		c = singleLine[2]
		a = eval(a)
		b = eval(b)
		c = eval(c)
		(a, b, c) = sortNumbers(a, b, c)
		if a == b == c:
			a = b = c = 0
		elif a == b:
			a = a + 1
			b = b + 1
			if a < c:
				c = c - 1
		elif b == c:
			b = b - 1
			c = c - 1
			if a < b:
				a = a + 1
		else:
			a = a + 1
			b = b
			c = c - 1
		first = b - a
		second = c - b
		third = c - a
		summ = first + second + third
		if i < len(input) - 1:
			result = result + str(summ) + '\n'
		else:
			result = result + str(summ)
	print(result)
n = eval(input())
givenInput = str(n) + '\n'
for i in range(n):
	singleLine = input()
	if i == n - 1:
		givenInput += singleLine
		continue
	givenInput += singleLine + '\n'
threeFriends(givenInput)


t = int(input())
for i in range(t):
	min = -1
	(a, b, c) = map(int, input().split())
	A = [a, a - 1, a + 1]
	B = [b, b - 1, b + 1]
	C = [c, c - 1, c + 1]
	for i in A:
		for j in B:
			for k in C:
				if min == -1 or abs(i - j) + abs(j - k) + abs(k - i) < min:
					min = abs(i - j) + abs(j - k) + abs(k - i)
	print(min)


from math import ceil

def solve():
	a = list(map(int, input().split()))
	e = round(sum(a) / 3)
	for i in range(3):
		if a[i] > e:
			a[i] -= 1
		elif a[i] < e:
			a[i] += 1
	print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
q = int(input())
for i in range(q):
	solve()


t = int(input())
for _ in range(t):
	lis = list(map(int, input().split()))
	(a, b, c) = sorted(lis)
	if a == b == c:
		print(0)
	elif a == b:
		if c - b == 1:
			print(0)
		else:
			print(2 * (c - b - 2))
	elif b == c:
		if b - a == 1:
			print(0)
		else:
			print(2 * (b - a - 2))
	else:
		print(2 * (c - a - 2))


def dis(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	ls = list(map(int, input().split()))
	ls.sort()
	s = set(ls)
	if len(s) == 1:
		print('0')
		continue
	elif len(s) == 2:
		if ls[0] == ls[1]:
			ls[0] += 1
			ls[1] += 1
			if ls[0] == ls[2]:
				print(dis(ls[0], ls[0], ls[2]))
				continue
			else:
				print(dis(ls[0], ls[0], ls[2] - 1))
				continue
		else:
			ls[1] -= 1
			ls[2] -= 1
			if ls[0] == ls[1]:
				print(dis(ls[0], ls[1], ls[1]))
				continue
			else:
				print(dis(ls[0] + 1, ls[1], ls[1]))
				continue
	else:
		print(dis(ls[0] + 1, ls[1], ls[2] - 1))


q = int(input())
for _ in range(q):
	(a, b, c) = [int(x) for x in input().split()]
	print(2 * (max(max([a, b, c]) - min([a, b, c]), 2) - 2))


def d(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	(c, b, a) = sorted([a, b, c])
	if a == b == c:
		print(0)
	elif b == c:
		x = d(a - 1, b + 1, c + 1)
		y = d(a, b + 1, c + 1)
		print(min(x, y))
	elif a == b:
		x = d(a - 1, b - 1, c + 1)
		y = d(a, b, c + 1)
		print(min(x, y))
	else:
		print(d(a - 1, b, c + 1))


n = int(input())
for k in range(n):
	entrada = input().split(' ')
	entrada.sort()
	a = int(entrada[0])
	b = int(entrada[1])
	c = int(entrada[2])
	medio = (a + c) // 2
	if a <= medio:
		if a != medio:
			a += 1
	else:
		a -= 1
	if b <= medio:
		if b != medio:
			b += 1
	else:
		b -= 1
	if c <= medio:
		if c != medio:
			c += 1
	else:
		c -= 1
	d = abs(a - b) + abs(a - c) + abs(b - c)
	print(d)


t = int(input())
while t:
	t = t - 1
	a = [int(x) for x in input().split()]
	x = []
	a.sort()
	b = a[1]
	c = a[2]
	a = a[0]
	(p, q, r) = (a, b, c)
	(a, b, c) = (a - 1, b - 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b - 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b + 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b + 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b - 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b - 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b + 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b + 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b - 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b - 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b + 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b + 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b - 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b - 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b + 1, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b + 1, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b - 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b - 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b + 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b + 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b - 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b - 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b + 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b + 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b, c + 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b + 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a + 1, b, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b, c - 1)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a, b - 1, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	(a, b, c) = (a - 1, b, c)
	x.append(2 * (c - a))
	(a, b, c) = (p, q, r)
	x.append(2 * (c - a))
	if min(x) < 0:
		print(0)
	else:
		print(min(x))


def mindistance(a, b, c):
	la = [a, a - 1, a + 1]
	lb = [b, b - 1, b + 1]
	lc = [c, c - 1, c + 1]
	mindis = []
	for i in la:
		for j in lb:
			for k in lc:
				mindis.append(abs(i - j) + abs(i - k) + abs(j - k))
	return min(mindis)
x = eval(input())
inputs = []
for i in range(x):
	nums = input()
	nums = nums.split()
	inputs.append(nums)
for k in range(len(inputs)):
	print(mindistance(int(inputs[k][0]), int(inputs[k][1]), int(inputs[k][2])))


for i in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	b = b - 1 if b - a > 1 else b + 1 if c - b > 1 else b
	a = a + 1 if a < b else a
	c = c - 1 if b < c else c
	print(c - a << 1)


def ans(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	res = ans(a, b, c)
	for i in [-1, 0, 1]:
		for j in [-1, 0, 1]:
			for k in [-1, 0, 1]:
				res = min(res, ans(a + i, b + j, c + k))
	print(res)


from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
for _ in range(val()):
	(a, b, c) = sorted(li())
	if a == b and c > b + 1:
		a += 1
		b += 1
		c -= 1
	elif b == c and a < b - 1:
		a += 1
		b -= 1
		c -= 1
	else:
		if a != b:
			a += 1
		if b != c:
			c -= 1
	print(abs(a - b) + abs(b - c) + abs(c - a))


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	a = int(p[0])
	b = int(p[1])
	c = int(p[2])
	G = 0
	if a == b and b == c:
		print(0)
	else:
		if a == b:
			if c > a:
				c = c - 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					a = a + 1
					b = b + 1
			else:
				c = c + 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					a = a - 1
					b = b - 1
		elif a == c:
			if b > a:
				b = b - 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					a = a + 1
					c = c + 1
			else:
				b = b + 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					a = a - 1
					c = c - 1
		elif b == c:
			if a > b:
				a = a - 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					b = b + 1
					c = c + 1
			else:
				a = a + 1
				if a == b and b == c:
					print(0)
					G = 1
				else:
					b = b - 1
					c = c - 1
		else:
			p.sort(key=int)
			a = int(p[0]) + 1
			b = int(p[1])
			c = int(p[2]) - 1
		if G == 0:
			print(abs(a - b) + abs(a - c) + abs(b - c))


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
q = int(input())
for _ in range(q):
	(a, b, c) = sorted(list(map(int, input().split())))
	if c - a > 1:
		print(2 * (c - a - 2))
	else:
		print(0)


from sys import stdin
t = int(stdin.readline())
while t:
	x = list(map(int, stdin.readline().split()))
	x.sort()
	if x[0] == x[1] and x[1] != x[2]:
		x[0] += 1
		x[1] += 1
		if x[2] != x[1]:
			x[2] -= 1
	elif x[1] == x[2] and x[2] != x[0]:
		x[1] -= 1
		x[2] -= 1
		if x[0] != x[1]:
			x[0] += 1
	else:
		if x[0] < x[1]:
			x[0] += 1
		if x[2] > x[1]:
			x[2] -= 1
	print(abs(x[0] - x[1]) + abs(x[1] - x[2]) + abs(x[0] - x[2]))
	t -= 1


for _ in range(int(input())):
	l = sorted(map(int, input().split()))

	def minimum_distance(l, i):
		if i >= len(l):
			return abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
		ans = 1e+18
		for val in [-1, 0, 1]:
			li = l[:]
			li[i] += val
			ans = min(ans, minimum_distance(li, i + 1))
		return ans
	print(minimum_distance(l, 0))


q = int(input())
for i in range(q):
	arr = map(int, input().split())
	arr = list(arr)
	arr.sort()
	if arr[0] == arr[2]:
		b = 0
	elif arr[0] == arr[1]:
		arr[2] -= 1
		if arr[1] != arr[2]:
			arr[1] += 1
			arr[0] += 1
	elif arr[1] == arr[2]:
		arr[0] += 1
		if arr[0] != arr[1]:
			arr[1] -= 1
			arr[2] -= 1
	else:
		arr[0] += 1
		arr[2] -= 1
	print(abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]))


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	if a == b == c:
		print(0)
		return
	if l[0] != l[1]:
		l[0] += 1
	else:
		l[0] += 1
		l[1] += 1
	if l[0] == l[1] == l[2]:
		print(0)
		return
	if l[1] != l[2]:
		l[2] -= 1
	else:
		l[1] -= 1
		l[2] -= 1
	(a, b, c) = l
	print(abs(a - b) + abs(b - c) + abs(a - c))
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


for _ in range(int(input())):
	mylist = []
	(a, b, c) = input().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	mylist.append(a)
	mylist.append(b)
	mylist.append(c)
	mylist.sort()
	y = mylist[2] - mylist[0]
	y -= 2
	if y < 0:
		y = 0
	print(2 * y)


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
q = int(input())
for i in range(q):
	(a, b, c) = sorted(map(int, input().split()))
	ans = max(0, 2 * c - 2 * a - 4)
	print(ans)


n = int(input())
for i in range(n):
	fri = list(map(int, input().split()))
	(a, b, c) = fri
	liste = []
	temp = lambda x, y, z: abs(x - y) + abs(x - z) + abs(y - z)
	merak = temp(a, b, c)
	if merak >= 4:
		print(merak - 4)
	else:
		print(0)


def friends(a, b, c):
	ans = float('inf')
	a_val = [a - 1, a, a + 1]
	b_val = [b - 1, b, b + 1]
	c_val = [c - 1, c, c + 1]
	for i in a_val:
		for j in b_val:
			for k in c_val:
				cur = abs(i - j) + abs(i - k) + abs(j - k)
				ans = min(ans, cur)
	return ans
q = int(input())
for i in range(q):
	(a, b, c) = list(map(int, input().rstrip().split()))
	print(friends(a, b, c))


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	d = []
	a = a or a - 1 or a + 1
	b = b or b - 1 or b + 1
	c = c or c - 1 or c + 1
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = abs(a + k - (b + j)) + abs(b + j - (c + i)) + abs(c + i - (a + k))
				d.append(x)
	print(min(d))


all_operation = int(input())
for l in range(all_operation):
	a = input().split(' ')
	for i in range(len(a)):
		a[i] = int(a[i])
	a.sort()
	if a[0] != a[1] != a[2]:
		a[0] += 1
		a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	elif a[0] == a[1] == a[2]:
		print(0)
	elif a[0] == a[1]:
		if a[2] - a[1] == 1:
			print(0)
		else:
			a[0] += 1
			a[1] += 1
			a[2] -= 1
			print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))
	elif a[1] - a[0] == 1:
		print(0)
	else:
		a[0] += 1
		a[1] -= 1
		a[2] -= 1
		print(abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]))


q = int(input())
for i in range(q):
	l = input().split()
	k = 0
	for k in range(3):
		l[k] = int(l[k])
	l = sorted(l)
	if l[1] > l[0] and l[1] < l[2]:
		print(2 * (l[2] - l[0] - 2))
	elif l[0] == l[1] and l[1] == l[2]:
		print(0)
	elif l[0] == l[1] and l[1] + 1 < l[2]:
		print(2 * (l[2] - l[1] - 2))
	elif l[2] == l[1] and l[0] + 1 < l[1]:
		print(2 * (l[1] - l[0] - 2))
	else:
		print(0)


t = int(input())
while t != 0:
	dis = 0
	x = [int(x) for x in input().split()]
	x.sort()
	if x[0] != x[1]:
		x[0] = x[0] + 1
		if x[1] != x[2]:
			x[2] = x[2] - 1
		elif x[1] != x[0]:
			x[1] = x[1] - 1
			x[2] = x[2] - 1
	elif x[1] != x[2]:
		x[0] = x[0] + 1
		x[1] = x[1] + 1
		if x[1] != x[2]:
			x[2] = x[2] - 1
	a = x[1] - x[0]
	b = x[2] - x[1]
	c = x[2] - x[0]
	print(a + b + c)
	t = t - 1


def solve(arr):
	a = max(arr)
	b = min(arr)
	return str(max(a - b - 2, 0) * 2) + '\n'
line = input().split(' ')
output = ''
for i in range(int(line[0])):
	arr = [int(x) for x in input().split(' ')]
	output += solve(arr)
print(output)


n = int(input())
d = []
for i in range(n):
	(a, b, c) = tuple(map(int, input().split()))
	if 2 * max(abs(c - a), abs(b - a), abs(b - c)) - 4 > 0:
		d.append(2 * max(abs(c - a), abs(b - a), abs(b - c)) - 4)
	else:
		d.append(0)
for j in d:
	print(j)


q = int(input())
for query in range(q):
	p = [int(x) for x in input().split(' ')]
	if len(set(p)) == 1:
		ans = 0
	elif len(set(p)) == 2:
		ans = max(2 * (max(p) - min(p) - 2), 0)
	else:
		ans = 2 * (max(p) - min(p) - 2)
	print(ans)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	l.sort()
	(a, b, c) = (l[0], l[1], l[2])
	r = 0
	if len(set(l)) == 3:
		a = a + 1
		c = c - 1
		r = abs(a - b) + abs(b - c) + abs(a - c)
	elif len(set(l)) == 2:
		if a == b:
			a = a + 1
			b = b + 1
			if a == c:
				r = abs(a - b) + abs(b - c) + abs(a - c)
			else:
				r = abs(a - b) + abs(b - c) + abs(a - c) - 2
		else:
			a = a + 1
			if a == b:
				r = abs(a - b) + abs(b - c) + abs(a - c)
			else:
				r = abs(a - b) + abs(b - c) + abs(a - c) - 2
	else:
		r = 0
	print(r)


def minDistance(x, y, z):
	return abs(x - y) + abs(y - z) + abs(x - z)
n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	ans = minDistance(a, b, c)
	for da in range(-1, 2):
		for db in range(-1, 2):
			for dc in range(-1, 2):
				newDistance_a = a + da
				newDistance_b = b + db
				newDistance_c = c + dc
				ans = min(ans, minDistance(newDistance_a, newDistance_b, newDistance_c))
	print(ans)


t = int(input())
while t != 0:
	t -= 1
	l = list(map(int, input().split()))
	l.sort()
	s = abs(l[1] - l[0]) + abs(l[2] - l[1]) + abs(l[2] - l[0])
	s = s - 4
	if s > 0:
		print(s)
	else:
		print(0)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(a, b, c) = sorted(l)
	if a == b and b == c:
		print(0)
		continue
	elif a == b and b + 1 == c or (c == b and a + 1 == b):
		print(0)
	elif a == b:
		print((c - b - 2) * 2)
	elif c == b:
		print((b - a - 2) * 2)
	else:
		ans = b - a - 1 + c - b - 1 + c - a - 2
		print(ans)


for test in range(int(input())):
	(a, b, c) = map(int, input().split())
	mi = min(a, b, c)
	ma = max(a, b, c)
	print(max(2 * (ma - mi - 2), 0))


T = int(input())
for i in range(T):
	A = list(map(int, input().split()))
	A.sort()
	if A[0] == A[1] and A[1] == A[2]:
		print(0)
	elif A[0] == A[1] or A[1] == A[2]:
		k = 2 * (A[2] - A[0]) - 4
		if k < 0:
			print(0)
		else:
			print(k)
	else:
		k = A[2] - A[1] - 1
		k += A[1] - A[0] - 1
		k += A[2] - A[0] - 2
		print(k)


import math
q = int(input())
for _ in range(q):
	l = list(map(int, input().split(' ')))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	l_a = a - 1
	m_a = a + 1
	l_b = b - 1
	m_b = b + 1
	l_c = c - 1
	m_c = c + 1
	mi = l[0]
	ma = l[2]
	ans = 0
	if ma - mi == 0 or ma - mi == 1:
		ans = 0
	elif l[1] - mi == 1 and ma - l[1] == 1:
		ans = 0
	elif l[1] - mi == 1:
		mi = mi + 1
		ma = ma - 1
		ans = 2 * abs(ma - mi)
	elif ma - l[1] == 1:
		ma = ma - 1
		mi = mi + 1
		ans = 2 * abs(ma - mi)
	else:
		l[1] -= 1
		mi += 1
		ma -= 1
		ans = ma - mi + (ma - l[1]) + (l[1] - mi)
	print(ans)


q = int(input())
for i in range(q):
	(x, y, z) = map(int, input().split())
	friends = [x, y, z]
	friends.sort()
	x = friends[2]
	y = friends[1]
	z = friends[0]
	if x == z:
		print(0)
	elif x == y:
		if (abs(x - z) - 2) * 2 < 0:
			print(0)
		else:
			print((abs(x - z) - 2) * 2)
	elif y == z:
		if (abs(x - y) - 2) * 2 < 0:
			print(0)
		else:
			print((abs(x - y) - 2) * 2)
	else:
		print(abs(x - z - 2) * 2)


q = int(input())

def func(a, b, c):
	return abs(a - b) + abs(b - c) + abs(a - c)
for _ in range(q):
	arr = [int(x) for x in input().split()]
	arr.sort()
	temp = [[-1, -1, -1], [-1, -1, 0], [-1, -1, 1], [-1, 0, -1], [-1, 0, 0], [-1, 0, 1], [-1, 1, -1], [-1, 1, 0], [-1, 1, 1], [0, -1, -1], [0, -1, 0], [0, -1, 1], [0, 0, -1], [0, 0, 0], [0, 0, 1], [0, 1, -1], [0, 1, 0], [0, 1, 1], [1, -1, -1], [1, -1, 0], [1, -1, 1], [1, 0, -1], [1, 0, 0], [1, 0, 1], [1, 1, -1], [1, 1, 0], [1, 1, 1]]
	ans = 9999999999999999
	for t in temp:
		ans = min(ans, func(arr[0] + t[0], arr[1] + t[1], arr[2] + t[2]))
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c) = sorted(map(int, input().split()))
	res = 10 ** 100
	for p in range(-1, 2):
		for q in range(-1, 2):
			for r in range(-1, 2):
				aa = a + p
				bb = b + q
				cc = c + r
				tmp = abs(aa - bb)
				tmp += abs(aa - cc)
				tmp += abs(cc - bb)
				res = min(res, tmp)
	print(res)


t = int(input())
while t:
	l = list(map(int, input().split()))
	l.sort()
	(a, b, c) = l
	res = 0
	if a == b == c:
		res = 0
	elif a == b and a != c:
		a += 1
		b += 1
		if b != c:
			c -= 1
		res = c - a + c - b
	elif a != b and b == c:
		b -= 1
		c -= 1
		if a != b:
			a += 1
		res = b - a + c - a
	else:
		a += 1
		c -= 1
		res += b - a + c - b + c - a
	print(res)
	t -= 1


import sys
input = sys.stdin.readline
N = int(input())
L = []
for _ in range(N):
	L.append([int(x) for x in input().split()])
for i in L:
	i.sort()
	if i[0] == i[1] and i[1] == i[2]:
		print(0)
	elif i[0] == i[1]:
		a = i[0] + 1
		b = i[1] + 1
		c = i[2] - 1
		print(max(0, 2 * (c - b)))
	elif i[1] == i[2]:
		a = i[0] + 1
		b = i[1] - 1
		print(max(0, 2 * (b - a)))
	else:
		a = i[0] + 1
		b = i[1]
		c = i[2] - 1
		print(max(0, abs(a - b) + abs(b - c) + abs(c - a)))


q = int(input())
while q > 0:
	q = q - 1
	(A, B, C) = input().split()
	A = int(A)
	B = int(B)
	C = int(C)
	sum = A + B + C
	a = min(A, B, C)
	c = max(A, B, C)
	b = sum - a - c
	if a == b == c:
		print(0)
		continue
	elif a == b and c - b == 1:
		c = c - 1
		print(abs(b - c) * 2)
		continue
	elif a == b:
		c = c - 1
		b = b + 1
		print(abs(b - c) * 2)
	elif b == c and b - a == 1:
		a = a + 1
		print(abs(c - a) * 2)
	elif b == c:
		a = a + 1
		b = b - 1
		print(abs(a - b) * 2)
	else:
		a = a + 1
		c = c - 1
		print(abs(a - b) + abs(b - c) + abs(c - a))


def main():
	q = int(input())
	for i in range(q):
		(a, b, c) = map(int, input().split())
		if a == b and b == c:
			print(0)
			continue
		else:
			if a == b or c == b:
				if abs(a - c) == 1:
					print(0)
					continue
				else:
					print(abs(min(a, c) + 1 - (max(a, c) - 1)) + abs(min(a, c) + 1 - (max(a, c) - 1)))
					continue
			if a == c:
				if abs(a - b) == 1:
					print(0)
					continue
				else:
					print(abs(min(a, b) + 1 - (max(a, b) - 1)) + abs(min(a, b) + 1 - (max(a, b) - 1)))
					continue
			else:
				search(a, b, c)

def search(a, b, c):
	(x, y, z) = (a, b, c)
	a = max(x, y, z)
	c = min(x, y, z)
	b = x + y + z - a - c
	if abs(b - a) == 1 and abs(b - c) == 1:
		print(0)
		return
	elif abs(b - a) > 1:
		print(abs(c + 1 - (b + 1)) + abs(c + 1 - (a - 1)) + abs(b + 1 - (a - 1)))
		return
	elif abs(b - c) > 1:
		print(abs(c + 1 - (b - 1)) + abs(c + 1 - (a - 1)) + abs(b - 1 - (a - 1)))
		return
main()


t = int(input())

def compute_distance(L):
	return abs(L[0] - L[1]) + abs(L[0] - L[2]) + abs(L[1] - L[2])
for _ in range(t):
	L = list(map(int, input().split()))
	moves = (-1, 0, 1)
	possiblities = [(L[0] + move1, L[1] + move2, L[2] + move3) for move1 in moves for move2 in moves for move3 in moves]
	print(min([compute_distance(possibility) for possibility in possiblities]))


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	a.sort()
	sum = 2 * (a[-1] - 1 - (a[0] + 1))
	if sum > 0:
		print(sum)
	else:
		print(0)


testcases = int(input())
for i in range(0, testcases):
	positions = list(map(int, input().split()))
	positions.sort()
	if positions[2] == positions[1] and positions[1] != positions[0]:
		positions[2] -= 1
		positions[1] -= 1
	if positions[0] == positions[1] and positions[1] != positions[2]:
		positions[0] += 1
		positions[1] += 1
	if positions[1] - positions[0] > 0:
		positions[0] += 1
	if positions[2] - positions[1] > 0:
		positions[2] -= 1
	print(abs(positions[0] - positions[1]) + abs(positions[2] - positions[1]) + abs(positions[0] - positions[2]))


def lol(m, n, o):
	return abs(m - n) + abs(m - o) + abs(n - o)
t = int(input())
for i in range(t):
	a = []
	yo = sorted(list(map(int, input().split())))
	x = yo[0]
	y = yo[1]
	z = yo[2]
	if x == y and y == z:
		print(0)
	else:
		a.append(lol(x + 1, y, z))
		a.append(lol(x - 1, y, z))
		a.append(lol(x, y + 1, z))
		a.append(lol(x, y - 1, z))
		a.append(lol(x, y, z + 1))
		a.append(lol(x, y, z - 1))
		a.append(lol(x + 1, y + 1, z))
		a.append(lol(x + 1, y - 1, z))
		a.append(lol(x - 1, y + 1, z))
		a.append(lol(x - 1, y - 1, z))
		a.append(lol(x + 1, y, z + 1))
		a.append(lol(x + 1, y, z - 1))
		a.append(lol(x - 1, y, z + 1))
		a.append(lol(x - 1, y, z - 1))
		a.append(lol(x, y + 1, z + 1))
		a.append(lol(x, y + 1, z - 1))
		a.append(lol(x, y - 1, z + 1))
		a.append(lol(x, y - 1, z - 1))
		a.append(lol(x + 1, y + 1, z - 1))
		a.append(lol(x + 1, y - 1, z + 1))
		a.append(lol(x - 1, y + 1, z - 1))
		a.append(lol(x - 1, y + 1, z + 1))
		a.append(lol(x - 1, y - 1, z + 1))
		a.append(lol(x + 1, y - 1, z - 1))
		print(min(a))


t = int(input())
for j in range(t):
	ar = [int(x) for x in input().split()]
	ar.sort()
	a = ar[0]
	b = ar[1]
	c = ar[2]
	if a == b and b == c:
		print(0)
	elif a == b and c - b > 1:
		print(2 * (c - 1 - b) - 2)
	elif a == b and c - b <= 1:
		print(2 * (c - 1 - b))
	elif b == c and b - a > 1:
		print(2 * (b - a - 1) - 2)
	elif b == c and b - a <= 1:
		print(2 * (b - a - 1))
	else:
		print(2 * (c - a - 2))


q = int(input())
for x in range(q):
	lista = list(map(int, input().split()))
	lista.sort()
	(a, b, c) = lista
	if a != b:
		a += 1
		if a != b:
			b -= 1
	elif a != c:
		a += 1
		b += 1
	if c != b:
		c -= 1
	ans = abs(a - b) + abs(c - a) + abs(b - c)
	print(ans)


def dis(x, y, z):
	return abs(x - y) + abs(y - z) + abs(x - z)

def func(a, b, c):
	min = dis(a, b, c)
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				if dis(a + i, b + j, c + k) < min:
					min = dis(a + i, b + j, c + k)
	return min
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(a, b, c) = (l[0], l[1], l[2])
	print(func(a, b, c))


import math
t = int(input())
while t > 0:
	ans = int(100000 ** 2)
	(a, b, c) = map(int, input().split())
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = a + i
				y = b + j
				z = c + k
				ans = min(ans, abs(x - y) + abs(x - z) + abs(y - z))
	print(ans)
	t -= 1


for _ in range(int(input())):
	(a, b, c) = [int(q) for q in input().split()]
	l = []
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				l.append(abs(i - j) + abs(i - k) + abs(j - k))
	print(min(l))


q = int(input())
while q:
	l = [int(i) for i in input().split()]
	l.sort()
	print(max(0, 2 * (l[2] - l[0] - 2)))
	q -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		a = LI()
		t = max(a) - min(a)
		r = max(0, (t - 2) * 2)
		rr.append(r)
	return JA(rr, '\n')
print(main())


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	things = [int(i) for i in input().split()]
	things.sort()
	if things[2] - things[0] >= 2:
		things[0] += 1
	if things[1] > things[0]:
		things[1] -= 1
	if things[2] > things[1]:
		things[2] -= 1
	print(things[1] - things[0] + (things[2] - things[1]) + (things[2] - things[0]))


q = int(input())
while q > 0:
	list_a = list(map(int, input().split()))
	list_a.sort(reverse=True)
	sum = 0
	if list_a[0] == list_a[1] and list_a[0] == list_a[2]:
		sum = 0
	elif list_a[0] == list_a[1] + 1 and list_a[1] == list_a[2]:
		sum = 0
	elif list_a[0] == list_a[1] and list_a[0] == list_a[2] + 1:
		sum = 0
	elif list_a[0] > list_a[1] + 1 and list_a[1] == list_a[2]:
		list_a[0] -= 1
		list_a[1] += 1
		list_a[2] += 1
		sum = list_a[0] - list_a[1] + (list_a[1] - list_a[2]) + (list_a[0] - list_a[2])
	elif list_a[0] > list_a[1] + 1 and list_a[1] > list_a[2]:
		list_a[0] -= 1
		list_a[1] += 1
		list_a[2] += 1
		sum = list_a[0] - list_a[1] + (list_a[1] - list_a[2]) + (list_a[0] - list_a[2])
	elif list_a[0] == list_a[1] and list_a[0] > list_a[2] + 1:
		list_a[0] -= 1
		list_a[1] -= 1
		list_a[2] += 1
		sum = list_a[0] - list_a[1] + (list_a[1] - list_a[2]) + (list_a[0] - list_a[2])
	elif list_a[0] == list_a[1] + 1 and list_a[0] > list_a[2] + 1:
		list_a[0] -= 1
		list_a[2] += 1
		sum = list_a[0] - list_a[1] + (list_a[1] - list_a[2]) + (list_a[0] - list_a[2])
	print(sum)
	q -= 1


n = int(input())
for _ in range(n):
	arr = list(map(int, input().split()))
	s = abs(arr[0] - arr[1]) + abs(arr[0] - arr[2]) + abs(arr[1] - arr[2])
	if s - 4 <= 0:
		print(0)
	else:
		print(s - 4)


q = int(input())
for _ in range(q):
	(x, y, z) = list(map(int, input().strip().split()))
	sort = list(sorted((x, y, z)))
	mini = 10 ** 12
	for d1 in range(-1, 2):
		for d2 in range(-1, 2):
			for d3 in range(-1, 2):
				(a, b, c) = sort
				(a, b, c) = (a + d1, b + d2, c + d3)
				total = abs(a - b) + abs(a - c) + abs(b - c)
				if total < mini:
					mini = total
	print(mini)


q = int(input())
for it in range(q):
	A = [int(i) for i in input().split()]
	A.sort()
	sum = A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0])
	A[0] += 1
	if A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]) > sum:
		A[0] -= 1
	else:
		sum = max(A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]), 0)
	A[1] += 1
	if A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]) > sum:
		A[1] -= 1
	else:
		sum = max(A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]), 0)
	A[1] -= 1
	if A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]) > sum:
		A[1] += 1
	else:
		sum = max(A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]), 0)
	A[2] -= 1
	if A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]) > sum:
		A[2] += 1
	else:
		sum = max(A[2] - A[1] + (A[2] - A[0]) + (A[1] - A[0]), 0)
	print(sum)


q = input()
q = int(q)
cases = []
for _ in range(q):
	line = input()
	nums = line.split()
	nums = [int(x) for x in nums]
	cases.append(nums)

def solver(case):
	(a, b, c) = case
	if a == b and a == c:
		return 0
	dmin = None
	for i in range(-1, 2):
		aa = a + i
		for j in range(-1, 2):
			bb = b + j
			for k in range(-1, 2):
				cc = c + k
				d = abs(aa - bb) + abs(bb - cc) + abs(aa - cc)
				if dmin == None:
					dmin = d
				elif d < dmin:
					dmin = d
	return dmin
for case in cases:
	d = solver(case)
	print(d)


q = int(input())

def cul(li):
	return abs(li[0] - li[1]) + abs(li[1] - li[2]) + abs(li[2] - li[0])
for _ in range(q):
	(a, b, c) = list(map(int, input().split()))
	ans = 10 ** 12
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				ans = min(ans, cul([a + i, b + j, c + k]))
	print(ans)


n = int(input())
for i in range(n):
	abc = 0
	(a, b, c) = map(int, input().split())
	if abs(a - c) > abs(a - b):
		abc = abs(a - c)
	else:
		abc = abs(a - b)
	if abc < abs(b - c):
		abc = abs(b - c)
	if abc > 2:
		print((abc - 2) * 2)
	else:
		print('0')


from itertools import product
pre = [*product(range(-1, 2), repeat=3)]

def dist(l):
	(a, b, c) = l
	return abs(a - b) + abs(a - c) + abs(b - c)
for _ in range(int(input())):
	l = [*map(int, input().split())]
	print(min((dist(map(sum, zip(p, l))) for p in pre)))


for _ in range(int(input())):
	(a, b, c) = sorted(map(int, input().split()))
	a1 = min(b - a, b - a - 2)
	b1 = min(c - a, c - a - 2)
	c1 = c - b
	print([0, a1 + b1 + c1][a1 + b1 + c1 >= 0])


q = int(input())
for t in range(q):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	c = int(s[2])
	l = [a, b, c]
	l.sort()
	if l[0] == l[1] == l[2]:
		pass
	elif l[0] != l[1] and l[1] != l[2]:
		l[0] += 1
		l[2] -= 1
	elif l[0] == l[1] and l[1] != l[2]:
		l[2] -= 1
		if l[2] != l[0]:
			l[0] += 1
			l[1] += 1
	elif l[2] == l[1] and l[0] != l[1]:
		l[2] -= 1
		l[1] -= 1
		if l[1] != l[0]:
			l[0] += 1
	ans = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[0] - l[2])
	print(ans)


for _ in range(int(input())):
	arr = list(map(int, input().split()))
	arr.sort()
	if arr[0] != arr[1] != arr[2]:
		arr[0] += 1
		arr[2] -= 1
		print(2 * (arr[2] - arr[0]))
	elif arr[0] == arr[1] == arr[2]:
		print(0)
	elif arr[0] == arr[1] != arr[2]:
		arr[0] += 1
		arr[1] += 1
		x = abs(arr[1] - arr[0]) + abs(arr[2] - arr[0]) + abs(arr[2] - arr[1])
		arr[2] -= 1
		y = abs(arr[1] - arr[0]) + abs(arr[2] - arr[0]) + abs(arr[2] - arr[1])
		print(min(x, y))
	elif arr[0] != arr[1] == arr[2]:
		arr[1] -= 1
		arr[2] -= 1
		x = abs(arr[1] - arr[0]) + abs(arr[2] - arr[0]) + abs(arr[2] - arr[1])
		arr[0] += 1
		y = abs(arr[1] - arr[0]) + abs(arr[2] - arr[0]) + abs(arr[2] - arr[1])
		print(min(x, y))


for _ in range(int(input())):
	s = [*map(int, input().split())]
	s.sort()
	if s[0] == s[1] == s[2]:
		print(0)
	elif s[0] == s[1]:
		if abs(s[2] - s[1]) >= 2:
			ans = s[2] - 1
			s[0] = s[0] + 1
			s[1] = s[1] + 1
			print(2 * (ans - s[0]))
		else:
			ans = s[2] - 1
			print(2 * (ans - s[0]))
	elif s[1] == s[2]:
		if abs(s[1] - s[0]) >= 2:
			ans = s[0] + 1
			s[1] = s[1] - 1
			s[2] = s[2] - 1
			print(2 * (s[1] - ans))
		else:
			ans = s[0] + 1
			print(2 * (s[1] - ans))
	else:
		ans = s[0] + 1
		n = s[2] - 1
		print(s[1] - ans + (n - s[1]) + (n - ans))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = abs(a - b) + abs(b - c) + abs(c - a)
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				p = a + i
				q = b + j
				r = c + k
				hh = abs(p - q) + abs(q - r) + abs(p - r)
				ans = min(hh, ans)
	print(ans)


def gs(a, b, c):
	return abs(a - b) + abs(c - a) + abs(b - c)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	res = 10000000000.0
	for i in range(3):
		for j in range(3):
			for k in range(3):
				res = min(res, gs(a + i - 1, b + j - 1, c + k - 1))
	print(res)


k = int(input())
for i in range(k):
	(a, b, c) = [int(i) for i in input().split(' ')]
	summ = abs(a - b) + abs(a - c) + abs(b - c) - 4
	if summ < 0:
		print(0)
	else:
		print(summ)


for _ in range(0, int(input())):
	l = list(map(int, input().split()))
	l.sort()
	a = l[1] - l[0] + l[2] - l[1] + l[2] - l[0]
	b = a - 4
	if b < 0:
		print(0)
	else:
		print(b)


for q in range(int(input())):
	a = sorted(map(int, input().split()))
	print(2 * max(0, a[2] - a[0] - 2))


for _ in range(int(input())):
	arr = list(map(int, input().split()))
	arr.sort()
	arr[0] = min(arr[0] + 1, arr[2])
	arr[2] = max(arr[2] - 1, arr[0])
	ans = 2 * (arr[2] - arr[0])
	print(ans)


for _ in range(int(input())):
	friends = [int(i) for i in input().split()]
	friends.sort()
	if friends[0] != friends[1] and friends[1] != friends[2]:
		friends[0] += 1
		friends[2] -= 1
	elif friends[0] == friends[1] and friends[1] != friends[2]:
		if friends[2] - friends[1] == 1:
			friends[0] += 1
			friends[1] += 1
		else:
			friends[0] += 1
			friends[1] += 1
			friends[2] -= 1
	elif friends[0] != friends[1] and friends[1] == friends[2]:
		if friends[1] - friends[0] == 1:
			friends[1] -= 1
			friends[2] -= 1
		else:
			friends[0] += 1
			friends[1] -= 1
			friends[2] -= 1
	print(abs(friends[0] - friends[1]) + abs(friends[0] - friends[2]) + abs(friends[1] - friends[2]))


for q in range(int(input())):
	abc = list(map(int, input().split()))
	Sum = abs(abc[0] - abc[1]) + abs(abc[0] - abc[2]) + abs(abc[1] - abc[2])
	print(max(Sum - 4, 0))


t = eval(input())
inputs = list()
(ac, ab, bc) = (0, 0, 0)
for _ in range(t):
	temp = input()
	inputs.append(temp.split(' '))
for val in inputs:
	val = sorted(val)
	for i in range(3):
		val[i] = eval(val[i])
	ac = abs(val[0] - val[2])
	ab = abs(val[0] - val[1])
	bc = abs(val[1] - val[2])
	if ac == 0 or ac == 1:
		print(0)
	elif ac == ab or ac == bc:
		print(ac + ab + bc - 4)
	elif ac > 1:
		ac -= 2
		if ab >= 1:
			ab -= 1
		if bc >= 1:
			bc -= 1
		print(ac + ab + bc)


n = int(input())
for i in range(n):
	(a, b, c) = [int(x) for x in input().split()]
	s = abs(a - b) + abs(a - c) + abs(b - c)
	seta = [a - 1, a, a + 1]
	setb = [b - 1, b, b + 1]
	setc = [c - 1, c, c + 1]
	for d in seta:
		for f in setb:
			for g in setc:
				s = min(s, abs(d - f) + abs(f - g) + abs(d - g))
	print(s)


q = int(input())
for qt in range(q):
	(a, b, c) = sorted(map(int, input().split()))
	if a != c:
		if a == b:
			if c != a + 1:
				a = a + 1
				b = b + 1
			c = c - 1
		elif b == c:
			if a != b - 1:
				b = b - 1
				c = c - 1
			a = a + 1
		else:
			if a < b:
				a = a + 1
			if c > b:
				c = c - 1
	print(b - a + (c - a) + (c - b))


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = 0
	if a == b and b == c:
		print('0')
		continue
	else:
		s = abs(a - b) + abs(a - c) + abs(b - c)
		if s > 4:
			print(s - 4)
		else:
			print('0')


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	(a, b, c) = sorted([a, b, c])
	if a == b & b == c:
		print(0)
	elif a == b:
		print(max(0, 2 * (c - a - 2)))
	elif b == c:
		print(max(0, 2 * (b - a - 2)))
	else:
		print(max(0, 2 * (c - a - 2)))


import math
m = 1000000007

def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans % m * (i % m) % m
	return ans

def power_2(n):
	ans = 1
	for i in range(n):
		ans = ans % m * 2 % m
	return ans
for z in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a, c, b) = (min(a, b, c), max(a, b, c), a + b + c - min(a, b, c) - max(a, b, c))
	if min(a, b, c) == max(a, b, c):
		print(0)
	elif b - a == 0:
		if c - b == 1:
			print(0)
		else:
			print(2 * (c - b - 2))
	elif c - b == 0:
		if b - a == 1:
			print(0)
		else:
			print(2 * (b - a - 2))
	elif c - b == 1 and b - a == 1:
		print(0)
	else:
		a += 1
		if a != b:
			b -= 1
		if b != c:
			c -= 1
		print(2 * (c - a))


t = int(input())
for p in range(t):
	l1 = list(map(int, input().split()))
	l = sorted(l1)
	if l[0] != l[1] and l[1] != l[2]:
		l[0] += 1
		l[2] -= 1
		if l[1] != l[0] and l[1] != l[2]:
			l[1] -= 1
	elif l[0] == l[1] and l[1] == l[2]:
		l[0] = l[1]
	elif l[1] == l[2]:
		l[2] -= 1
		l[1] -= 1
		if l[1] - l[0] >= 1:
			l[0] += 1
	elif l[1] == l[0]:
		l[0] += 1
		l[1] += 1
		if l[2] - l[1] >= 1:
			l[2] -= 1
	a = abs(l[0] - l[1]) + abs(l[2] - l[1]) + abs(l[0] - l[2])
	print(a)


def friends(lst):
	if lst[2] - lst[0] <= 2:
		return 0
	else:
		if lst[0] == lst[1]:
			lst[0] += 1
			lst[1] += 1
			lst[2] -= 1
		elif lst[1] == lst[2]:
			lst[2] -= 1
			lst[1] -= 1
			lst[0] += 1
		else:
			lst[0] += 1
			lst[2] -= 1
		return abs(lst[0] - lst[1]) + abs(lst[0] - lst[2]) + abs(lst[1] - lst[2])
for _ in range(int(input())):
	a = [int(i) for i in input().split()]
	print(friends(sorted(a)))


for q in range(int(input())):
	[a, b, c] = map(int, input().split())
	rr = [-1, 0, 1]
	dist = 2 * 10 ** 9
	for i in rr:
		for j in rr:
			for k in rr:
				(av, bv, cv) = (a + i, b + j, c + k)
				dist = min(dist, abs(av - bv) + abs(bv - cv) + abs(av - cv))
	print(dist)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	mini = 3000000009
	for x in range(a - 1, a + 2):
		for y in range(b - 1, b + 2):
			for z in range(c - 1, c + 2):
				d = abs(x - y) + abs(x - z) + abs(y - z)
				mini = min(mini, d)
	print(mini)


for _ in range(int(input())):
	p = list(sorted(map(int, input().split())))
	print(0 if p[2] - p[0] <= 2 else 2 * (p[2] - p[0]) - 4)


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
for _ in range(int(stdin.readline())):
	(x, y, z) = map(int, stdin.readline().strip().split())
	sum = 10 ** 10
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				a = x + i
				b = y + j
				c = z + k
				if abs(a - b) + abs(a - c) + abs(b - c) < sum:
					sum = abs(a - b) + abs(a - c) + abs(b - c)
	print(sum)


tests = int(input())
for te in range(tests):
	arr = list(map(int, input().split()))
	arr.sort()
	if arr[0] == arr[1] and arr[1] == arr[2]:
		print(0)
	elif arr[0] == arr[1] and arr[1] != arr[2]:
		ans = 2 * (arr[2] - arr[1] - 1)
		if arr[2] - arr[1] > 1:
			ans -= 2
		print(ans)
	elif arr[1] == arr[2] and arr[1] != arr[0]:
		ans = 2 * (arr[1] - arr[0] - 1)
		if arr[1] - arr[0] > 1:
			ans -= 2
		print(ans)
	else:
		print(2 * (arr[2] - arr[0] - 2))


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	new = sorted([a, b, c])
	if abs(new[1] - new[0]) + abs(new[2] - new[1]) + abs(new[2] - new[0]) < 3:
		print(0)
		continue
	new[0] += 1
	new[2] -= 1
	if new[1] < new[0]:
		new[1] += 1
	elif new[1] > new[2]:
		new[1] -= 1
	print(abs(new[1] - new[0]) + abs(new[2] - new[1]) + abs(new[2] - new[0]))


import math
tc = int(input())
for i in range(tc):
	(a, b, c) = map(int, input().split())
	if a == b and b == c and (a == c):
		print(0)
	else:
		maxx = max(a, b, c)
		minn = min(a, b, c)
		mid = math.floor((maxx + minn) / 2)
		if a > mid:
			a = a - 1
		elif a < mid:
			a = a + 1
		if b > mid:
			b = b - 1
		elif b < mid:
			b = b + 1
		if c > mid:
			c = c - 1
		elif c < mid:
			c = c + 1
		print(abs(a - b) + abs(a - c) + abs(b - c))


t = int(input())
while t:
	(a, b, c) = map(int, input().split())
	if a == b == c:
		print(0)
	elif a + 1 == b + 1 == c or a - 1 == b - 1 == c or a == b + 1 == c + 1 or (a == b - 1 == c - 1) or (a - 1 == b == c - 1) or (a + 1 == b == c + 1) or (a + 1 == b - 1 == c) or (a - 1 == b + 1 == c) or (a == b - 1 == c + 1) or (a == b + 1 == c - 1) or (a - 1 == b == c + 1) or (a + 1 == b == c - 1):
		print(0)
	else:
		l = [a, b, c]
		l.sort()
		print(l[1] - l[0] + l[2] - l[1] + l[2] - l[0] - 4)
	t = t - 1


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	if a[2] - a[0] <= 2:
		print(0)
	else:
		print((a[2] - a[0] - 2) * 2)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(a, b, c) = sorted(list(map(int, input().split())))
	if a == b == c:
		ans = 0
	elif a == b or b == c:
		if a == b:
			if c - a > 1:
				a += 1
				b += 1
			c -= 1
			ans = abs(a - b) + abs(a - c) + abs(b - c)
		elif b == c:
			if b - a > 1:
				c -= 1
				b -= 1
			a += 1
			ans = abs(a - b) + abs(a - c) + abs(b - c)
	else:
		a += 1
		c -= 1
		ans = abs(a - b) + abs(a - c) + abs(b - c)
	print(ans)
t = int(input())
for _ in range(t):
	main()


import sys
t = int(input())
for x in range(t):
	(a, b, c) = map(int, input().split(' '))
	g_min = sys.maxsize
	for i in [a - 1, a, a + 1]:
		for j in [b - 1, b, b + 1]:
			for k in [c - 1, c, c + 1]:
				ans = abs(i - j) + abs(i - k) + abs(j - k)
				g_min = min(g_min, ans)
	print(g_min)


n = int(input())
a = [0] * 3
for i in range(n):
	a = list(map(int, input().split()))
	a.sort()
	c = 2 * a[2] - 2 * a[0] - 4
	if c < 0:
		c = 0
	print(c)


t = int(input())
while t:
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	l3 = []
	j = 1
	for i in range(3):
		l1.append(l[0] + j)
		l2.append(l[1] + j)
		l3.append(l[2] + j)
		j -= 1
	ans = []
	for i in range(3):
		for j in range(3):
			for k in range(3):
				ans.append(abs(l1[i] - l2[j]) + abs(l1[i] - l3[k]) + abs(l2[j] - l3[k]))
	print(min(ans))
	t -= 1


def sort(d):
	if d[0]['x'] > d[1]['x']:
		(d[0], d[1]) = (d[1], d[0])
	if d[1]['x'] > d[2]['x']:
		(d[1], d[2]) = (d[2], d[1])
	if d[0]['x'] > d[1]['x']:
		(d[0], d[1]) = (d[1], d[0])
	return d

def spd(f):
	(a, b, c) = (0, 0, 0)
	for friend in f:
		if friend['name'] == 'a':
			a = friend['x']
		elif friend['name'] == 'b':
			b = friend['x']
		else:
			c = friend['x']
	return abs(a - b) + abs(a - c) + abs(b - c)

def normilize(f):
	(min, sred, max) = f
	if min['x'] == sred['x'] == max['x']:
		pass
	elif sred['x'] == max['x'] and sred['x'] - min['x'] == 1:
		min['x'] += 1
	elif sred['x'] == max['x']:
		min['x'] += 1
		sred['x'] -= 1
		max['x'] -= 1
	elif min['x'] == sred['x'] and max['x'] - sred['x'] == 1:
		max['x'] -= 1
	elif min['x'] == sred['x']:
		max['x'] -= 1
		min['x'] += 1
		sred['x'] += 1
	else:
		min['x'] += 1
		max['x'] -= 1
	return [min, sred, max]
q = int(input())
friends = []
for i in range(0, q):
	(a, b, c) = list(map(int, str(input()).split(' ')))
	friends.append({'x': a, 'name': 'a'})
	friends.append({'x': b, 'name': 'b'})
	friends.append({'x': c, 'name': 'c'})
	friends = sort(friends)
	friends = normilize(friends)
	print(spd(friends))
	friends.clear()


from math import fabs
from math import floor

def count(a1, b1, c1):
	return fabs(a1 - b1) + fabs(a1 - c1) + fabs(b1 - c1)
n = int(input())
(a, b, c) = [int(i) for i in input().split(' ')]
answ = 9999999999
for aa in range(-1, 2):
	for bb in range(-1, 2):
		for cc in range(-1, 2):
			answ = floor(min(answ, count(a + aa, b + bb, c + cc)))
print(answ, end='')
for i in range(n - 1):
	(a, b, c) = [int(i) for i in input().split(' ')]
	answ = 9999999999
	print()
	for aa in range(-1, 2):
		for bb in range(-1, 2):
			for cc in range(-1, 2):
				answ = floor(min(answ, count(a + aa, b + bb, c + cc)))
	print(answ, end='')


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	coordinates = [a, b, c]
	coordinates.sort()
	coordinates[0] += 1
	coordinates[2] -= 1
	mindist = 0
	mindist = coordinates[1] - coordinates[0] + (coordinates[2] - coordinates[1]) + (coordinates[2] - coordinates[0])
	if mindist < 0:
		print(0)
	else:
		print(mindist)


for i in range(int(input())):
	a = [int(x) for x in input().split()]
	b = []
	for i in a:
		b.append(i - 1)
		b.append(i)
		b.append(i + 1)
	answer = 100000000000
	for i in b[:3]:
		for j in b[3:6]:
			for k in b[6:]:
				c = abs(i - j) + abs(i - k) + abs(j - k)
				if c < answer:
					answer = c
	print(answer)


def check(arr):
	return abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2])
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = [a, b, c]
	l.sort()
	l1 = l[:]
	ans1 = check(l1)
	ans2 = check([l[0], l[1] + 1, l[2]])
	ans2 = check([l[0], l[1] - 1, l[2]])
	ans3 = check([l[0] + 1, l[1], l[2]])
	ans4 = check([l[0] - 1, l[1], l[2]])
	ans5 = check([l[0], l[1], l[2] - 1])
	ans6 = check([l[0], l[1], l[2] + 1])
	ans7 = check([l[0] + 1, l[1] + 1, l[2]])
	ans8 = check([l[0] + 1, l[1] - 1, l[2]])
	ans9 = check([l[0] - 1, l[1] + 1, l[2]])
	ans10 = check([l[0] - 1, l[1] - 1, l[2]])
	ans11 = check([l[0], l[1] + 1, l[2] + 1])
	ans12 = check([l[0], l[1] + 1, l[2] - 1])
	ans13 = check([l[0], l[1] - 1, l[2] + 1])
	ans14 = check([l[0], l[1] - 1, l[2] - 1])
	ans15 = check([l[0] + 1, l[1], l[2] + 1])
	ans16 = check([l[0] + 1, l[1], l[2] - 1])
	ans17 = check([l[0] + 1, l[1] - 1, l[2] - 1])
	ans = min(ans17, ans16, ans15, ans14, ans13, ans12, ans11, ans10, ans9, ans8, ans7, ans6, ans5, ans4, ans3, ans2, ans1)
	ans = min(ans, check([l[0] + 1, l[1] - 1, l[2] - 1]))
	ans = min(ans, check([l[0] + 1, l[1] + 1, l[2] - 1]))
	print(ans)


n = int(input())
ar = []
for i in range(n):
	s = input()
	a = s.split(' ')
	ar.append(a)
arr = []

def dist(x, y, z):
	t = abs(x - y) + abs(y - z) + abs(z - x)
	return t
for i in range(n):
	a = int(ar[i][0])
	b = int(ar[i][1])
	c = int(ar[i][2])
	m1 = min(a, b, c)
	m3 = max(a, b, c)
	m2 = a + b + c - (m1 + m3)
	if m1 == m2 and m2 == m3 and (m3 == m1):
		arr.append(0)
	elif m1 != m2 and m2 != m3 and (m3 != m1):
		p = min(dist(m1 + 1, m2 + 1, m3 - 1), dist(m1 + 1, m2 - 1, m3 - 1), dist(m1 + 1, m2, m3 - 1))
		q = min(dist(m1, m2 - 1, m3), dist(m1, m2 + 1, m3), dist(m1, m2, m3))
		k = min(dist(m1, m2, m3 - 1), dist(m1 + 1, m2, m3), dist(m1 + 1, m2 + 1, m3), dist(m1, m2 + 1, m3 - 1), dist(m1 + 1, m2 - 1, m3), dist(m1, m2 - 1, m3 - 1))
		arr.append(min(p, q, k))
	elif m1 == m2:
		p = min(dist(m1 + 1, m2 + 1, m3), dist(m1 + 1, m2 + 1, m3 - 1), dist(m1, m2, m3), dist(m1, m2, m3 - 1))
		arr.append(p)
	else:
		q = min(dist(m1, m2 - 1, m3 - 1), dist(m1 + 1, m2 - 1, m3 - 1), dist(m1, m2, m3), dist(m1 + 1, m2, m3))
		arr.append(q)
for i in range(n):
	print(arr[i])


def dist(l):
	y = abs(l[0] - l[1]) + abs(l[1] - l[2]) + abs(l[2] - l[0])
	return y
t = int(input())
for v in range(t):
	x = [int(q) for q in input().split()]
	ans = dist(x) - 4
	if ans < 0:
		print('0')
	else:
		print(ans)


q = int(input())
for qwe in range(q):
	(a, b, c) = map(int, input().split())
	o = 0
	x1 = min(a, b, c)
	x3 = max(a, b, c)
	x2 = a + b + c - x1 - x3
	if x2 == x3 and x2 > x1:
		x2 -= 1
		x3 -= 1
		if x1 < x2:
			x1 += 1
	elif x1 == x2 and x1 < x3:
		x1 += 1
		x2 += 1
		if x3 > x1:
			x3 -= 1
	elif x1 == x2 == x3:
		(x1, x2, x3) = (0, 0, 0)
	else:
		x1 += 1
		x3 -= 1
	print(abs(x1 - x2) + abs(x1 - x3) + abs(x3 - x2))


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
import math
dx = [-1, 0, 1]
for _ in range(int(stdin.readline())):
	(a, b, c) = get_ints()
	sum = INF
	for i in range(3):
		x = a - dx[i]
		for j in range(3):
			y = b - dx[j]
			for k in range(3):
				z = c - dx[k]
				sum = min(sum, abs(x - y) + abs(y - z) + abs(z - x))
	print(sum)


q = int(input())
while q:
	q -= 1
	(a, b, c) = [int(x) for x in input().split()]
	ans = abs(a - b) + abs(b - c) + abs(a - c) - 4
	if ans > 0:
		print(ans)
	else:
		print(0)


import sys

def main():
	inp = sys.stdin.read().strip().split('\n')
	out = []
	for s in inp[1:]:
		(a, b, c) = map(int, s.split())
		out.append(max(0, abs(a - b) + abs(a - c) + abs(b - c) - 4))
	return out
print(*main(), sep='\n')


def play(abc):
	abc.sort()
	a = abc[0]
	b = abc[1]
	c = abc[2]
	s = b - a + c - b + c - a
	if a == c:
		return s
	if a == b:
		if c > b + 1:
			return s - 4
		else:
			return s - 2
	if c == b:
		if c > a + 1:
			return s - 4
		else:
			return s - 2
	return s - 4

def main():
	q = list(map(int, input().split()))[0]
	while q > 0:
		abc = list(map(int, input().split()))
		print(play(abc))
		q -= 1
main()


def pairwise(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def minimum(a, b, c):
	li = []
	li.append(pairwise(a - 1, b - 1, c - 1))
	li.append(pairwise(a - 1, b - 1, c))
	li.append(pairwise(a - 1, b - 1, c + 1))
	li.append(pairwise(a - 1, b, c - 1))
	li.append(pairwise(a - 1, b, c))
	li.append(pairwise(a - 1, b, c + 1))
	li.append(pairwise(a - 1, b + 1, c - 1))
	li.append(pairwise(a - 1, b + 1, c))
	li.append(pairwise(a - 1, b + 1, c + 1))
	li.append(pairwise(a, b - 1, c - 1))
	li.append(pairwise(a, b - 1, c))
	li.append(pairwise(a, b - 1, c + 1))
	li.append(pairwise(a, b, c - 1))
	li.append(pairwise(a, b, c))
	li.append(pairwise(a, b, c + 1))
	li.append(pairwise(a, b + 1, c - 1))
	li.append(pairwise(a, b + 1, c))
	li.append(pairwise(a, b + 1, c + 1))
	li.append(pairwise(a + 1, b - 1, c - 1))
	li.append(pairwise(a + 1, b - 1, c))
	li.append(pairwise(a + 1, b - 1, c + 1))
	li.append(pairwise(a + 1, b, c - 1))
	li.append(pairwise(a + 1, b, c))
	li.append(pairwise(a + 1, b, c + 1))
	li.append(pairwise(a + 1, b + 1, c - 1))
	li.append(pairwise(a + 1, b + 1, c))
	li.append(pairwise(a + 1, b + 1, c + 1))
	return li
N = int(input())
for i in range(N):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	li = minimum(a, b, c)
	print(min(li))


def ab():
	b = list(map(int, input().split(' ')))
	b.sort()
	c = b[0]
	d = b[1]
	e = b[2]
	if c == d and d == e:
		print('0')
		return
	elif c == d:
		e = e - 1
		if e != c:
			c = c + 1
		print(2 * abs(e - c))
	elif e == d:
		c = c + 1
		if c != d:
			e = e - 1
		print(2 * abs(e - c))
	else:
		c = c + 1
		if c != d:
			d = d - 1
		if d != e:
			e = e - 1
		print(abs(c - d) + abs(c - e) + abs(d - e))
a = int(input())
for i in range(0, a):
	ab()


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	r = c - a + (c - b) + (b - a)
	if r - 4 > 0:
		print(r - 4)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c) = list(map(int, input().strip().split()))
	s = []
	for j in [a - 1, a, a + 1]:
		for k in [b - 1, b, b + 1]:
			for l in [c - 1, c, c + 1]:
				s.append(abs(j - k) + abs(k - l) + abs(l - j))
	print(min(s))


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] != l[1] and l[1] != l[2]:
		x = abs(l[1] - l[0]) + abs(l[2] - l[1]) + abs(l[2] - l[0])
		y = abs(l[1] - l[0] - 1) + abs(l[2] - l[1] - 1) + abs(l[2] - l[0] - 2)
		y = min(x, y)
		print(y)
	elif l[0] == l[1] and l[1] != l[2]:
		x = abs(l[2] - l[1] - 1) + abs(l[2] - l[0] - 1)
		y = abs(l[2] - l[1] - 2) + abs(l[2] - l[0] - 2)
		print(min(x, y))
	elif l[1] == l[2] and l[0] != l[1]:
		x = abs(l[2] - l[0] - 1) + abs(l[1] - l[0] - 1)
		y = abs(l[2] - l[0] - 2) + abs(l[1] - l[0] - 2)
		print(min(x, y))
	elif l[0] == l[2]:
		print(0)


import sys
input = sys.stdin.readline
import itertools

def main():
	t = int(input())
	for _ in range(t):
		(a, b, c) = [int(x) for x in input().split()]
		mi = float('inf')
		x = list(itertools.product(range(-1, 2), repeat=3))
		for i in x:
			y = abs(i[0] + a - (i[1] + b)) + abs(i[0] + a - (i[2] + c)) + abs(i[1] + b - (i[2] + c))
			mi = min(y, mi)
		print(mi)
main()


def min_dist_friends():
	distances = list(map(int, input().split()))
	distances.sort()
	if distances[2] - distances[0] > 1:
		print(2 * (distances[2] - 2 - distances[0]))
	else:
		print(0)

def main():
	for case in range(int(input())):
		min_dist_friends()
main()


q = int(input())
for case in range(q):
	(a, b, c) = list(map(int, input().split()))
	sm = abs(c - a) + abs(b - a) + abs(b - c)
	ans = max(0, sm - 4)
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	avg = (a + b + c) / 3
	if avg - a >= 0.5:
		a += 1
	if avg - b >= 0.5:
		b += 1
	if avg - c >= 0.5:
		c += 1
	if a - avg >= 0.5:
		a -= 1
	if b - avg >= 0.5:
		b -= 1
	if c - avg >= 0.5:
		c -= 1
	print(abs(a - b) + abs(c - b) + abs(a - c))


for _ in range(int(input())):
	a = sorted(map(int, input().split()))
	if a[0] < a[2]:
		a[0] += 1
	if a[0] < a[2]:
		a[2] -= 1
	if a[0] < a[1]:
		a[1] -= 1
	elif a[1] < a[2]:
		a[1] += 1
	a.sort()
	print(a[1] - a[0] + (a[2] - a[1]) + (a[2] - a[0]))


l = [-1, 0, 1]
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	m = 1000000000000000000000
	for i in l:
		for j in l:
			for k in l:
				(x, y, z) = (a + i, b + j, c + k)
				m = min(abs(x - y) + abs(y - z) + abs(x - z), m)
	print(m)


for _ in range(int(input())):
	ls = list(map(int, input().split()))
	ls.sort()
	dist = [ls[1] - ls[0], ls[2] - ls[1], ls[2] - ls[0]]
	s = sum(dist)
	if s >= 4:
		s -= 4
	else:
		s = 0
	print(s)


n = int(input())
text_list = []
for i in range(n):
	text_list.append(list(map(int, input().split())))
for one_data_list in text_list:
	one_data_list.sort()
	a = one_data_list[0]
	b = one_data_list[-1]
	if b - a < 3:
		print('0')
	else:
		print(2 * (b - a - 2))


q = int(input())
for n in range(q):
	(d1, d2, d3) = (0, 0, 0)
	lst = [int(i) for i in input().split()]
	lst.sort()
	if lst[0] != lst[1]:
		lst[0] += 1
	elif lst[1] == lst[0] and lst[1] < lst[2]:
		lst[1] += 1
		lst[0] += 1
	if lst[2] != lst[1]:
		lst[2] -= 1
	elif lst[2] == lst[1] and lst[0] < lst[1]:
		lst[2] -= 1
		lst[1] -= 1
	d1 = lst[2] - lst[1]
	d2 = lst[2] - lst[0]
	d3 = lst[1] - lst[0]
	ans = d1 + d2 + d3
	print(ans)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve():
	pass
for _ in range(int(input())):
	(a, b, c) = get_int()
	res = abs(a - b) + abs(b - c) + abs(a - c)
	print(max(0, res - 4))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	dis = 9999999999999999999999999
	for i in range(a - 1, a + 2):
		for j in range(b - 1, b + 2):
			for k in range(c - 1, c + 2):
				if dis > abs(i - j) + abs(j - k) + abs(k - i):
					dis = abs(i - j) + abs(j - k) + abs(k - i)
	print(dis)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	a.sort()
	a0 = a[0]
	a1 = a[1]
	a2 = a[2]
	if a0 == a1 and a0 == a2:
		d = 0
	elif a0 == a1:
		if a2 - a1 > 1:
			d = 2 * (a2 - a1 - 2)
		else:
			d = 2 * (a2 - a1 - 1)
	elif a1 == a2:
		if a1 - a0 > 1:
			d = 2 * (a2 - a0 - 2)
		else:
			d = 2 * (a2 - a0 - 1)
	else:
		d = a2 - 1 - a1 + a1 - a0 - 1 + a2 - 1 - a0 - 1
	print(d)


for _ in range(int(input())):
	l = sorted(list(map(int, input().split())))
	ans = 2 * (l[2] - l[0])
	for i in [-1, 0, 1]:
		for j in [-1, 0, 1]:
			for k in [-1, 0, 1]:
				L = list(l)
				L[0] += i
				L[1] += j
				L[2] += k
				L.sort()
				ans = min(ans, 2 * (L[2] - L[0]))
	print(ans)


from sys import stdin
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(a, b, c) = sorted([a, b, c])
	if a == b == c:
		print(0)
	elif a == b or b == c:
		if a == b:
			a += 1
			if a == c:
				print(2 * abs(c - a))
			else:
				c -= 1
				print(2 * abs(c - a))
		else:
			a += 1
			if a == c:
				print(2 * abs(c - a))
			else:
				c -= 1
				print(2 * abs(c - a))
	else:
		a += 1
		c -= 1
		print(abs(a - b) + abs(b - c) + abs(c - a))


q = int(input())
for i in range(q):
	l = list(map(int, input().split()))
	l.sort()
	if l[0] == l[1] == l[2]:
		pass
	elif l[0] != l[1] and l[1] != l[2]:
		l[0] += 1
		l[2] -= 1
	elif l[0] == l[1]:
		l[0] += 1
		l[1] += 1
		if l[1] < l[2]:
			l[2] -= 1
	elif l[1] == l[2]:
		l[1] -= 1
		l[2] -= 1
		if l[1] > l[0]:
			l[0] += 1
	l.sort()
	print(2 * (l[2] - l[0]))


for _ in range(int(input())):
	arr = sorted(list(map(int, input().split())))
	dist = arr[2] - arr[0]
	if dist <= 2:
		print(0)
	else:
		print(2 * (dist - 2))


q = int(input())
while q > 0:
	q = q - 1
	l1 = list(map(int, input().split()))
	l1.sort()
	if l1[0] == l1[1] == l1[2]:
		print(0)
	elif l1[0] == l1[1]:
		if l1[2] - l1[0] > 1:
			print(2 * (l1[2] - l1[0] - 2))
		else:
			print(0)
	elif l1[1] == l1[2]:
		if l1[2] - l1[0] > 1:
			print(2 * (l1[2] - l1[0] - 2))
		else:
			print(0)
	else:
		d1 = l1[0] + 1
		d2 = l1[1]
		d3 = l1[2] - 1
		sum = d3 - d1 + d3 - d2 + d2 - d1
		print(sum)


n = int(input())
for i in range(n):
	s = input().split()
	(a, b, c) = (int(s[0]), int(s[1]), int(s[2]))
	min = abs(a - b) + abs(a - c) + abs(b - c)
	for j in range(3):
		a1 = a - 1 + j
		for k in range(3):
			b1 = b - 1 + k
			for l in range(3):
				c1 = c - 1 + l
				if abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1) < min:
					min = abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1)
	print(min)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	a = sorted([a, b, c])
	print(max(0, (a[-1] - a[0]) * 2 - 4))


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	l.sort()
	a = l[0]
	b = l[1]
	c = l[2]
	if a != b != c:
		a += 1
		c -= 1
	elif a == b and a != c:
		if c - 1 == b:
			c -= 1
		elif c - 1 > b:
			c -= 1
			a += 1
			b += 1
	elif b == c and b != a:
		if a + 1 == b:
			a += 1
		elif a + 1 < b:
			a += 1
			b -= 1
			c -= 1
	d = abs(a - b) + abs(a - c) + abs(b - c)
	print(d)


n = int(input())
for i in range(n):
	ch = input()
	L = [int(i) for i in ch.split()]
	L.sort()
	a = L[0]
	b = L[1]
	c = L[2]
	if c - a <= 2:
		print(0)
	else:
		a += 1
		c -= 1
		print(2 * abs(c - a))


def s(a, b, c):
	return abs(c - a) + abs(b - c) + abs(b - a)
n = int(input())
for i in range(n):
	mas = list(map(int, input().split()))
	mas.sort()
	(a, b, c) = (mas[0], mas[1], mas[2])
	ans = s(a, b, c)
	d = s(a + 1, b, c)
	ans = min(ans, d)
	d = s(a + 1, b, c - 1)
	ans = min(ans, d)
	d = s(a, b, c - 1)
	ans = min(ans, d)
	d = s(a, b - 1, c - 1)
	ans = min(ans, d)
	d = s(a, b - 1, c)
	ans = min(ans, d)
	d = s(a, b + 1, c - 1)
	ans = min(ans, d)
	d = s(a, b + 1, c)
	ans = min(ans, d)
	a += 1
	d = s(a, b - 1, c - 1)
	ans = min(ans, d)
	d = s(a, b - 1, c)
	ans = min(ans, d)
	d = s(a, b + 1, c - 1)
	ans = min(ans, d)
	d = s(a, b + 1, c)
	ans = min(ans, d)
	print(ans)


t = int(input())
for i in range(t):
	inp = sorted([int(i) for i in input().split()])
	ans1 = max(0, inp[2] - inp[1] - 1) + max(0, inp[1] - inp[0] - 1) + max(0, inp[2] - inp[0] - 2)
	ans2 = ans1
	if inp[0] == inp[1]:
		ans2 = max(0, 2 * (inp[2] - inp[1] - 2))
	if inp[1] == inp[2]:
		ans2 = max(0, 2 * (inp[1] - inp[0] - 2))
	print(min(ans1, ans2))


t = int(input())
for i in range(t):
	s = [int(i) for i in input().split()]
	s.sort()
	a = (max(s) + min(s)) // 2
	for i in range(3):
		if s[i] > a:
			s[i] -= 1
		elif s[i] < a:
			s[i] += 1
	print(sum([s[1] - s[0], s[2] - s[0], s[2] - s[1]]))


n = int(input())

def do_operation(a, avg):
	if a >= avg:
		if a != avg:
			a -= 1
	else:
		a += 1
	return a

def reduce_min_sum(a):
	for _ in range(2):
		if a == 0:
			break
		a -= 1
	return a

def get_min_pariwise(a, b, c):
	arr = [a, b, c]
	avg = (max(arr) + min(arr)) // 2
	a = do_operation(a, avg)
	b = do_operation(b, avg)
	c = do_operation(c, avg)
	s = 0
	s += abs(a - b)
	s += abs(b - c)
	s += abs(c - a)
	return s
for _ in range(n):
	(a, b, c) = map(int, input().split())
	print(get_min_pariwise(a, b, c))


def solve():
	q = int(input())
	for _ in range(q):
		a = list(map(int, input().split()))
		a.sort()
		if a[0] == a[2]:
			print(0)
		elif a[0] == a[1]:
			print(2 * max(0, a[2] - a[1] - 2))
		elif a[1] == a[2]:
			print(2 * max(0, a[1] - a[0] - 2))
		else:
			print(2 * (a[1] - a[0] - 1 + (a[2] - a[1] - 1)))
solve()


Q = int(input())
for _ in range(Q):
	(a, b, c) = tuple(map(int, input().split()))
	A = [a - 1, a, a + 1]
	B = [b - 1, b, b + 1]
	C = [c - 1, c, c + 1]
	comps = []
	for x in A:
		for y in B:
			for z in C:
				comps.append((x, y, z))
	ans = float('inf')
	for (a, b, c) in comps:
		ans = min(ans, abs(a - b) + abs(a - c) + abs(b - c))
	print(ans)


import math
test = int(input())
while test != 0:
	count = 0
	arr = list(map(int, input().split()))
	arr.sort()
	a = arr[0]
	b = arr[1]
	c = arr[2]
	if b != a:
		a += 1
	elif a + 1 <= c:
		a += 1
		b += 1
	if b != c:
		c -= 1
	elif c - 1 >= a:
		c -= 1
		b -= 1
	if c != b:
		b += 1
	elif a != b:
		b -= 1
	print(abs(a - b) + abs(b - c) + abs(a - c))
	test -= 1


for _ in range(int(input())):
	(x, y, z) = sorted(map(int, input().split()))
	if x == y == z:
		print(0)
	elif x == y and abs(y - z) == 1:
		print(0)
	elif x == y and abs(y - z) > 1:
		print(abs(y + 1 - (z - 1)) * 2)
	elif abs(x - y) == 1 and y != z:
		print(abs(y - (z - 1)) * 2)
	elif abs(x - y) == 1 and y == z:
		print(0)
	else:
		x += 1
		y -= 1
		z -= 1
		print(abs(x - y) + abs(y - z) + abs(z - x))


import sys
for _ in range(int(input())):
	(a, b, c) = sorted(list(map(int, input().split())))
	ans = abs(a - b) + abs(a - c) + abs(b - c)
	print(min(ans, abs(ans - 2), abs(ans - 4)))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(p, q, r) = (a, b, c)
	sum = 0
	mi = 5000000000
	for i in range(-1, 2, 1):
		for j in range(-1, 2, 1):
			for k in range(-1, 2, 1):
				p += i
				q += j
				r += k
				sum += abs(p - q) + abs(q - r) + abs(p - r)
				if mi > sum:
					mi = sum
				sum = 0
				(p, q, r) = (a, b, c)
	print(mi)


n = int(input())
for a in range(n):
	values = input().split()
	total = 0
	for b in range(len(values)):
		total += int(values[b])
		values[b] = int(values[b])
	target = round(total / 3)
	for b in range(len(values)):
		if values[b] < target:
			values[b] += 1
		elif values[b] > target:
			values[b] -= 1
	print(abs(values[0] - values[1]) + abs(values[0] - values[2]) + abs(values[1] - values[2]))


def get_m(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	k = get_m(a, b, c)
	if k in [0, 2, 4]:
		print(0)
	else:
		print(k - 4)


q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	ans = 3 * 10 ** 9
	for a1 in range(a - 1, a + 2):
		for b1 in range(b - 1, b + 2):
			for c1 in range(c - 1, c + 2):
				ans = min(ans, abs(a1 - b1) + abs(b1 - c1) + abs(c1 - a1))
	print(ans)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	a.sort()
	b = []
	b.append(a[1] - a[0] + a[2] - a[1] + a[2] - a[0])
	b.append(a[1] - a[0] + a[2] - a[1] + a[2] - a[0] - 2)
	b.append(a[1] - a[0] + a[2] - a[1] + a[2] - a[0] - 3)
	b.append(a[1] - a[0] + a[2] - a[1] + a[2] - a[0] - 4)
	b.sort()
	for i in b:
		if i >= 0:
			print(i)
			break
		elif i == b[len(b) - 1]:
			print(i)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	mindst = []
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				mindst.append(abs(a + i - b - j) + abs(a + i - c - k) + abs(b + j - c - k))
	mindst.sort()
	print(mindst[0])


def ans(data):
	data.sort()
	res = float('+inf')
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				res = min(res, abs(data[0] + i - j - data[1]) + abs(data[0] + i - k - data[2]) + abs(data[1] + j - k - data[2]))
	return res
n = int(input())
for i in range(n):
	inp = list(map(int, input().split()))
	print(ans(inp))


import math
q = int(input())
for tt in range(q):
	(a, b, c) = map(int, input().split())
	ans = 100000000000000
	for i in range(-1, 2):
		for j in range(-1, 2):
			for k in range(-1, 2):
				x = a + i
				y = b + j
				z = c + k
				ans = min(ans, abs(x - y) + abs(y - z) + abs(z - x))
	print(ans)


for _ in range(int(input())):
	a = sorted(list(map(int, input().split())))
	res1 = abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0]) - 4
	if res1 <= 0:
		print(0)
	else:
		print(res1)


q = int(input())
for xxxx in range(q):
	(a, b, c) = map(int, input().split())
	ar = []
	for a_ in range(a - 1, a + 2):
		for b_ in range(b - 1, b + 2):
			for c_ in range(c - 1, c + 2):
				ar.append(abs(a_ - b_) + abs(a_ - c_) + abs(b_ - c_))
	print(min(ar))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a == b and b == c:
		print('0')
	elif a == b:
		if abs(c - b) > 1:
			print(abs(a - b) + abs(b - c) + abs(c - a) - 4)
		else:
			print('0')
	elif b == c:
		if abs(c - a) > 1:
			print(abs(a - b) + abs(b - c) + abs(c - a) - 4)
		else:
			print('0')
	elif a == c:
		if abs(c - b) > 1:
			print(abs(a - b) + abs(b - c) + abs(c - a) - 4)
		else:
			print('0')
	else:
		print(abs(a - b) + abs(b - c) + abs(c - a) - 4)


import itertools
t = int(input())

def f(a, b, c):
	return abs(a - b) + abs(b - c) + abs(c - a)
l = [-1, 0, 1]
lis = list(itertools.product(l, repeat=3))
while t:
	(a, b, c) = map(int, input().split())
	ans = []
	for i in range(27):
		ans.append(f(a + lis[i][0], b + lis[i][1], c + lis[i][2]))
	print(min(ans))
	t = t - 1


for i in range(int(input())):
	(a, b, c) = sorted(list(map(int, input().split())))
	if a != b and b == c:
		if b - a == 1:
			a += 1
		else:
			a += 1
			b -= 1
			c -= 1
	elif a == b and b != c:
		if c - b == 1:
			c -= 1
		else:
			a += 1
			b += 1
			c -= 1
	elif a != b != c:
		a += 1
		c -= 1
	print(b - a + c - a + c - b)


def find_nearest(l):
	d = []
	near = 0
	min_dist = 99999999999999999999
	for i in range(0, len(l)):
		s = 0
		for j in range(0, len(l)):
			if i != j:
				s += abs(l[i] - l[j])
		if s < min_dist:
			min_dist = s
			near = i
	return near

def move_closer(l, closest):
	for i in range(0, len(l)):
		if i != closest:
			if l[i] < l[closest]:
				l[i] += 1
			elif l[i] > l[closest]:
				l[i] -= 1

def find_pairwise(l):
	d = abs(l[0] - l[1]) + abs(l[0] - l[2]) + abs(l[1] - l[2])
	return d
T = int(input())
for i in range(0, T):
	l = list(map(int, input().split()))
	x = l.copy()
	closest = find_nearest(l)
	move_closer(l, closest)
	optimal = find_pairwise(l)
	flag = 1
	if (x[0] == x[1] or x[1] == x[2] or x[0] == x[2]) and optimal != 0:
		for i in range(0, len(x)):
			if i != closest:
				if abs(x[i] - x[closest]) == 1:
					flag = -1
		if flag == 1:
			optimal -= 2
	print(optimal)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	if abs(a - b) + abs(b - c) + abs(a - c) == 1 or abs(a - b) + abs(b - c) + abs(a - c) == 2 or abs(a - b) + abs(b - c) + abs(a - c) == 3 or (abs(a - b) + abs(b - c) + abs(a - c) == 0):
		print(0)
	else:
		mini = abs(a - b) + abs(b - c) + abs(a - c)
		x = max(a, b, c)
		y = min(a, b, c)
		z = a + b + c - x - y
		x -= 1
		y += 1
		h = abs(x - y) + abs(y - z) + abs(x - z)
		z -= 1
		k = abs(x - y) + abs(y - z) + abs(x - z)
		z += 2
		i = abs(x - y) + abs(y - z) + abs(x - z)
		print(min(h, k, i))


def minimumPairWise(a, b, c):
	lst = []
	state = [1, 0, -1]
	for i in range(3):
		x = a + state[i]
		for k in range(3):
			y = b + state[k]
			for j in range(3):
				z = c + state[j]
				lst.append(totalPaireWise(x, y, z))
	print(min(lst))

def totalPaireWise(a, b, c):
	return abs(a - b) + abs(a - c) + abs(b - c)

def main():
	q = int(input())
	while q > 0:
		inpt = input().split()
		minimumPairWise(int(inpt[0]), int(inpt[1]), int(inpt[2]))
		q -= 1
main()


for i in range(int(input())):
	l1 = list(map(int, input().split()))
	l1.sort()
	a = l1[0]
	b = l1[1]
	c = l1[2]
	d = 0
	if len(set(l1)) == 1:
		d = 1
	elif len(set(l1)) == 3:
		a += 1
		c -= 1
	elif a == b:
		if c - a == 1:
			c -= 1
		else:
			c -= 2
	elif b == c:
		if b - a == 1:
			a += 1
		else:
			a += 2
	if d == 1:
		print(0)
	else:
		print(abs(a - b) + abs(b - c) + abs(a - c))


q = int(input())
for _ in range(q):
	min_val = 9999999999999
	(a, b, c) = [int(x) for x in input().split()]
	for i in [a - 1, a, a + 1]:
		for j in [b - 1, b, b + 1]:
			for k in [c - 1, c, c + 1]:
				min_val = min(min_val, abs(i - j) + abs(j - k) + abs(k - i))
	print(min_val)


t = int(input())
for w in range(t):
	x = [int(i) for i in input().split()]
	x.sort()
	a = x[0]
	b = x[1]
	c = x[2]
	if a == b == c:
		print(0)
		continue
	if a + 1 == b == c:
		print(0)
		continue
	if a + 1 == b + 1 == c:
		print(0)
		continue
	a += 1
	b += 1
	c -= 1
	print(abs(a - b + (a - c) + (b - c)))


t = int(input())
while t:
	a = list(map(int, input().split()))
	a.sort()
	if a[0] == a[-1]:
		print(0)
	elif a[0] == a[1]:
		a[0] += 1
		a[1] += 1
		if a[-1] != a[1]:
			a[-1] -= 1
		print(abs(a[0] - a[1]) + abs(a[1] - a[-1]) + abs(a[0] - a[-1]))
	elif a[1] == a[-1]:
		a[1] -= 1
		a[-1] -= 1
		if a[1] != a[0]:
			a[0] += 1
		print(abs(a[0] - a[1]) + abs(a[1] - a[-1]) + abs(a[0] - a[-1]))
	else:
		a[-1] -= 1
		a[0] += 1
		if a[1] == a[0] or a[1] == a[-1]:
			print(abs(a[0] - a[1]) + abs(a[1] - a[-1]) + abs(a[0] - a[-1]))
		else:
			print(abs(a[0] - (a[1] + 1)) + abs(a[1] + 1 - a[-1]) + abs(a[0] - a[-1]))
	t -= 1


I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	a = LI()
	a.sort()
	if a[0] == a[1] and a[1] == a[2]:
		print(0)
	else:
		c = min(a)
		d = max(a)
		if a[2] - a[0] <= 2:
			print(0)
		elif a.count(c) > 1 or a.count(d) > 1:
			ans = d - c
			if d <= 2:
				print(0)
			else:
				print((ans - 2) * 2)
		else:
			a[0] += 1
			a[2] -= 1
			print(abs(a[0] - a[1]) + abs(a[1] - a[2]) + abs(a[2] - a[0]))


q = int(input())
qs = []
for i in range(q):
	li = list(map(int, input().split()))
	li.sort()
	if li[0] <= li[1] and li[0] < li[2]:
		li[0] += 1
	if li[2] >= li[1] and li[2] > li[0]:
		li[2] -= 1
	sum = 2 * (li[2] - li[0])
	print(sum)


q = int(input())
for _ in range(q):
	ara = list(map(int, input().split()))
	ara.sort()
	distance = ara[1] - ara[0] + (ara[2] - ara[1]) + (ara[2] - ara[0]) - 4
	print(max(0, distance))


for x in range(int(input())):
	l = list(map(int, input().split()))
	l.sort()
	d = 2 * (l[2] - l[0])
	if d <= 4:
		print(0)
	else:
		print(d - 4)


import sys
q = int(input())
for i in range(q):
	(a, b, c) = map(int, input().split())
	g = [a, b, c]
	g.sort()
	ans = (g[2] - g[0] - 2) * 2
	if ans > 0:
		print((g[2] - g[0] - 2) * 2)
	else:
		print(0)