Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! 

Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.

Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.

According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.


-----Input-----

The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 10^18,  b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. 


-----Output-----

Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. 


-----Examples-----
Input
3 2 1

Output
1


Input
1 0 0

Output
0


Input
1 1 1

Output
0


Input
1000000000000000000 0 1000000000000000000

Output
999999999999999999





-----Note-----

In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. 

In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.

In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.

Difficulty: EASY

Solutions:
l = list(map(int, input().split()))
ans = 10 ** 22
for st in range(4):
	for fin in range(4):
		new_l = [0] * 3
		new_l[0] = l[0]
		new_l[1] = l[1]
		new_l[2] = l[2]
		if st < 3:
			for i in range(0, st + 1):
				new_l[i] += 1
		if fin < 3:
			for i in range(0, fin + 1):
				new_l[i] -= 1
		cur_ans = 0
		for i in range(3):
			cur_ans += abs(max(new_l) - new_l[i])
		ans = min(ans, cur_ans)
print(ans)


(b, d, s) = map(int, input().split())
if b >= d and b >= s:
	print(max(b - 1 - d, 0) + max(b - 1 - s, 0))
elif d >= b and d >= s:
	print(max(d - b - 1, 0) + max(d - 1 - s, 0))
elif s >= b and s >= d:
	print(max(s - 1 - d, 0) + max(s - 1 - b, 0))


(a, b, c) = input().strip().split(' ')
(a, b, c) = (int(a), int(b), int(c))
m = max(a, b, c)
if a == b and b == c:
	print(0)
	exit()
if a == m and b < a and (c < a):
	print(2 * a - 2 - b - c)
elif b == m and b > c:
	if a < b:
		print(b - 1 + b - 1 - a - c)
	elif a == b:
		print(2 * b - 1 - a - c)
elif m == c:
	if a < c and b < c:
		print(c + c - 2 - a - b)
	elif a == c and b < c:
		print(c - 1 - b)
	elif a < c and b == c:
		print(c - 1 - a)


l_t = list(map(int, input().split()))
print(sum((max(0, max(l_t) - x - 1) for x in l_t)))


l = list(map(int, input().split()))
l.sort()
mi = l[0]
mid = l[1]
ma = l[2]
count = 0
count += max(0, ma - mi - 1)
count += max(0, ma - mid - 1)
print(count)


import sys, math, random
(a, b, c) = map(int, input().split())
ans = 10 ** 100
max_ = max(a, b, c)
ans = max_ - a + max_ - b + max_ - c
if a > b and a > c:
	ans = min(ans, a - 1 - b + a - 1 - c)
else:
	ans = min(ans, max_ + 1 - a + max_ - b + max_ - c)
gg = max(a, b)
hh = max(a, c)
tt = max(b, c)
if gg > c:
	ans = min(ans, gg - a + gg - b + gg - c - 1)
else:
	ans = min(ans, c + 1 - a + c + 1 - b)
if b > a and b > c:
	ans = min(ans, b - 1 - a + b - 1 - c)
else:
	ans = min(ans, hh - a + hh - c + hh + 1 - b)
if tt > a:
	ans = min(ans, tt - a - 1 + tt - b + tt - c)
else:
	ans = min(ans, a + 1 - b + a + 1 - c)
if c > a and c > b:
	ans = min(ans, c - a - 1 + c - b - 1)
else:
	ans = min(ans, gg - a + gg - b + gg + 1 - c)
if hh > b:
	ans = min(ans, hh - a + hh - b - 1 + hh - c)
else:
	ans = min(ans, b + 1 - a + b + 1 - c)
print(ans)


def solve(morning, lunch, dinner):
	largest = max(morning, lunch, dinner)
	ans = 0
	if largest - morning > 1:
		ans += largest - morning - 1
	if largest - lunch > 1:
		ans += largest - lunch - 1
	if largest - dinner > 1:
		ans += largest - dinner - 1
	return ans
(m, l, d) = list(map(int, input().split()))
print(solve(m, l, d))


(a, b, c) = map(int, input().split())
s = max(a, b, c)
g = s - a
l = s - b
j = s - c
if g != 0:
	g = abs(g) - 1
if l != 0:
	l = abs(l) - 1
if j != 0:
	j = abs(j) - 1
r = g + l + j
print(r)


(a, b, c) = sorted(map(int, input().split()))
c -= 1
print(max(0, c - a) + max(0, c - b))


a = list(map(int, input().split()))
m = max(a[0], a[1], a[2]) - 1
t = 0
for n in a:
	if m > n:
		t += m - n
print(t)


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


(b, d, c) = map(int, input().split())
m = max(b, d, c)
ans = 0
for i in (b, d, c):
	if m != i:
		ans += m - i - 1
print(ans)


(b, d, s) = [int(i) for i in input().split(' ')]
if b > d and b > s:
	print(2 * b - d - s - 2)
elif d > b and d > s:
	print(2 * d - b - s - 2)
elif s > d and s > b:
	print(2 * s - b - d - 2)
elif b == d and d == s:
	print(0)
elif b == d and d > s:
	print(b - s - 1)
elif b == s and s > d:
	print(b - d - 1)
elif d == s and s > b:
	print(d - b - 1)


(a, b, c) = list(map(int, input().split()))
x = max(a, b, c)
a = x - a
b = x - b
c = x - c
if a > 0 and b > 0 or (a > 0 and c > 0) or (b > 0 and c > 0):
	print(a + b + c - 2)
elif a > 0 or b > 0 or c > 0:
	print(a + b + c - 1)
else:
	print(a + b + c)


def main():
	DELTAS = ((0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0))
	try:
		while True:
			(b, d, s) = map(int, input().split())
			result = 1e+19
			for (db, dd, ds) in DELTAS:
				(x, y, z) = sorted((b + db, d + dd, s + ds))
				result = min(result, (z << 1) - x - y)
			print(result)
	except EOFError:
		pass
main()


import sys
fin = sys.stdin
fout = sys.stdout
(b, s, d) = map(int, fin.readline().split())
wars = []

def nextDelta(dB, dS, dD):
	tempB = b + dB
	tempS = s + dS
	tempD = d + dD
	m = max(tempB, tempS, tempD)
	rz = 0
	rz += abs(m - tempB)
	rz += abs(m - tempS)
	rz += abs(m - tempD)
	wars.append(abs(rz))
nextDelta(1, 0, 1)
nextDelta(1, 1, 1)
nextDelta(2, 1, 1)
nextDelta(2, 2, 1)
nextDelta(1, 2, 1)
nextDelta(1, 1, 1)
nextDelta(2, 2, 2)
nextDelta(1, 2, 2)
nextDelta(1, 1, 2)
nextDelta(0, 0, 0)
fout.write(str(min(wars)))


(b, d, s) = map(int, input().split())
mx = max(b, d, s) - 1
print(max(0, mx - b) + max(0, mx - d) + max(0, mx - s))


t = list(map(int, input().split()))
a = max(t)
b = min(t)
if a - b <= 1:
	print(0)
else:
	t.sort()
	ans = a - b - 1
	if t[1] + 1 < t[-1]:
		ans += t[-1] - t[1] - 1
	print(ans)


def pos(n):
	if n < 0:
		return 0
	return n
li = list(map(int, input().split()))
li.sort()
ans = pos(li[2] - li[1] - 1) + pos(li[2] - li[0] - 1)
print(ans)


(b, d, s) = map(int, input().split())
ans = float('infinity')
ans = min(ans, 2 * max(b, d, s) - min(b, d, s) - (b + d + s - min(b, d, s) - max(b, d, s)))
ans = min(ans, 2 * max(b - 1, d, s) - min(b - 1, d, s) - (b - 1 + d + s - min(b - 1, d, s) - max(b - 1, d, s)))
ans = min(ans, 2 * max(b, d - 1, s) - min(b, d - 1, s) - (b + d - 1 + s - min(b, d - 1, s) - max(b, d - 1, s)))
ans = min(ans, 2 * max(b, d, s - 1) - min(b, d, s - 1) - (b + d + s - 1 - min(b, d, s - 1) - max(b, d, s - 1)))
ans = min(ans, 2 * max(b - 1, d - 1, s) - min(b - 1, d - 1, s) - (b - 1 + d - 1 + s - min(b - 1, d - 1, s) - max(b - 1, d - 1, s)))
ans = min(ans, 2 * max(b, d - 1, s - 1) - min(b, d - 1, s - 1) - (b + d - 1 + s - 1 - min(b, d - 1, s - 1) - max(b, d - 1, s - 1)))
ans = min(ans, 2 * max(b - 1, d, s - 1) - min(b - 1, d, s - 1) - (b - 1 + d + s - 1 - min(b - 1, d, s - 1) - max(b - 1, d, s - 1)))
print(ans)


l = list(map(int, input().split()))
l.sort()
ans = 0
if l[-2] >= l[-1] - 1:
	ans += 0
else:
	ans = ans + l[-1] - l[-2] - 1
if l[-3] >= l[-1] - 1:
	ans += 0
else:
	ans = ans + l[-1] - l[-3] - 1
print(ans)


(b, d, s) = map(int, input().split())
p = max(b, d, s)
num = float('inf')
if p == b:
	tmp = 0
	tmp += max(0, p - 1 - d)
	tmp += max(0, p - 1 - s)
	num = min(num, tmp)
