AtCoder Beginner Contest 056 - NarrowRectanglesEasy

AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.
Find the minimum distance it needs to be moved.

-----Constraints-----
 - All input values are integers.
 - 1≤W≤10^5
 - 1≤a,b≤10^5

-----Input-----
The input is given from Standard Input in the following format:
W a b

-----Output-----
Print the minimum distance the second rectangle needs to be moved.

-----Sample Input-----
3 2 6

-----Sample Output-----
1

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.

Difficulty: EASY

Starter code:

Solutions:
(w, a, b) = map(int, input().split())
d = abs(a - b)
if d > w:
	print(d - w)
else:
	print(0)


(a, b, c) = map(int, input().split())
print(max(0, c - b - a) if c > b else max(0, b - c - a))


(w, a, b) = map(int, input().split())
li = [0, b - (a + w), a - (b + w)]
print(max(li))


(w, a, b) = map(int, input().split())
c = min(a, b)
d = max(a, b)
print(max(d - (c + w), 0))


(W, a, b) = list(map(int, input().split()))
z = sorted([a, b])
print(max(z[1] - z[0] - W, 0))


(W, a, b) = map(int, input().split())
if a > b:
	(a, b) = (b, a)
print(max(b - a - W, 0))


(w, a, b) = map(int, input().split())
if b >= a:
	print(max(0, b - (a + w)))
else:
	print(max(0, a - (b + w)))


(W, a, b) = map(int, input().split())
if abs(a - b) <= W:
	print(0)
else:
	print(abs(a - b) - W)


(W, a, b) = map(int, input().split())
c = abs(b - a) - W
if c < 0:
	c = 0
print(c)


(W, *N) = [int(n) for n in input().split()]
N.sort()
print(max(0, N[1] - W - N[0]))


(W, a, b) = map(int, input().split())
print(max(abs(a - b) - W, 0))


(w, a, b) = map(int, input().split())
(a, b) = (min(a, b), max(a, b))
print(max(b - a - w, 0))


(w, a, b) = map(int, input().split())
if a <= b <= a + w or a <= b + w <= a + w:
	print(0)
elif a + w < b:
	print(b - (w + a))
elif b + w < a:
	print(a - (w + b))


(w, a, b) = map(int, input().split())
print(max(0, abs(a - b) - w))


(W, a, b) = [int(x) for x in input().split()]
print(max(b - (a + W), a - (b + W), 0))


(w, a, b) = map(int, input().split())
if b > a + w:
	print(b - a - w)
elif b + w < a:
	print(a - b - w)
else:
	print(0)


(W, a, b) = map(int, input().split(' '))
(a, b) = sorted([a, b])
print(max(0, b - a - W))


(W, a, b) = map(int, input().split())
d = abs(b - a)
answer = max(0, d - W)
print(answer)


import sys

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

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

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

def main():
	(w, a, b) = MI()
	if b < a:
		temp = a
		a = b
		b = temp
	ans = max(0, b - a - w)
	print(ans)

def __starting_point():
	main()
__starting_point()


(W, a, b) = map(int, input().split())
ans = max(a, b) - (min(a, b) + W)
print(max(ans, 0))


(W, A, B) = map(int, input().split())
print(max(0, abs(A - B) - W))


(w, a, b) = map(int, input().split())
if b <= a + w <= b + w or b <= a <= b + w:
	print(0)
else:
	print(min(abs(a + w - b), abs(b + w - a)))


(w, a, b) = map(int, input().split())
arr = sorted([a, b])
print(max(0, arr[1] - w - arr[0]))


(w, a, b) = map(int, input().split())
if len(sorted(set(range(a, a + w + 1)) & set(range(b, b + w + 1)))) != 0:
	print('0')
elif b >= a + w:
	print(b - a - w)
elif a >= b + w:
	print(a - b - w)


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


(W, a, b) = [int(i) for i in input().split()]
print(max(max(a, b) - min(a, b) - W, 0))


(W, a, b) = list(map(int, input().split()))
if b + W < a:
	print(a - (b + W))
elif a + W < b:
	print(b - (a + W))
