Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and therefore, wants to have the minimum possible difference between the number of apples and oranges he has. To do so, he can purchase 1 apple or 1 orange by paying exactly 1 gold coin (that's some expensive fruit, eh?). Chef can purchase fruits at most K times (as he has only K gold coins in his pocket) to make the difference the minimum possible.
Our little Chef is busy in celebrating his birthday to the fullest, and therefore, he has handed this job to his best friend — you. Can you help him by finding the minimum possible difference he can achieve between the number of apples and orange he owns?

-----Input-----
The first line of input contains a single integer T denoting the number of test cases. The first and only line of each test case contains 3 space separated integers — N, M and K — denoting the number of apples, number of oranges, and number of gold coins our little Chef has.

-----Output-----
For each test case, output the minimum possible difference between the number of apples and oranges that Chef can achieve.

-----Constraints-----
- 1 ≤ T ≤ 100
- 1 ≤ N, M, K ≤ 100

-----Example-----Input
3
3 4 1
5 2 1
3 4 3

Output
0
2
0

-----Explanation-----
- Test 1: Chef will buy 1 apple by paying 1 gold coin and will have equal number of apples and oranges. 
- Test 2: Chef will buy 1 orange by paying 1 gold coin and will have 5 apples and 3 oranges.

Source: codechef | Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc


Solutions:
for i in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	if abs(a - b) >= c:
		print(abs(a - b) - c)
	else:
		print(0)


test_case = int(input())
for i in range(test_case):
	(apple, orange, coin) = map(int, input().split())
	k = abs(apple - orange)
	if k >= coin:
		print(k - coin)
	else:
		print(0)


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	d = abs(N - M)
	print(0) if d <= K else print(d - K)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n == m:
		print('0')
	elif n > m:
		a = n - m
		if a < k or a == k:
			print('0')
		else:
			print(n - (m + k))
	else:
		a = m - n
		if a < k or a == k:
			print('0')
		else:
			print(m - (n + k))


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = 0
	a = min(n, m)
	b = max(n, m)
	while k > 0:
		if a == b:
			break
		else:
			a += 1
			k -= 1
	print(b - a)


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


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	dif = abs(n - m)
	if dif == k or k > dif:
		print(0)
	else:
		print(dif - k)


try:
	for i in range(int(input())):
		(n, m, k) = map(int, input().split())
		if n == m or abs(n - m) <= k:
			print('0')
		else:
			print(abs(n - m) - k)
except:
	pass


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	d = max(a, b)
	e = min(a, b)
	f = d - e
	if f <= c:
		print(0)
	else:
		print(f - c)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	for i in range(k):
		if n > m:
			m += 1
		elif n < m:
			n += 1
		else:
			break
	print(abs(n - m))


x = int(input())
for i in range(x):
	(a, b, c) = map(int, input().split())
	if abs(a - b) == c or abs(a - b) < c:
		print('0')
	elif abs(a - b) > c:
		print(abs(a - b) - c)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	d = abs(n - m)
	if k >= d:
		print('0')
	else:
		print(d - k)


T = int(input())
for i in range(T):
	(a, b, c) = map(int, input().split())
	for i in range(c):
		if a < b:
			a += 1
		elif a == b:
			break
		else:
			b += 1
	print(abs(a - b))


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	print(max(abs(n - m) - k, 0))


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


N = int(input())
for i in range(N):
	(m, o, k) = list(map(int, input().split()))
	d = abs(m - o)
	if k > d:
		print(0)
	else:
		print(d - k)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	r = abs(n - m)
	if r - k > 0:
		print(r - k)
	else:
		print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if max(n, m) - min(n, m) <= k:
		print(0)
	else:
		print(max(n, m) - min(n, m) - k)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	if abs(n - m) <= k or m == n:
		print(0)
	elif m > n and k <= abs(n - m):
		print(m - (n + k))
	else:
		print(n - (m + k))


t = int(input())
for _ in range(t):
	(N, M, K) = map(int, input().split())
	if N == M:
		print(0)
	elif N > M:
		while N > M and K > 0:
			M += 1
			K -= 1
		print(N - M)
	else:
		while N < M and K > 0:
			N += 1
			K -= 1
		print(M - N)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = abs(n - m)
	if a >= k:
		print(a - k)
	else:
		print('0')


t = int(input())
for i in range(t):
	(n, m, o) = map(int, input().split())
	if abs(n - m) > o:
		print(abs(n - m) - o)
	elif abs(n - m) <= o:
		print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	print(max(abs(n - m) - k, 0))


try:
	for _ in range(int(input())):
		(N, M, K) = map(int, input().split())
		diff = abs(N - M)
		print(0 if diff <= K else diff - K)
except:
	pass


T = int(input())
while T > 0:
	(N, M, K) = map(int, input().split())
	if abs(N - M) >= K:
		print(abs(N - M) - K)
	else:
		print(0)
	T -= 1


goals = int(input())
for distractions in range(goals):
	(wife, life, aim) = map(int, input().split())
	for stress in range(aim):
		if wife < life:
			wife += 1
		elif life < wife:
			life += 1
		else:
			break
	print(abs(life - wife))


for tc in range(int(input())):
	(n, m, k) = map(int, input().split())
	dif = abs(n - m) - k
	if dif < 0:
		dif = 0
	print(dif)


t = int(input())
for i in range(0, t):
	arr = list(map(int, input().split()))
	n = arr[0]
	m = arr[1]
	k = arr[2]
	if m > n:
		(n, m) = (m, n)
	diff = n - m
	if diff == k:
		print(0)
	elif diff > k:
		print(diff - k)
	else:
		print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if abs(n - m) <= k:
		print(0)
	else:
		print(abs(n - m) - k)


for _ in range(int(input())):
	(a, m, g) = [int(x) for x in input().split()]
	r = abs(a - m)
	if g <= r:
		print(r - g)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	if n > m:
		ma = n
		mi = m
		d = n - m
	elif m > n:
		ma = m
		mi = n
		d = m - n
	else:
		d = 0
	if d <= k:
		print(0)
	else:
		mi = mi + k
		print(ma - mi)


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	d = abs(n - m)
	if d <= k:
		print(0)
	else:
		print(d - k)
	t -= 1


for __ in range(int(input())):
	(N, M, K) = map(int, input().split(' '))
	d = abs(N - M)
	if K >= d:
		print(0)
	elif M == N:
		print(0)
	elif M > N and K <= d:
		print(M - (N + K))
	elif N > M and K <= d:
		print(N - (M + K))


import math

def makeeql(a, o, g):
	print(abs(max(a, o) - min(min(a, o) + g, max(a, o))))
for i in range(int(input())):
	(a, o, g) = map(int, input().split())
	makeeql(a, o, g)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	mi = min(n, m)
	ma = max(n, m)
	c = ma - mi
	rc = k - c
	if rc < 0:
		print(abs(rc))
	else:
		print(0)


n = int(input())
for i in range(n):
	(n, m, k) = list(map(int, input().split()))
	if n == m:
		print(0)
	elif n > m:
		c = n - m - k
		if c <= 0:
			print(0)
		else:
			print(c)
	else:
		c = m - n - k
		if c <= 0:
			print(0)
		else:
			print(c)


t = int(input())
for i in range(t):
	(m, n, k) = map(int, input().split())
	if max(m, n) - min(m, n) > k:
		y = min(m, n) + k
		print(max(m, n) - y)
	elif max(m, n) - min(m, n) <= k:
		print(0)


N = int(input())
for i in range(N):
	(n, m, k) = [int(x) for x in input().split()]
	y = min(n, m)
	z = max(n, m)
	if y + k >= z:
		print(0)
	else:
		print(z - (y + k))


try:
	for _ in range(int(input())):
		(a, o, g) = map(int, input().split())
		res = abs(a - o)
		if res > g:
			print(res - g)
		else:
			print(0)
except:
	pass


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if abs(n - m) > k:
		print(abs(n - m) - k)
	elif abs(n - m) <= k:
		print(0)


for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	if abs(x - y) <= z:
		print(0)
	else:
		print(abs(x - y) - z)


t = int(input())
for i in range(t):
	(a, o, g) = map(int, input().split())
	diff = abs(a - o)
	if diff <= g:
		print(0)
	else:
		print(diff - g)


for _ in range(int(input())):
	(a, b, k) = list(map(int, input().split()))
	if max(a, b) - min(a, b) - k <= 0:
		print('0')
	else:
		print(max(a, b) - min(a, b) - k)


for t in range(int(input())):
	(n, m, k) = map(int, input().split(' '))
	for i in range(k):
		if m < n:
			m += 1
		elif n < m:
			n += 1
	print(abs(m - n))


for i in range(int(input())):
	(a, b, k) = list(map(int, input().split()))
	k1 = abs(a - b)
	if k1 >= k:
		print(k1 - k)
	else:
		print(0)


t = input()
for i in range(int(t)):
	(m, n, k) = list(map(int, input().split()))
	if max(m, n) - min(m, n) > k:
		y = min(m, n) + k
		print(abs(max(m, n) - y))
	else:
		print(0)


T = int(input())
for t in range(T):
	(apples, oranges, coins) = input().split()
	apples = int(apples)
	oranges = int(oranges)
	coins = int(coins)
	while coins > 0:
		if apples > oranges:
			oranges += 1
			coins -= 1
		elif oranges > apples:
			apples += 1
			coins -= 1
		elif coins % 2 == 0:
			half = int(coins / 2)
			apples = apples + half
			oranges = oranges + half
			coins = 0
			break
		else:
			half = int(coins / 2)
			apples = apples + half
			oranges = oranges + half
			coins = 1
			break
	print(int(abs(apples - oranges)))


for _ in range(int(input())):
	(apples, oranges, coins) = map(int, input().split())
	if abs(apples - oranges) > coins:
		print(abs(apples - oranges) - coins)
	else:
		print(0)


tc = int(input())
for i in range(tc):
	NMK = list(map(int, input().split()))
	(N, M, K) = (NMK[0], NMK[1], NMK[2])
	if abs(N - M) >= K:
		print(abs(N - M) - K)
	else:
		print(0)


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	diff = abs(n - m)
	print(0 if k >= diff else diff - k)


for _ in range(int(input())):
	(a, o, g) = map(int, input().split())
	while g > 0:
		if a < o:
			a += 1
			g -= 1
		elif o < a:
			o += 1
			g -= 1
		else:
			break
	print(abs(a - o))


T = int(input())
for i in range(T):
	(N, M, K) = list(map(int, input().split()))
	if abs(N - M) >= K:
		print(abs(N - M) - K)
	else:
		print(0)


for x in range(int(input())):
	(A, O, K) = map(int, input().split())
	if A == O:
		print(0)
		continue
	s = min(A, O)
	b = max(A, O)
	print(0) if s + K >= b else print(b - (s + K))