if p == d:
	tmp = 0
	tmp += max(0, p - 1 - b)
	tmp += max(0, p - 1 - s)
	num = min(num, tmp)
if p == s:
	tmp = 0
	tmp += max(0, p - 1 - b)
	tmp += max(0, p - 1 - d)
	num = min(num, tmp)
print(num)


(*l,) = map(int, input().split())
m = max(l) - 1
print(sum((m - a for a in l if m > a)))


def get(x, y, z):
	return max(x, y, z) * 3 - x - y - z
(a, b, c) = list(map(int, input().split()))
ans = min(get(a, b, c), get(a - 1, b, c), get(a - 1, b - 1, c), get(a, b - 1, c), get(a, b - 1, c - 1), get(a, b, c - 1), get(a - 1, b, c - 1))
print(ans)


from sys import stdin, stderr

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

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(b, d, s):
	bds = [b, d, s]
	c = max(bds)
	bds2 = []
	for v in bds:
		if v != c:
			bds2.append(v)
	c -= 1
	bds3 = [max(0, c - v) for v in bds2]
	return sum(bds3)

def run():
	(b, d, s) = readInts()
	print(solve(b, d, s))
run()


(b, d, s) = map(int, input().split())
ans = 10 ** 19
if b <= 1 and d <= 1 and (s <= 1):
	print(0)
else:
	for i in range(64, 128):
		k = 0
		(_, u, v, w, x, y, z) = map(int, bin(i)[2:])
		if u + x > b or v + y > d or w + z > s:
			continue
		if u:
			k += 2 - v - w
		elif v:
			k += 1 - w
		if z:
			k += 2 - x - y
		elif y:
			k += 1 - x
		day = max(b - u - x, d - v - y, s - w - z)
		k += day * 3 - (b + d + s - u - v - w - x - y - z)
		ans = min(ans, k)
	print(ans)


a = list(map(int, input().split()))
u = max(a)
r = 0
for i in a:
	if i != u and i < u - 1:
		r += u - 1 - i
print(r)


(b, d, s) = map(int, input().split())
ans = 10 ** 20
n = max(d, b, s)
for n in range(max(max(d, b, s) - 2, 0), max(d, b, s) + 3):
	for i in range(4):
		for j in range(4):
			z = n - (i > 0) - (j <= 0)
			o = n - (i > 1) - (j <= 1)
			u = n - (i > 2) - (j <= 2)
			if z >= b and o >= d and (u >= s):
				ans = min(ans, z + o + u - (b + d + s))
print(ans)


(a, b, c) = map(int, input().split())

def solve(v):
	ans = 0
	d = max(v) - 1
	for i in range(3):
		v[i] -= d
		ans += max(0, -v[i])
	i = 0
	while max(v) > 0:
		v[i] -= 1
		if v[i] < 0:
			ans += 1
		i = (i + 1) % 3
	return ans
print(min(solve([a, b, c]), solve([a, b - 1, c - 1]), solve([a, b, c - 1])))


(b, d, s) = map(int, input().split())
m = max(b, d, s)
print(max(0, m - 1 - b) + max(0, m - 1 - d) + max(0, m - 1 - s))


(b, d, s) = sorted(map(int, input().split()))
print(max(0, s - b - 1) + max(0, s - d - 1))


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


arr = [int(x) for x in input().split()]
c = max(arr)
a = min(arr)
b = sum(arr) - c - a
answer = 0
if b < c - 1:
	answer += c - b - 1
if a < c - 1:
	answer += c - a - 1
print(answer)


(b, d, s) = list(map(int, input().split()))
(a1, a2, a3, a4) = (0, 0, 0, 0)
if max(b, s, d) == b:
	if d < b - 1 and s != max(b, s, d):
		a1 += b - 1 - d
	if d < b - 1 and s == max(b, s, d):
		a1 += b - d
	if s < b - 1:
		a1 += b - 1 - s
elif max(b, s, d) == d:
	a1 += d - b
	if s < d - 1:
		a1 += d - 1 - s
elif max(b, s, d) == s:
	a1 += s - d
	a1 += s - b
(b1, d1, s1) = (d, s, b)
if max(b1, s1, d1) == b1:
	if d1 < b1 - 1 and s1 != max(b1, s1, d1):
		a2 += b1 - 1 - d1
	if d1 < b1 - 1 and s1 == max(b1, s1, d1):
		a2 += b1 - d1
	if s1 < b1 - 1:
		a2 += b1 - 1 - s1
elif max(b1, s1, d1) == d1:
	a2 += d1 - b1
	if s1 < d1 - 1:
		a2 += d1 - 1 - s1
elif max(b1, s1, d1) == s1:
	a2 += s1 - d1
	a2 += s1 - b1
(b, d, s) = (s, b, d)
if max(b, s, d) == b:
	if d < b - 1 and s != max(b, s, d):
		a3 += b - 1 - d
	if d < b - 1 and s == max(b, s, d):
		a3 += b - d
	if s < b - 1:
		a3 += b - 1 - s
elif max(b, s, d) == d:
	a3 += d - b
	if s < d - 1:
		a3 += d - 1 - s
elif max(b, s, d) == s:
	a3 += s - d
	a3 += s - b
print(min(a1, a2, a3))


(B, L, S) = (int(x) for x in input().split())
K = max(B, L, S)
cost = 0
for meal in [B, L, S]:
	if meal != K:
		cost += K - 1 - meal
print(cost)


from sys import stdin as fin
(b, l, d) = map(int, fin.readline().split())
variants_start = ((0, 0, 0), (-1, 0, 0), (-1, -1, 0))
variants_end = ((0, 0, 0), (0, 0, -1), (0, -1, -1))
n = max(b, l, d)
ans = float('inf')
mbr = mlr = mdr = 0
mi = 0
for i in range(n, n + 100):
	for (bs, ls, ds) in variants_start:
		for (be, le, de) in variants_end:
			(br, lr, dr) = (i + bs + be, i + ls + le, i + ds + de)
			res = br - b + lr - l + dr - d
			if br >= b and lr >= l and (dr >= d) and (ans > res):
				ans = res
				(mbr, mlr, mdr) = (br, lr, dr)
				mi = i
print(ans)


def do():
	(b, d, s) = map(int, input().split())
	x = max(b, d, s)
	z = min(b, d, s)
	y = b + d + s - x - z
	if x == y == z:
		return 0
	elif x == y:
		return x - z - 1
	elif y == z:
		return 2 * (x - y - 1)
	else:
		return 2 * (x - 1 - y) + y - z
rs = do()
print(rs)


I = lambda : list(map(int, input().split()))
a = I()
l = max(a)
maxa = [i == l for i in a]
if sum(maxa) == 1:
	ans = sum([l - 1 - i for i in a if i != l])
elif sum(maxa) == 2:
	ans = l - 1 - (sum(a) - 2 * l)
elif sum(maxa) == 3:
	ans = 0
print(ans)


def hren():
	input_list = input().split(' ')
	supper = [int(x.strip()) for x in input_list]
	supper.sort(reverse=True)
	result = supper[0] - supper[1] + supper[0] - supper[2]
	if supper[0] != supper[1]:
		result -= 1
	if supper[0] != supper[2]:
		result -= 1
	return result
print(hren())


line1 = input()
cart = [int(x) for x in line1.split(' ')]
breakfast = cart[0]
lunch = cart[1]
supper = cart[2]
total_meals = sum(cart)
firstDay_meals = 0
lastDay_meals = 0
firstDay_count = 0
lastDay_count = 0
result = 0
max_meals = max(cart)
for i in range(len(cart) - 1, -1, -1):
	if cart[i] == max_meals:
		if cart[i - 1] == cart[i] == cart[i - 2]:
			start_ind = 0
			stop_ind = 2
			break
		elif cart[i - 1] == cart[i]:
			start_ind = i - 1
			stop_ind = i
			break
		else:
			stop_ind = i
			start_ind = i
if start_ind > stop_ind:
	days = max_meals + 1
else:
	days = max_meals
if max(cart) == 1:
	result = 0
else:
	for firstDay in range(start_ind, len(cart)):
		firstDay_meals += 1
		if cart[firstDay] == 0:
			firstDay_count += 1
		else:
			cart[firstDay] -= 1
	for lastDay in range(0, stop_ind + 1):
		lastDay_meals += 1
		if cart[lastDay] - days + 2 > 0:
			lastDay_count += 1
	result = (days - 2) * 3 + firstDay_meals + lastDay_meals - total_meals
print(result)


read = lambda : map(int, input().split())
(b, d, s) = read()
A = ((0, 0, 0), (1, 0, 0), (1, 1, 0))
B = ((0, 0, 0), (0, 0, 1), (0, 1, 1))
ans = float('inf')
for (x1, y1, z1) in A:
	for (x2, y2, z2) in B:
		(x, y, z) = (x1 + x2, y1 + y2, z1 + z2)
		k = max(b - x, d - y, s - z)
		cur = k + x - b + (k + y - d) + (k + z - s)
		ans = min(ans, cur)
print(ans)


(a, b, c) = map(int, input().split())
m = max(a, b, c)
ans = max(0, m - a - 1) + max(0, m - b - 1) + max(0, m - c - 1)
print(ans)


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