else:
	print(0)


(x, a, b) = map(int, input().split())
print(a - (b + x) if a > b else max(0, b - (a + x)))


(W, a, b) = [int(item) for item in input().split()]
print(max(0, abs(b - a) - W))


(a, b, c) = map(int, input().split())
if abs(b - c) - a < 0:
	print(0)
else:
	print(abs(b - c) - a)


(w, a, b) = map(int, input().split())
aw = a + w
bw = b + w
print(max(0, a - bw, b - aw))


(w, a, b) = map(int, input().split())
min_side = min(a, b)
max_side = max(a, b)
t = max_side - (min_side + w)
t = max(t, 0)
print(t)


(W, a, b) = map(int, input().split())
if a < b:
	(A, B) = (W + a, b)
	if A >= B:
		print(0)
	else:
		print(B - A)
else:
	(A, B) = (a, W + b)
	if B >= A:
		print(0)
	else:
		print(A - B)


def main():
	(W, a, b) = map(int, input().split())
	if a > b:
		print(max(0, a - b - W))
	else:
		print(max(0, b - a - W))

def __starting_point():
	main()
__starting_point()


(W, a, b) = list(map(lambda x: int(x), input().split(' ')))
m = min([a, b])
M = max([a, b])
if M - m > W:
	print(M - m - W)
else:
	print(0)


(w, a, b) = map(int, input().split())
A = [i for i in range(a, a + w + 1)]
B = [i for i in range(b, b + w + 1)]
if a in B or b in A:
	print(0)
else:
	print(min(abs(a + w - b), abs(b + w - a)))


(w, a, b) = map(int, input().split())
res = abs(a - b) - w
if res < 0:
	res = 0
print(res)


(w, a, b) = map(int, input().split())
aw = a + w
bw = b + w
if a == bw or b == aw or a == b:
	print(0)
elif a < b < aw or b < a < bw:
	print(0)
else:
	if aw < b:
		print(b - aw)
	if bw < a:
		print(a - bw)


(W, a, b) = list(map(int, input().split()))
if a <= b <= a + W or a <= b + W <= a + W:
	print(0)
else:
	print(min(abs(a + W - b), abs(b + W - a)))


import sys

def solve(W: int, a: int, b: int):
	if abs(a - b) <= W:
		return 0
	return abs(a - b) - W

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	W = int(next(tokens))
	a = int(next(tokens))
	b = int(next(tokens))
	print(solve(W, a, b))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


(x, a, b) = map(int, input().split())
print(max(max(a, b) - min(a, b) - x, 0))


lst = input().split()
W = int(lst[0])
a = int(lst[1])
b = int(lst[2])
if b - W <= a <= b + W:
	print(0)
else:
	print(max([b - (a + W), a - (b + W)]))


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


(w, a, b) = map(int, input().split())
print(0) if a + w >= b and b + w >= a else print(b - a - w) if a + w < b else print(a - b - w)


(W, A, B) = map(int, input().split())
print(max(0, max(A, B) - min(A, B) - W))


(w, a, b) = list(map(int, input().split()))
if b + w < a:
	res = a - (b + w)
elif a <= b + w <= a + 2 * w:
	res = 0
else:
	res = b - (a + w)
print(res)


(W, a, b) = map(int, input().split())
L = [b - (a + W), a - (b + W), 0]
print(max(L))


f = lambda x: max(abs(x[2] - x[1]) - x[0], 0)
print(f(list(map(int, input().split()))))


(W, A, B) = [int(_) for _ in input().split()]
print(max(abs(A - B) - W, 0))


(W, a, b) = map(int, input().split())
M = max(a, b) - min(a, b) - W
print([0, M][M > 0])


(w, a, b) = map(int, input().split())
ma = max(a, b)
mi = min(a, b)
print(max(ma - (mi + w), 0))


(w, a, b) = [int(v) for v in input().split()]
print(max(abs(a - b) - w, 0))


(w, a, b) = list(map(int, input().split()))
res = max(0, abs(a - b) - w)
print(res)