x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
mexx = max(max(a, b), c)
mexx -= 1
ans = 0
ans += max(0, mexx - a)
ans += max(0, mexx - b)
ans += max(0, mexx - c)
print(ans)


(a, b, c) = map(int, input().split())
ans = 0
if a == b and a == c:
	ans = 0
elif a > b and a > c:
	ans = a - b - 1 + (a - c - 1)
elif a == b and c < a:
	ans = a - c - 1
elif a == c and b < a:
	ans = a - b - 1
elif b > a and b > c:
	ans = b - a - 1 + (b - c - 1)
elif b == c:
	ans = b - a - 1
elif c > a and c > b:
	ans = c - a - 1 + (c - b - 1)
print(ans)


__author__ = 'Think'
meals = [int(i) for i in input().split()]
large = max(meals) - 1
total = 0
for i in meals:
	total += max(0, large - i)
print(total)


from sys import stdin
li = list(map(int, input().strip().split()))
mn = min(li)
for i in range(len(li)):
	li[i] -= mn
mx = max(li)
ans = 0
if mx == 0:
	ans = 0
elif li.count(mx) == 2:
	ans = mx - 1
else:
	ans = (mx - 1) * 3 - sum(li) + 1
print(ans)


(a, b, c) = map(int, input().split())
m = max(a, b, c)
if a == b and b == c:
	print(0)
elif 2 * m == a + b or 2 * m == b + c or 2 * m == a + c:
	print(3 * m - a - b - c - 1)
else:
	print(3 * m - a - b - c - 2)


def diff(A, B):
	tot = 0
	for i in range(3):
		if A[i] > B[i]:
			return float('inf')
		tot += B[i] - A[i]
	return tot
(b, d, s) = map(int, input().split())
(a, b, c) = max([b, d, s], [d, s, b], [s, b, d])
print(min(diff([a, b, c], [a, a, a]), diff([a, b, c], [a, a, a - 1]), diff([a, b, c], [a, a - 1, a - 1])))


(x, y, z) = [int(i) for i in input().split()]
m = max(x, y, z)
k = 2
if m == x:
	if x == y:
		k -= 1
	if x == z:
		k -= 1
	ans = 2 * m - y - z - k
elif m == y:
	if y == x:
		k -= 1
	if y == z:
		k -= 1
	ans = 2 * m - x - z - k
elif m == z:
	if y == z:
		k -= 1
	if x == z:
		k -= 1
	ans = 2 * m - x - y - k
print(ans)


(b, d, s) = map(int, input().split(' '))
if b == d and d == s:
	print('0')
elif b != d and d != s and (b != s):
	count1 = 0
	k = max(b, d, s) - 1
	if k - b > 0:
		count1 += k - b
	if k - d > 0:
		count1 += k - d
	if k - s > 0:
		count1 += k - s
	print(count1)
elif b == 0 and d == 0 and (s != 0):
	print((s - 1) * 2)
elif b != 0 and d == 0 and (s == 0):
	print((b - 1) * 2)
elif d != 0 and b == 0 and (s == 0):
	print((d - 1) * 2)
elif b == d and d != s:
	if b > s:
		print(b - 1 - s)
	else:
		print((s - 1 - b) * 2)
elif b == s and s != d:
	if b > d:
		print(b - 1 - d)
	else:
		print((d - 1 - b) * 2)
elif s == d and s != b:
	if s > b:
		print(d - 1 - b)
	else:
		print((b - 1 - d) * 2)


mas = list(map(int, input().split()))
mas.sort()
ans = 0
if mas[2] != mas[1]:
	ans += mas[2] - mas[1] - 1
	mas[1] = mas[2] - 1
if mas[0] != mas[1]:
	if mas[1] == mas[2]:
		ans += mas[1] - mas[0] - 1
	else:
		ans += mas[1] - mas[0]
	mas[0] = mas[1]
print(ans)


def solve(a, b, c):
	if a < 0 or b < 0 or c < 0:
		return 1e+19
	if a == 0 and b == 0 and (c == 0):
		return 0
	a = max(a, 0)
	b = max(b, 0)
	c = max(c, 0)
	d = min(a, b, c)
	a = a - d
	b = b - d
	c = c - d
	arr = [a, b, c]
	arr.sort()
	return arr[1] + (arr[2] - arr[1]) * 2
(a, b, c) = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
ans = 1e+19
ans = min(ans, solve(a, b, c))
ans = min(ans, solve(a, b - 1, c))
ans = min(ans, solve(a - 1, b, c))
ans = min(ans, solve(a, b, c - 1))
ans = min(ans, solve(a - 1, b - 1, c))
ans = min(ans, solve(a - 1, b, c - 1))
ans = min(ans, solve(a, b - 1, c - 1))
ans = min(ans, solve(a - 1, b - 2, c - 1))
print(ans)


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 = 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 main():
	a = LI()
	m = max(a)
	r = 0
	for c in a:
		r += max(0, m - 1 - c)
	return r
print(main())


l = [int(i) for i in input().split()]
m = max(l)
print(sum((m - z - 1 for z in l if z < m)))


from math import *
from collections import *
from random import *
from bisect import *
import sys

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

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

def inp():
	return int(input())
(b, d, s) = ma()
z = [b, d, s]
z.sort()
s = abs(max(z[-1] - z[-2] - 1, 0)) + abs(max(z[-1] - z[-3] - 1, 0))
if s <= 0:
	print(0)
else:
	print(s)


def fun(b, d, s):
	if b == d == s:
		return 0
	if b > d and b > s:
		return b - 1 - d + (b - 1 - s)
	if d > b and d > s:
		return d - 1 - b + (d - 1 - s)
	if s > b and s > d:
		return s - 1 - b + (s - 1 - d)
	if b == d and b > s:
		return b - 1 - s
	if b == s and b > d:
		return b - 1 - d
	if d == s and d > b:
		return d - 1 - b
	return 0
(b, d, s) = map(int, input().split())
ans = fun(b, d, s)
print(ans)


numbers = [int(n) for n in input().split()]
b = numbers[0]
d = numbers[1]
s = numbers[2]
ans = max(numbers) * 3 - sum(numbers)
for i in range(3):
	op1 = max(numbers) * 3 - sum(numbers)
	op2 = op1
	if b > d and b > s:
		op2 = b * 3 - sum(numbers) - 2
	elif d >= b and d > s:
		op2 = d * 3 - sum(numbers) + 1
	else:
		op2 = s * 3 - sum(numbers) + 1
	op3 = op1
	if b > d and b > s:
		op3 = b * 3 - sum(numbers) - 1
	elif d >= b and d > s:
		op3 = d * 3 - sum(numbers) - 1
	else:
		op3 = s * 3 - sum(numbers) + 2
	ans = min(ans, min(op3, op2))
	aux = b
	b = d
	d = s
	s = aux
print(ans)


(a, b, c) = map(int, input().split())
h = max(a, b, c)
g = h - a
j = h - b
k = h - c
if g != 0:
	g -= 1
if j != 0:
	j -= 1
if k != 0:
	k -= 1
print(g + j + k)


(x, y, z) = input().split(' ')
x = int(x)
y = int(y)
z = int(z)
m = max(x, y, z)
m1 = m - x - 1
m2 = m - y - 1
m3 = m - z - 1
c = 0
if m1 > 0:
	c += m1
if m2 > 0:
	c += m2
if m3 > 0:
	c += m3
print(c)


m = input()
b = int(m.split()[0])
d = int(m.split()[1])
s = int(m.split()[2])
arr = [b, d, s]
total = 3 * max(arr) - 2
visited = b + d + s
if arr.count(max(arr)) != 1:
	total += 1 + (b == d and b == s)
print(total - visited)


(a, b, c) = map(int, input().split(' '))
if a + b + c == 1:
	print('0')
	exit()
elif a == b and b == c:
	print('0')
	exit()
d = max(a, b, c)
res = 0
if a < d:
	res = res + (d - a - 1)
if b < d:
	res = res + (d - b - 1)
if c < d:
	res = res + (d - c - 1)
print(res)


(b, d, s) = list(map(int, input().split()))
r = 0
if b == s and d == s:
	print(0)
elif b >= s and b >= d:
	print(max(0, abs(b - d) - 1) + max(abs(b - s) - 1, 0))
elif s >= b and s >= d:
	print(max(0, abs(s - b) - 1) + max(abs(s - d) - 1, 0))
elif d >= s and d >= b:
	print(max(0, abs(d - s) - 1) + max(abs(d - b) - 1, 0))


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')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
array = list(map(int, input().split()))
last = max(array) - 1
ans = 0
for i in range(3):
	if last - array[i] > 0:
		ans += last - array[i]
print(ans)


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


n = list(map(int, input().split()))
k = n[:]
m = max(n)
s = min(n)
k.remove(s)
g = min(k)
if len(list(set(n))) == 1:
	print(0)
elif s == g:
	m = m - 1
	print(m - g + m - s)
elif m == g:
	m -= 1
	print(m - s)
else:
	m -= 1
	print(m - s + m - g)


def rest(lst):
	m = max(lst)
	return max(0, m - 1 - lst[0]) + max(0, m - 1 - lst[2]) + max(0, m - 1 - lst[1])
a = [int(i) for i in input().split()]
print(rest(a))


cnt = list(map(int, input().split()))
cnt.sort()
(small, middle, large) = cnt
if large > middle:
	print((large - 1) * 2 - middle - small)
elif middle > small:
	print(middle - small - 1)
else:
	print(0)


(b, d, s) = map(int, input().split())

def calc(b, d, s):
	return max(b, d, s) * 3 - sum((b, d, s))
res = []
res.append(calc(b, d, s))
res.append(calc(b, d, s - 1))
res.append(calc(b, d - 1, s - 1))
res.append(calc(b - 1, d, s))
res.append(calc(b - 1, d - 1, s))
res.append(calc(b - 1, d, s - 1))
res.append(calc(b - 1, d - 1, s - 1))
res.append(calc(b - 1, d - 2, s - 1))
print(min(res))


a = [int(s) for s in input().split()]
mi = min(a)
a[0] = a[0] - mi
a[1] = a[1] - mi
a[2] = a[2] - mi
if a[0] == a[1] and a[1] == a[2]:
	print(0)
elif max(a) == a[0]:
	if a[0] == a[1] or a[0] == a[2]:
		print(a[0] - min(a) - 1)
	else:
		print(2 * a[0] - 2 - a[1] - a[2])
elif max(a) == a[1]:
	if a[1] == a[2]:
		print(max(a) - min(a) - 1)
	else:
		print(2 * a[1] - 2 - a[2] - a[0])
elif max(a) == a[2]:
	print(2 * a[2] - 2 - a[1] - a[0])


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())
(a, b, c) = sorted(il(), reverse=True)
sm = 0
if a != b:
	sm += max(0, a - b - 1) + max(0, a - c - 1)
else:
	sm += max(0, b - c - 1)
print(sm)


def main():
	(b, d, s) = map(int, input().split())
	if b + d + s < 3 and b < 2 and (d < 2) and (s < 2):
		return 0
	if b == d == s == 1:
		return 0
	ans = []
	for start in range(3):
		for finish in range(3):
			breakfast_add = 0
			dinner_add = 0
			supper_add = 0
			for i in range(start, 3):
				if i == 0:
					breakfast_add += 1
				elif i == 1:
					dinner_add += 1
				else:
					supper_add += 1
			for i in range(finish + 1):
				if i == 0:
					breakfast_add += 1
				elif i == 1:
					dinner_add += 1
				else:
					supper_add += 1
			n = -1
			if b <= breakfast_add and d <= dinner_add and (s <= supper_add):
				n = 0
			else:
				left = 0
				right = 10 ** 19
				while left + 1 < right:
					mid = (left + right) // 2
					if b <= mid + breakfast_add and d <= mid + dinner_add and (s <= mid + supper_add):
						right = mid
					else:
						left = mid
				n = right
			ans.append(3 * n + breakfast_add + dinner_add + supper_add - b - d - s)
	return min(ans)
print(main())


def distance(position):
	if b > position[0] or d > position[1] or s > position[2]:
		return 10 ** 20
	return abs(b - position[0] + d - position[1] + s - position[2])
(b, d, s) = map(int, input().split())
(old_b, old_d, old_s) = (b, d, s)
max1 = max(b, d, s)
f = True
if max1 - b > 1 or max1 - d > 1 or max1 - s > 1:
	f = False
if f:
	print(0)
	exit()
max1 = max(b, d, s)
positions = [[0] * 3 for _ in range(7)]
positions[0] = [max1, max1 - 1, max1 - 1]
positions[1] = [max1, max1, max1 - 1]
positions[2] = [max1, max1, max1]
positions[3] = [max1 - 1, max1, max1 - 1]
positions[4] = [max1 - 1, max1, max1]
positions[5] = [max1 - 1, max1 - 1, max1]
positions[6] = [max1, max1 - 1, max1]
ans = 10 ** 20
for position in positions:
	ans = min(ans, distance(position))
print(ans)


a = map(int, input().split(' '))
a = sorted(a)
c = 0
if a[2] == a[0]:
	c = 0
elif a[2] == a[1]:
	c = 1
else:
	c = 2
ans = 3 * a[2] - c - sum(a)
print(ans)


meals = list(map(int, input().split()))
meals.sort()
maxmiss = meals[2] - meals[0] - 1
secondmiss = meals[2] - meals[1] - 1
if maxmiss > 0:
	answer = maxmiss + secondmiss if secondmiss > 0 else maxmiss
	print(answer)
else:
	print(0)


(b, d, s) = map(int, input().split())
maxi = max(b, d, s)
c = 0
if maxi - 1 - b > 0:
	c += maxi - 1 - b
if maxi - 1 - d > 0:
	c += maxi - 1 - d
if maxi - 1 - s > 0:
	c += maxi - 1 - s
print(c)


def c(ans, b, d, s):
	return min(ans, 3 * max(b, d, s) - b - d - s)
(b, d, s) = list(map(int, input().split()))
ans = 10 ** 19
m = min(b, d, s)
b = b - m
d = d - m
s = s - m
if b > 0:
	b -= 1
	ans = c(ans, b, d, s)
	b += 1
if d > 0:
	d -= 1
	ans = c(ans, b, d, s)
	d += 1
if s > 0:
	s -= 1
	ans = c(ans, b, d, s)
	s += 1
if b * d > 0:
	b -= 1
	d -= 1
	ans = c(ans, b, d, s)
	b += 1
	d += 1
if b * s > 0:
	b -= 1
	s -= 1
	ans = c(ans, b, d, s)
	b += 1
	s += 1
if s * d > 0:
	s -= 1
	d -= 1
	ans = c(ans, b, d, s)
	s += 1
	d += 1
if b + d + s == 0:
	ans = 0
print(ans)


a = list(map(int, input().split()))
m = max(a)
ans = 0
for i in a:
	if i + 1 < m:
		ans += m - i - 1
print(ans)


a = [int(x) for x in input().split()]
m = max(a)
print(sum([m - x - 1 for x in a if x < m]))


import sys
(b, d, s) = map(int, sys.stdin.readline().split())
array = [b, d, s]
maxx = max(b, d, s)
result = 0
for x in array:
	result += max(0, maxx - 1 - x)
print(result)


(b, d, s) = list(map(int, input().split()))
har = [max(s - 1, d - 1, b), max(d, b - 1, s - 1), max(d - 1, s, b - 1)]
print(har[0] - b + har[1] - d + har[2] - s)


def f(l):
	mx = max(l)
	dl = [mx - i for i in l]
	dl.sort()
	if dl[1] > 0:
		return dl[1] + dl[2] - 2
	if dl[2] == 0:
		return 0
	return dl[2] - 1
l = list(map(int, input().split()))
print(f(l))


a = list(map(int, input().split(' ')))
a.sort(reverse=True)
res = 0
if a[2] + 1 < a[0]:
	res += a[0] - a[2] - 1
if a[1] + 1 < a[0]:
	res += a[0] - a[1] - 1
print(res)


__author__ = 'linh'

def main():
	str = input()
	meal_list = list(map(int, str.split()))
	s = 0
	m = max(meal_list)
	for i in meal_list:
		if i < m:
			s += m - i - 1
	print(s)
main()


def do():
	(b, d, s) = map(int, input().split())
	if b == d == s:
		return 0
	elif b == d and b > s:
		return b - s - 1
	elif b == d and b < s:
		return 2 * (s - b - 1)
	elif b == s and b > d:
		return b - d - 1
	elif b == s and b < d:
		return 2 * (d - b - 1)
	elif d == s and d > b:
		return d - b - 1
	elif d == s and d < b:
		return 2 * (b - d - 1)
	elif b > d and b > s:
		if d > s:
			return 2 * (b - 1 - d) + d - s
		else:
			return 2 * (b - 1 - s) + s - d
	elif d > b and d > s:
		if b > s:
			return 2 * (d - 1 - b) + b - s
		else:
			return 2 * (d - 1 - s) + s - b
	elif b > d:
		return 2 * (s - 1 - b) + b - d
	else:
		return 2 * (s - 1 - d) + d - b
rs = do()
print(rs)


L = list(map(int, input().split()))
maxv = max(L)
if L.count(maxv) == 1:
	ans = 0
	for l in L:
		if l == maxv:
			continue
		ans += maxv - l - 1
elif L.count(maxv) == 2:
	for l in L:
		if l != maxv:
			ans = maxv - l - 1
else:
	ans = 0
print(ans)


(b, d, s) = map(int, input().split())
if b == d == s:
	print(0)
	raise SystemExit
if b >= d and b >= s:
	if b != d and b != s:
		print(b - 1 - d + b - 1 - s)
	elif b == d:
		print(b - 1 - s)
	elif b == s:
		print(b - 1 - d)
elif d >= b and d >= s:
	if d != b and d != s:
		print(d - 2 - (b - 1) + d - 2 - (s - 1))
	elif d == s:
		print(d - 1 - b)
elif s >= d and s >= b:
	if s != d and s != b:
		print(s - 1 - d + s - 1 - b)


tpl = tuple(map(int, input().split()))
s = 0
for i in range(3):
	if tpl[i] < max(tpl) - 1:
		s += max(tpl) - tpl[i] - 1
print(s)


l = list(map(int, input().split()))
m = max(l)
a = 0
for e in l:
	if e < m - 1:
		a += m - 1 - e