(W, A, B) = [int(i) for i in input().split()]
if B <= A <= B + W or B <= A + W <= B + W or A <= B <= A + W or (A <= B + W <= A + W):
	print(0)
elif W + A <= B:
	print(B - (W + A))
else:
	print(A - (B + W))


(w, a, b) = list(map(int, input().split()))
if a <= b <= a + w or b <= a <= b + w:
	ans = 0
elif a < b:
	ans = b - a - w
else:
	ans = a - b - w
print(ans)


import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda : sys.stdin.readline().rstrip()
rs = lambda : sys.stdin.readline().split()
ri = lambda : int(sys.stdin.readline())
rm = lambda : list(map(int, sys.stdin.readline().split()))
rl = lambda : list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10 ** 9 + 7
(w, a, b) = rm()
if a < b:
	print(max(b - (a + w), 0))
else:
	print(max(a - (b + w), 0))


(W, a, b) = [int(n) for n in input().split()]
res = max(b - (a + W), a - (b + W), 0)
print(res)


(w, a, b) = list(map(int, input().split()))
ans = abs(a - b) - w
print(ans) if ans > 0 else print(0)


(w, a, b) = map(int, input().split())
A = min(a, b)
B = max(a, b)
print(max(0, B - A - w))


(W, a, b) = map(int, input().split())
if b > a:
	if b - (a + W) <= 0:
		print(0)
		return
	print(b - (a + W))
else:
	if a - (b + W) <= 0:
		print(0)
		return
	print(a - (b + W))


(W, a, b) = map(int, input().split())
f = lambda x: x if x > 0 else 0
print(f(abs(a - b) - W))


(w, a, b) = map(int, input().split())
print((a + w < b) * (b - a - w) or (b + w < a) * (a - b - w) or 0)


(W, A, B) = map(int, input().split())
if B >= A:
	(A, B) = (B, A)
print(max(0, A - (W + B)))


(w, a, b) = map(int, input().split())
s = abs(a - b)
print([0, s - w][s > w])


def answer(w: int, a: int, b: int) -> int:
	b_a = abs(b - a)
	if b_a <= w:
		return 0
	return b_a - w

def main():
	(w, a, b) = map(int, input().split())
	print(answer(w, a, b))

def __starting_point():
	main()
__starting_point()


a = list(map(int, input().split()))
x = max(a)
a.remove(x)
print(x - sum(a) if x - sum(a) > 0 else 0)


(a, b, c) = map(int, input().split())
print(max(max([b, c]) - min([b, c]) - a, 0))


(x, y, z) = map(int, input().split())
ans = abs(y - z) - x
print(ans) if ans > 0 else print(0)


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


(w, a, b) = map(int, input().split())
x = min(a, b)
y = max(a, b)
print(y - x - w if y - x > w else 0)


(n, m, k) = map(int, input().split())
if m > k:
	(m, k) = (k, m)
print(max(0, k - (m + n)))


(W, a, b) = list(map(int, input().split()))
a_l = a
a_r = a + W
b_l = b
b_r = b + W
if b_r < a_l:
	print(abs(b_r - a_l))
elif a_r < b_l:
	print(abs(a_r - b_l))
else:
	print(0)


(w, a, b) = (int(T) for T in input().split())
if a + w < b:
	print(b - (a + w))
elif a <= b <= a + w:
	print(0)
else:
	print(a - (b + w))


(w, a, b) = map(int, input().split())
d = [a - w - b, b - w - a][a < b]
print([0, d][d > 0])


import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

def si():
	return input()

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

def fi():
	return float(input())

def lstr():
	return input().split()

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

def lint_dec():
	return list(map(lambda x: int(x) - 1, input().split()))

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [int(input()) for _ in range(n)]

def lint_list(n):
	return [lint() for _ in range(n)]
(W, a, b) = lint()
print(max(0, max(a, b) - min(a, b) - W))


(w, a, b) = [int(x) for x in input().split()]
print(max(0, b - a - w, a - b - w))


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


(W, *s) = map(int, input().split())
(a, b) = sorted(s)
print((b - a - W) * (a + W < b))


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