print(a)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
a = sorted(int_array())
s = sum(a)
if a[0] == a[2]:
	ans = 0
elif a[0] != a[1] and a[1] == a[2]:
	ans = a[1] - a[0] - 1
else:
	ans = a[2] - a[0] - 1
	ans += a[2] - a[1] - 1
print(ans)


(b, l, d) = map(int, input().split())
if b == l and b == d:
	print('0')
else:
	k = max(b, max(l, d))
	mn = min(b, min(l, d))
	flag = 0
	if b == k:
		flag += 1
	if l == k:
		flag += 1
	if d == k:
		flag += 1
	if flag == 1:
		print(abs(3 * (k - 1) + 1 - l - d - b))
	elif flag == 2:
		print(abs(3 * (k - 1) + 2 - l - d - b))


PAD = 5
(a, b, c) = map(int, input().split())
ma = max(a, b, c)
ma = max(ma - PAD, 0)
ans = 0
d = [a, b, c]
for i in [0, 1, 2]:
	if d[i] < ma:
		ans += ma - d[i]
		d[i] = ma
	d[i] -= ma
best = PAD * 30
for first in (0, 1, 2):
	t = first - 1
	e = [0, 0, 0]
	while e[0] < d[0] or e[1] < d[1] or e[2] < d[2]:
		t += 1
		meal = t % 3
		e[meal] += 1
	mis = sum((x - y for (x, y) in zip(e, d)))
	best = min(best, mis)
print(best + ans)


(a, b, c) = map(int, input().split())
d = 0
m = max(a, b, c)
if m - a > 1:
	d = d + m - a - 1
if m - b > 1:
	d = d + m - b - 1
if m - c > 1:
	d = d + m - c - 1
print(d)


a = [int(x) for x in input().strip().split(' ')]
a.sort()
t = a[2] - a[1]
if t > 0:
	t -= 1
d = a[2] - a[0]
if d > 0:
	d -= 1
print(d + t)


a = list(map(int, input().split()))
t = min(a)
a[0] -= t
a[1] -= t
a[2] -= t
b1 = min(a)
s1 = max(a)
a.remove(min(a))
a.remove(max(a))
d1 = a[0]
sc = 0
if s1 > b1 + 1:
	sc += s1 - b1 - 1
	b1 = s1 - 1
if s1 > d1 + 1:
	sc += s1 - d1 - 1
	d1 = s1 - 1
print(sc)


(b, d, s) = map(int, input().split())

def mins(a, b, c):
	if min([a, b, c]) == a:
		return (a, min(b, c))
	if min([a, b, c]) == b:
		return (b, min(a, c))
	if min([a, b, c]) == c:
		return (c, min(a, b))
ma = max([b, d, s])
(mi1, mi2) = mins(b, d, s)
a1 = max(0, ma - 1 - mi1)
a2 = max(0, ma - 1 - mi2)
print(a1 + a2)


l = list(map(int, input().split()))
if len(set(l)) == 1:
	print(0)
if len(set(l)) == 2:
	l.sort()
	if l[0] == l[1]:
		print(2 * (l[2] - 1 - l[0]))
	else:
		print(max(l) - min(l) - 1)
if len(set(l)) == 3:
	l.sort()
	print(l[2] - l[1] + l[2] - l[0] - 2)


a = input()
a = a.split()
for i in range(0, 3):
	a[i] = int(a[i])
a.sort()
if a[0] == a[2]:
	print(0)
	exit()
print(a[2] - a[0] - 1 + max(0, a[2] - a[1] - 1))


a = list(map(int, input().split()))
mx = max(a)
print(max(0, mx - 1 - a[0]) + max(0, mx - 1 - a[2]) + max(0, mx - 1 - a[1]))


arr = [int(ch) for ch in input().split(' ')]
a = arr[0]
b = arr[1]
c = arr[2]
if a == b and a == c:
	print('0')
	exit()
maximum = max(a, b, c)
res = True
for i in arr:
	if i != maximum or i != maximum - 1:
		res = False
if res:
	print('0')
	exit()
adding = 0
for i in arr:
	if i == maximum:
		continue
	else:
		adding += maximum - i - 1
print(adding)


(b, d, s) = map(int, input().split())

def avg(x, y, z):
	A = [x, y, z]
	A.sort()
	return A[1]
print(max(max(b, d, s) - min(b, d, s) - 1, 0) + max(max(b, d, s) - avg(b, d, s) - 1, 0))


(a, b, c) = map(int, input().split())
d = max(a, b, c)
b1 = 0
c1 = 0
a1 = 0
if d - a - 1 > 0:
	a1 = d - a - 1
if d - b - 1 > 0:
	b1 = d - b - 1
if d - c - 1 > 0:
	c1 = d - c - 1
print(c1 + a1 + b1)


(b, d, s) = map(int, input().split())
x = max(b, d, s)
x = x - 1
a = 0
if b < x:
	a = a + x - b
if d < x:
	a = a + x - d
if s < x:
	a = a + x - s
print(a)


a = list(map(int, input().split()))
ans = 10 ** 22
for i in range(4):
	for j in range(4):
		b = a.copy()
		cnt = 0
		for k in range(i, 3):
			if b[k] > 0:
				b[k] -= 1
			else:
				cnt += 1
		for k in range(j):
			if b[k] > 0:
				b[k] -= 1
			else:
				cnt += 1
		ans = min(ans, max(b) * 3 - sum(b) + cnt)
if max(a) == 1:
	i = 0
	while a[i] == 0:
		i += 1
	j = 2
	while a[j] == 0:
		j -= 1
	ans = min(ans, j - i + 1 - sum(a))
print(ans)


from collections import defaultdict
import sys, os, math
(b, d, s) = map(int, input().split())
ans = 0
if b > d and b > s:
	ans = (b - 1) * 3 + 1 - d - b - s
elif d > b and d > s:
	ans = (d - 2) * 3 + 4 - d - b - s
elif s > d and s > b:
	ans = (s - 1) * 3 + 1 - d - b - s
elif s == d == b:
	ans = 0
elif d == b:
	ans = (b - 1) * 3 + 2 - d - b - s
elif b == s:
	ans = (b - 1) * 3 + 2 - d - b - s
else:
	ans = (d - 1) * 3 + 2 - d - b - s
print(ans)


from sys import stdin
(b, d, s) = map(int, stdin.readline().split())

def calculate(last_meal, b, d, s):
	if last_meal == 'b':
		if b > d and b > s:
			return b - d - 1 + (b - s - 1)
		else:
			new_b = max(d, s) + 1
			return new_b - d - 1 + (new_b - s - 1) + new_b - b
	elif last_meal == 'd':
		days = max(b, d, s + 1)
		return days - b + days - d + days - 1 - s
	else:
		days = max(b, d, s)
		return days - b + days - d + days - s
print(min((calculate(l, *days) for l in ('b', 'd', 's') for days in ((b, d, s), (d, s, b), (s, b, d)))))


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


t = input
p = print
r = range
a = list(map(int, t().split()))
ans = 0
if a[0] == a[1] == a[2] or max(a) - min(a) == 1:
	ans = 0
elif min(a) == 0:
	mid = sorted(a)[1]
	diff = 1 if max(a) == mid else 2
	ans = max(a) * 2 - mid - diff
else:
	a = list(map(lambda x: x - min(a), a))
	mid = sorted(a)[1]
	diff = 1 if max(a) == mid else 2
	ans = max(a) * 2 - mid - diff
p(ans)


(b, d, s) = map(int, input().split())
if b == d and d == s:
	print(0)
else:
	l = sorted([b, d, s])
	if l[-1] == l[-2]:
		print(l[-1] - l[0] - 1)
	elif l[0] == l[1]:
		print(2 * l[-1] - 2 * l[0] - 2)
	else:
		print(2 * l[-1] - l[0] - l[1] - 2)


(a, b, c) = map(int, input().split())
m = max(a, b, c)
if a == m:
	if a == b == c:
		print(0)
	elif a == c:
		print(a - b - 1)
	elif a == b:
		print(a - c - 1)
	else:
		print(a - b + a - c - 2)
elif b == m:
	if b == c:
		print(b - a - 1)
	else:
		print(b - a + b - c - 2)
elif c == m:
	print(c - b + c - a - 2)


ara = list(map(int, input().split()))
maxi = max(ara)
print(max(0, maxi - ara[0] - 1) + max(0, maxi - ara[1] - 1) + max(0, maxi - ara[2] - 1))


(a, b, c) = map(int, input().split())
ans = 0
(x, y, z) = (max(a, b, c), a + b + c - (max(a, b, c) + min(a, b, c)), min(a, b, c))
if x > y:
	ans += x - y - 1
if x > z:
	ans += x - z - 1
print(ans)


(b, d, s) = map(int, input().split())
if b == max(b, d, s):
	if b == d:
		if d == s:
			print(0)
		else:
			print(abs(d - 1 - s))
	elif b == s:
		print(abs(b - 1 - d))
	else:
		print(abs(b - 1 - s) + abs(b - 1 - d))
elif d == max(b, d, s):
	if d == s:
		print(d - 1 - b)
	else:
		print(abs(d - 1 - b) + abs(d - 1 - s))
elif s == d:
	if d == b:
		print(0)
	else:
		print(abs(d - 1 - b))
elif b == s:
	print(abs(s - 1 - d))
else:
	print(abs(s - 1 - b) + abs(s - 1 - d))


(b, d, s) = map(int, input().split())
mn = min(b, d, s)
mx = max(b, d, s)
if mx - mn <= 1:
	print(0)
else:
	ans = 0
	if mx - b >= 2:
		ans += mx - b - 1
	if mx - d >= 2:
		ans += mx - d - 1
	if mx - s >= 2:
		ans += mx - s - 1
	print(ans)


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


ms = list(map(int, input().split()))
mx = max(ms)
ans = 0
for m in ms:
	if m <= mx - 1:
		ans += mx - 1 - m
print(ans)


from sys import stdin, setrecursionlimit, stdout
setrecursionlimit(100)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

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 si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
test = test_case = 1
while test <= test_case:
	test += 1
	a = li()
	a.sort(reverse=True)
	ans = a[0] - 1
	s = 0
	for i in a:
		if i < ans:
			s += ans - i
	print(s)


list1 = list(map(int, input().split()))
b = list1[0]
d = list1[1]
s = list1[2]
if b == d and d == s:
	print(0)
elif b == d and b > s:
	print(d - 1 - s)
elif d == s and s > b:
	print(s - 1 - b)
else:
	temp = max(list1)
	if temp == b and temp == s:
		print(b - 1 - d)
	elif temp == b:
		print(b - 1 - s + (b - 1 - d))
	elif temp == d:
		print(d - 1 - s + (d - 1 - b))
	elif temp == s:
		print(s - 1 - b + (s - 1 - d))


a = list(map(int, input().split()))
mx = max(a) - 1
ans = 0
for i in range(3):
	if mx - a[i] > 0:
		ans += mx - a[i]
print(ans)


mas = [int(x) for x in input().split()]
mas.sort()
p = 0
k = mas[2] - 1
if mas[1] < k:
	p += k - mas[1]
if mas[0] < k:
	p += k - mas[0]
print(p)


cnt = list(map(int, input().split()))
if cnt.count(max(cnt)) == 3:
	print(0)
elif cnt.count(max(cnt)) == 2:
	if cnt[1] != max(cnt):
		print(max(cnt) - 1 - cnt[1])
	elif cnt[0] != max(cnt):
		print(max(cnt) - 1 - cnt[0])
	else:
		print(max(cnt) - 1 - cnt[2])
elif cnt[0] == max(cnt):
	print(2 * (max(cnt) - 1) - cnt[1] - cnt[2])
elif cnt[1] == max(cnt):
	print(max(cnt) - 1 - cnt[0] + max(cnt) - 1 - cnt[2])
else:
	print(max(cnt) - 1 - cnt[0] + max(cnt) - 1 - cnt[1])


a = list(map(int, input().split()))
a.sort()
print(max(0, a[2] - 1 - a[1]) + max(0, a[2] - 1 - a[0]))


import copy

def rotate(l, n):
	return l[-n:] + l[:-n]
base_meals = list(map(int, input().split()))
max_meal = max(base_meals)
N = len(base_meals)
ans = 1 << 114
for _ in range(3):
	meals = rotate(base_meals, _)
	tmp_meals = copy.deepcopy(meals)
	tmp_meals[0] -= max_meal
	tmp_meals[1] -= max_meal - 1
	tmp_meals[2] -= max_meal - 1
	if tmp_meals[1] <= 0 and tmp_meals[2] <= 0:
		res = sum(tmp_meals)
		ans = min(ans, abs(res))
	elif tmp_meals[2] > 0:
		tmp_meals[1] -= 1
		tmp_meals[2] -= 1
	elif tmp_meals[1] > 0:
		tmp_meals[1] -= 1
	res = sum(tmp_meals)
	ans = min(ans, abs(res))
print(ans)


a = [*map(int, input().split())]
print(sum([max(0, max(a) - i - 1) for i in a]))


A = [int(x) for x in input().split()]
A.sort()
X = A[2] - A[1] - 1
Y = A[2] - A[0] - 1
if X < 0:
	X = 0
if Y < 0:
	Y = 0
print(X + Y)


from collections import deque as de
import math
from collections import Counter as cnt

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic
(b, d, s) = map(int, input().split())
if b <= 1 and d <= 1 and (s <= 1):
	print(0)
else:
	ans = 0
	if b == d == s:
		print(0)
	elif b != d and d != s and (b != s):
		if b == max(b, d, s):
			b -= 1
			ans += b - d
			ans += b - s
		elif s == max(b, d, s):
			s -= 1
			ans += s - d
			ans += s - b
		elif b > s:
			s += 1
			ans += d - s
			ans += d - b
			ans -= 1
		else:
			b += 1
			ans += d - s
			ans += d - b
			ans -= 1
		print(ans)
	else:
		if b == d:
			if b > s:
				ans = b - s - 1
			else:
				s -= 1
				ans = 2 * (s - b)
		elif d == s:
			if d > b:
				ans = d - b - 1
			else:
				b -= 1
				ans = 2 * (b - d)
		elif d < s:
			s -= 1
			ans = s - d
		else:
			ans = (d - s - 1) * 2
		print(ans)


(b, d, s) = [int(n) for n in input().split()]
n = max(b, d, s) - 1
ans = max(n - b, 0) + max(n - d, 0) + max(n - s, 0)
print(ans)


a = list(map(int, input().split(' ')))
a = sorted(a)
sum = 0
if a[0] != a[2]:
	sum = sum + (a[2] - a[0] - 1)
if a[1] != a[2]:
	sum = sum + (a[2] - a[1] - 1)
print(sum)


l = [*map(int, input().split())]
res = float('inf')
for i in range(0, 3):
	for j in range(0, 3):
		x = l[:]
		for k in range(i):
			x[k] += 1
		for k in range(j):
			x[2 - k] += 1
		m = max(x)
		res = min(res, sum((m - e for e in x)))
print(res)


l = list(map(int, input().split()))
max = max(l)
min = min(l)
for i in range(3):
	if max == l[i]:
		l[i] -= 1
sum = 0
max = max - 1
for i in l:
	sum += max - i
print(sum)


(a, b, c) = [int(x) for x in input().split()]
a -= 2
b -= 2
c -= 2
_sum = a + b + c
_max = max([a, b, c])
r = 0
for x in [a, b, c]:
	if x == _max:
		continue
	if _max - 1 - x > 0:
		r += _max - 1 - x
print(r)


a = list(map(int, input().split()))
a = sorted(a, reverse=True)
r = 0
for i in range(0, len(a)):
	for j in range(i + 1, len(a)):
		if abs(a[i] - a[j]) > 1:
			r += abs(a[i] - a[j]) - 1
			a[j] = a[j] + abs(a[i] - a[j]) - 1
print(r)


(a, b, c) = [int(i) for i in input().split()]
if max(a, b, c) <= min(a, b, c) + 1:
	print(0)
else:
	arr = [a, b, c]
	arr.sort()
	(a, b, c) = arr
	res = c - a - 1
	if b + 1 < c:
		res += c - b - 1
	print(res)


def main():
	(a, b, c) = [int(s) for s in input().split()]
	m = max(a, b, c)
	maxes = [max(m - i - 1, 0) for i in [a, b, c]]
	print(sum(maxes))
main()


(b, d, s) = map(int, input().split())
start = s
startpos = 2
endpos = 0
if d >= start:
	start = d
	startpos = 1
	if b >= start:
		start = b
		startpos = 0
if b > start:
	start = b
	startpos = 0
end = b
if d >= end:
	end = d
	endpos = 1
	if s >= end:
		end = s
		endpos = 2
if s > end:
	end = s
	endpos = 2
l = [b, d, s]
i = startpos
while True:
	l[i] -= 1
	if i == endpos:
		break
	i = (i + 1) % 3
m = max(l)
ans = 0
for i in l:
	ans += m - i
print(ans)


(a, b, c) = [int(x) for x in input().split()]
t = max(a, b, c)
a1 = t - a
b1 = t - b
c1 = t - c
d = [a1, b1, c1]
d.sort()
cnt = 0
for i in range(len(d)):
	if d[i] > 0:
		cnt += 1
if cnt == 2:
	print(abs(a1 + b1 + c1) - 2)
elif cnt == 1:
	print(abs(a1 + b1 + c1) - 1)
else:
	print(abs(a1 + b1 + c1))


(a, b, c) = map(int, input().split())
p = min(a, b, c)
a -= p
b -= p
c -= p
q = max(a, b, c)
if q == 0:
	print(0)
	exit(0)
s = sorted([a, b, c])
s.reverse()
s[0] -= 1
res = max(0, s[0] - s[1]) + max(0, s[0] - s[2])
print(res)


(b, d, s) = input().split()
(b, d, s) = (int(b), int(d), int(s))
sm = sum([b, d, s])
if b > d and b > s:
	sm += 2
elif b < d > s:
	sm += 2
elif s > b and s > d:
	sm += 2
elif b == d == s:
	sm += 0
else:
	sm += 1
print(3 * max([b, d, s]) - sm)


def solve(a):
	if len(set(a)) == 1:
		return 0
	elif a[1] == a[2]:
		return a[1] - a[0] - 1
	else:
		return a[2] - 1 - a[1] + a[2] - 1 - a[0]
print(solve(sorted(list(map(int, input().split())))))


a = [int(i) for i in input().split()]
a.sort()
a[2] -= a[0]
a[1] -= a[0]
count = 0
if a[2] == a[1]:
	print(max(a[2] - 1, 0))
elif a[2] > a[1]:
	count += a[1]
	a[2] -= a[1]
	print(max((a[2] - 1) * 2 + count, 0))


d = list(map(int, input().split()))
ans = 3 * max(d) - sum(d) if max(d) > 1 else 0
for i in range(4):
	for j in range(4):
		dd = [0, 0, 0]
		for k in range(i, 3):
			if d[k]:
				dd[k] += 1
		for k in range(j):
			if d[k] - dd[k]:
				dd[k] += 1
		m = max([d[k] - dd[k] for k in range(3)])
		ans = min(ans, sum([(i <= k) + (j > k) + m - d[k] for k in range(3)]))
print(ans)


from sys import stdin, stdout

def main():
	A = list(map(int, stdin.readline().strip().split()))
	A[:] = sorted(A, reverse=True)
	m = max(A) - 1
	c = 0
	for i in A[1:]:
		c += max(0, m - i)
	stdout.write(f'{c}')
main()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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 tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(b, d, s) = sorted(value())
ans = max(0, s - 1 - d)
d = max(d, s - 1)
ans += max(0, d - 1 - b)
b = max(b, d - 1)
if b == d or d == s:
	print(ans)
else:
	print(ans + 1)


a = list(map(int, input().split()))
m = max(a) - 1
print(sum((m - i for i in a if i < m)))


(a, b, c) = map(int, input().split())
f = max(a, b, c) - 1
print(max(f - a, 0) + max(f - b, 0) + max(f - c, 0))


I = lambda : list(map(int, input().split()))
c = sorted(I())
print(max(c[2] - c[0] - 1, 0) + max(c[2] - c[1] - 1, 0))


(b, d, s) = list(map(int, input().split()))
t = max(b, d, s)
a1 = b - t
a2 = d - t
a3 = s - t
if a1 < 0:
	a1 = -(a1 + 1)
if a2 < 0:
	a2 = -(a2 + 1)
if a3 < 0:
	a3 = -(a3 + 1)
print(a1 + a2 + a3)


(b, l, d) = map(int, input().split())
m = max(b, l, d)
x = m - 1
missing = 0
if x - b > 0:
	missing += x - b
if x - l > 0:
	missing += x - l
if x - d > 0:
	missing += x - d
print(missing)


(x, y, z) = input().split(' ')
x = int(x)
y = int(y)
z = int(z)
m = max(x, y, z) - 1
resp = 0
if x < m:
	resp = resp + m - x
if y < m:
	resp = resp + m - y
if z < m:
	resp = resp + m - z
print(resp)


def min_1(b, d, s):
	a = sorted([b, d, s])
	res = a[2] - a[1] + (a[2] - a[0])
	return res
(b, d, s) = map(int, input().split())
a = []
a.append(min_1(b, d, s))
a.append(min_1(b, d, s - 1))
a.append(min_1(b, d - 1, s - 1))
a.append(min_1(b - 1, d, s))
a.append(min_1(b - 1, d, s - 1))
a.append(min_1(b - 1, d - 1, s - 1))
a.append(min_1(b - 1, d - 1, s))
a.append(min_1(b - 1, d - 1, s - 1))
a.append(min_1(b - 1, d - 2, s - 1))
a.sort()
print(a[0])


def inp():
	return map(int, input().split())
(b, d, s) = inp()
if b == d == s:
	print(0)
else:
	(lis, ans) = (sorted([b, d, s], reverse=True), 0)
	if lis[0] != lis[1]:
		ans += lis[0] - (lis[1] + 1)
	ans += lis[0] - (lis[2] + 1)
	print(ans)


import math
str1 = [int(a) for a in input().split()]
z = 0
k = max(str1)
for a in str1:
	if a < k - 1:
		z += k - 1 - a
print(z)


(a, b, c) = map(int, input().split())
mn = max(a, b, c)
a = mn - a
b = mn - b
c = mn - c
if a > 0 and b > 0 or (a > 0 and c > 0) or (b > 0 and c > 0):
	print(a + b + c - 2)
elif sum([a, b, c]) > 0:
	print(a + b + c - 1)
else:
	print(0)


(a, b, c) = [int(i) for i in input().split()]
z = max(a, b, c)
ans = 0
if z > a:
	ans += z - a - 1
if z > b:
	ans += z - b - 1
if z > c:
	ans += z - c - 1
print(ans)


from sys import stdin, stdout

def ri():
	return map(int, stdin.readline().split())
option1 = [[1, 1, 1], [0, 1, 1], [0, 0, 1]]
option2 = [[1, 1, 1], [1, 1, 0], [1, 0, 0]]

def findoption(m1, m2, m3):
	ans = 10 ** 100
	for o1 in option1:
		for o2 in option2:
			fl1 = o1[0] + o2[0]
			fl2 = o1[1] + o2[1]
			fl3 = o1[2] + o2[2]
			nonflday = max(m1 - fl1, m2 - fl2, m3 - fl3)
			summeal = fl1 + fl2 + fl3 + nonflday * 3
			skipmeal = summeal - (m1 + m2 + m3)
			ans = min(ans, skipmeal)
	return ans
(m1, m2, m3) = ri()
if m1 == 0 and m2 == 1 and (m3 == 0):
	print(0)
else:
	print(findoption(m1, m2, m3))


(a, b, c) = map(int, input().split())
d = max(a, b, c)
e = 0
for x in (a, b, c):
	if x + 1 < d:
		e += d - x - 1
print(e)


(b, l, d) = map(int, input().split())
ans = 0
m = max([b, l, d])
if b < m:
	ans += m - b - 1
if l < m:
	ans += m - l - 1
if d < m:
	ans += m - d - 1
print(ans)


(br, din, sup) = map(int, input().split())
d = max(br, din, sup)
ans = 0
ans += max(0, d - din - 1)
ans += max(0, 0, d - sup - 1)
ans += max(0, d - br - 1)
print(ans)


D = input().split()
D = [int(x) for x in D]
b = D[0]
d = D[1]
s = D[2]
q = 0
if b == s and s == d:
	q = 0
elif b == max(b, d, s):
	if max(d, s) < b:
		q += b - 1 - d + (b - 1 - s)
	elif d == b:
		q += b - 1 - s
	elif s == b:
		q += b - 1 - d
elif d == max(b, d, s):
	if max(b, s) < d:
		q += d - b - 1 + (d - 1 - s)
	elif d == s:
		q += d - 1 - b
elif s == max(b, d, s):
	if max(b, d) < s:
		q += s - b - 1 + (s - 1 - d)
print(q)


(b, d, s) = map(int, input().split())
max1 = max(b, d, s)
max_count = 0
if max1 == b:
	max_count += 1
if max1 == d:
	max_count += 1
if max1 == s:
	max_count += 1
if max_count == 3:
	ans = 0
elif max_count == 2:
	ans = max1 - min(b, d, s) - 1
else:
	ans = max1 - min(b, d, s) - 1 + (max1 - 1 - (b + d + s - max1 - min(b, d, s)))
print(ans)


l = list(map(int, input().split()))
l = sorted(l, reverse=True)
min_result = 10000000000000000000000000000
delts = [(1, 0, 0), (1, 1, 0), (0, 0, 1), (0, 1, 1), (0, 0, 0)]
for delt in delts:
	a = []
	for i in range(3):
		a.append(l[i] + delt[i])
	a = sorted(a, reverse=True)
	min_result = min(min_result, a[0] - a[1] + a[0] - a[2])
print(min_result)


(b, d, s) = map(int, input().split())
m = max(b, d, s)
mi = min(b, d, s)
mid = sorted([b, d, s])[1]
print(max(m - mi - 1, 0) + max(m - mid - 1, 0))


(b, d, s) = map(int, input().split())

def calc(b, d, s):
	return max(b, d, s) * 3 - sum((b, d, s))
res = []
for i in range(3):
	for j in range(3):
		res.append(calc(b - (j > 0), d - (j > 1) - (i > 1), s - (i > 0)))
print(min(res))


(b, d, s) = map(lambda x: int(x), input().split(' '))
ans = 10 ** 20 + 1
if b >= max(d, s):
	ans = min(ans, max(b - 1 - d, 0) + max(b - 1 - s, 0))
if d >= max(b, s):
	ans = min(ans, max(d - 1 - b, 0) + max(d - 1 - s, 0))
if s >= max(b, d):
	ans = min(ans, max(s - 1 - b, 0) + max(s - 1 - d, 0))
print(ans)


l = list(map(int, input().split()))
n = 0
b = l[0]
d = l[1]
s = l[2]
l.sort(reverse=True)
b -= l[0]
d -= l[0]
s -= l[0]
k1 = l[0]
k2 = l[1]
k3 = l[2]
if k1 > k2 + 1:
	n = n + (k1 - (k2 + 1))
if k1 > k3 + 1:
	n = n + (k1 - (k3 + 1))
print(n)


a = list(map(int, input().split()))
a.sort()
a[2] -= 1
ans = (a[2] - a[1] > 0) * (a[2] - a[1]) + (a[2] - a[0] > 0) * (a[2] - a[0])
print(ans)


a = list(map(int, input().split()))
(q, s) = (max(a), 0)
for i in a:
	if i < q:
		s += q - i - 1
print(s)


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from fractions import *
from math import sqrt, ceil, log2, gcd, cos, pi
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	while n % 2 == 0:
		n = n // 2
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		cc = 0
		while n % ps == 0:
			n = n // ps
			lk += 1
	if n != 1:
		lk += 1
		return False
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return qlr

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	su = 0
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
				su += i
			else:
				list.append(n // i)
				list.append(i)
				su += i
				su += n // i
	return su

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

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

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

def inp():
	return input().strip()

def google(test, ans):
	return 'Case #' + str(test) + ': ' + str(ans)

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2

def dist(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
t = 1
for p in range(t):
	arr = ilist()
	m = max(arr)
	ans = 0
	for i in range(3):
		ans += max(0, m - arr[i] - 1)
	print(ans)


a = input().strip().split()
for (index, item) in enumerate(a):
	a[index] = int(item)
a.sort(reverse=True)
if a[0] > a[1]:
	ans = a[0] - a[1] + a[0] - a[2] - 2
elif a[0] == a[1] and a[1] > a[2]:
	ans = a[0] - a[2] - 1
else:
	ans = 0
print(ans)


s = input()
s = s.split()
ans = 0
Max = 0
for i in range(3):
	s[i] = int(s[i])
	if s[i] > Max:
		Max = s[i]
for i in s:
	if Max - 1 > i:
		ans += Max - 1 - i
print(ans)


def add_list(s1, s2):
	res = list(s1)
	for x in range(len(s1)):
		res[x] -= s2[x]
	return res

def find_min(seq, max_list):
	sum = 0
	for x in seq:
		if x > max_list:
			x = max_list
		sum += max_list - x
	return sum
data = [int(x) for x in input().split()]
pre_max = max(data)
for x in range(len(data)):
	data[x] - pre_max
max_val = max(data)
all_cases = []
template_cases1 = [(0, 0, 0), (0, 1, 1), (0, 0, 1), (1, 1, 1)]
template_cases2 = [(1, 1, 1), (0, 1, 1), (0, 0, 1), (0, 0, 0)]
for case1 in template_cases1:
	for case2 in template_cases2:
		sun = add_list(case1, case2)
		all_cases.append(sun)
result = []
for x in all_cases:
	result.append(find_min(add_list(data, x), max_val))
print(int(min(result)))


def solve(a):
	ans = 1 << 100
	b = [0] * 3
	for i in range(2, -1, -1):
		b[i] += 1
		c = b[:]
		for j in range(3):
			c[j] += 1
			x = max((a[k] - c[k] for k in range(3)))
			ans = min(ans, x * 3 + sum(c))
	return ans - sum(a)
print(solve(list(map(int, input().split()))))


import sys
(breakfast, lunch, dinner) = map(int, input().strip().split())
minval = min(breakfast, lunch, dinner)
breakfast -= minval
lunch -= minval
dinner -= minval
if lunch == 0 and breakfast == 0 and (dinner == 0):
	print('0')
elif breakfast == 0 and dinner == 0:
	print((lunch - 1) * 2)
elif breakfast == 0 and lunch == 0:
	print((dinner - 1) * 2)
elif lunch == 0 and dinner == 0:
	print((breakfast - 1) * 2)
else:
	min_val = max(breakfast, lunch, dinner) * 3 - (breakfast + lunch + dinner)
	if lunch == 0 and breakfast == dinner or (breakfast == 0 and lunch == dinner) or (dinner == 0 and breakfast == lunch):
		min_val -= 1
	elif lunch == 0 or (breakfast == 0 and dinner != lunch) or (dinner == 0 and breakfast != lunch):
		min_val -= 2
	print(min_val)


(b, d, s) = [int(x) for x in input().split()]
a = []
a.append(max(b, d, s) * 3)
if b > s and b > d:
	a.append((b - 1) * 3 + 1)
else:
	a.append(max(s, d) * 3 + 1)
if max(b, d) > s:
	a.append((max(b, d) - 1) * 3 + 2)
else:
	a.append(s * 3 + 2)
if b < max(s, d):
	a.append((max(s, d) - 1) * 3 + 2)
else:
	a.append(b * 3 + 2)
if d > max(b, s):
	a.append((d - 1) * 3 + 1)
else:
	a.append(max(b, s) * 3 + 1)
if s > max(b, d):
	a.append((s - 1) * 3 + 1)
else:
	a.append(max(b, d) * 3 + 1)
if d < max(b, s):
	a.append((max(b, s) - 1) * 3 + 2)
else:
	a.append(d * 3 + 2)
print(max(0, min(a) - b - s - d))


def f(x, y, z):
	return 3 * max(x, y, z) - x - y - z
v = 3 * 10 ** 18
(b, d, s) = map(int, input().split())
for (x, y, z) in ((b, d, s), (b + 1, d, s), (b + 1, d + 1, s)):
	v = min(v, f(x, y, z), f(x, y + 1, z + 1), f(x, y, z + 1))
print(v)


def f(a, b, c):
	m = min(a, b, c)
	(a, b, c) = (a - m, b - m, c - m)
	if a == b and a == c:
		return 0
	if a == b:
		if abs(a - c) == 1:
			return 0
		elif c > a:
			return (c - a - 1) * 2
		else:
			return a - c - 1
	if a == c:
		if abs(a - b) == 1:
			return 0
		elif b > a:
			return (b - a - 1) * 2
		else:
			return a - b - 1
	if b == c:
		if abs(a - b) == 1:
			return 0
		elif a > b:
			return (a - b - 1) * 2
		else:
			return b - a - 1
	m = min(a, b, c)
	n = min(max(a, b), max(b, c), max(a, c))
	if a == m:
		a = n
	elif b == m:
		b = n
	else:
		c = n
	return n + f(a, b, c)
print(f(*[int(i) for i in input().split()]))


(b, d, s) = map(int, input().split())
days = max(b, d, s)
print(max(0, max(days - b - 1, 0) + max(days - d - 1, 0) + max(days - s - 1, 0)))


import itertools

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

def output_list(v):
	print(' '.join((str(x) for x in v)))

def main():
	(a, b, c) = input_ints()
	ans = 10 ** 20
	for (i, j, k) in itertools.product(range(2), range(2), range(2)):
		x = [a - i, b - j, c - k]
		if min(x) < 0:
			continue
		ma = max(x)
		ans = min(ans, 3 * ma - sum(x))
	print(ans)
main()


a = sorted(list(map(int, input().split())))
if a.count(0) == 2 and a[-1] == 1:
	print(0)
	exit()
elif a.count(0) == 2 and a[-1] != 1:
	print(a[-1] * 2 - 2)
	exit()
if a[2] - a[1] == 1:
	print(a[2] - a[0] - 1)
	exit()
elif a[2] == a[1]:
	if a[1] - a[0] > 1:
		print(a[2] - a[0] - 1)
	else:
		print(0)
	exit()
elif a[0] == a[1] == a[2]:
	print(0)
	exit()
else:
	print(a[2] * 2 - 2 - a[0] - a[1])
	exit()


a = input()
(s1, s2, s3) = a.split()
maxi = 0
s1 = eval(s1)
s2 = eval(s2)
s3 = eval(s3)
if s1 > maxi:
	maxi = s1
if s2 > maxi:
	maxi = s2
if s3 > maxi:
	maxi = s3
sumi = 0
if not s1 == maxi:
	sumi += maxi - s1 - 1
if not s2 == maxi:
	sumi += maxi - s2 - 1
if not s3 == maxi:
	sumi += maxi - s3 - 1
print(sumi)


L = list(map(int, input().split()))
high = max(L)
ans = 0
for x in L:
	x = high - x
	if x > 0:
		x -= 1
	ans += x
print(ans)


numbers = list(map(int, input().split()))
if len(numbers) == 3:
	b = numbers[0]
	d = numbers[1]
	s = numbers[2]
	maxi = max(numbers)
	numbers.remove(maxi)
	maxi1 = max(numbers)
	if maxi > maxi1:
		print(max(0, 3 * maxi - s - b - d - 2))
	else:
		print(max(0, 3 * maxi - s - b - d - 1))
else:
	print(-1)


our = list(map(int, input().split()))
m = max(our)
if our[0] == m:
	if our[2] == m:
		res = m - our[1] - 1
	elif our[1] == m:
		res = m - our[2] - 1
	else:
		res = m * 3 - sum(our) - 2
elif our[1] == m:
	if our[0] == m:
		res = max(0, m - our[2] - 1)
	else:
		res = max(0, m - our[0] - 1)
		res += max(0, m - our[2] - 1)
elif our[0] == m:
	res = m - our[1]
else:
	res = m * 3 - sum(our) - 2
print(max(res, 0))


arr = list(map(int, input().split()))
arr.sort()
ans = 0
arr[-1] -= 1
if arr[-1] - arr[0] > 0:
	ans += arr[-1] - arr[0]
if arr[-1] - arr[1] > 0:
	ans += arr[-1] - arr[1]
print(ans)