Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 

Chef has two piles of stones with him, one has n_{1} stones and the other has n_{2} stones. Fired up by boredom, he invented a game with the two piles.

Before the start of the game Chef chooses an integer m.

In the j-th move: 
He chooses a number x_{j} such that 1 ≤ x_{j} ≤ m, and removes x_{j} stones from both the piles (this is only possible when both the piles have ≥ x_{j} stones).
The number chosen must be unique over all the moves in the game. That is, for all k < j, x_{j} ≠ x_{k}. 

The game stops when Chef is unable to make any more moves.

Chef wants to make the moves in such a way that the sum of the number of stones remaining in the two piles is minimized. Please help Chef find this.

------ Input ------ 

The first line of input contains an integer T denoting the number of test cases.
Each test case consists of 1 line with three integers — n_{1}, n_{2} and m — separated by single spaces. 

------ Output ------ 

For each test case, output a single line containing the minimum sum of the number of stones of two piles.

------ Constraints ------ 

Subtask 1 : (5 pts)
$1 ≤ T ≤ 100$
$0 ≤ m ≤ 18$
$0 ≤ n_{1}, n_{2} ≤ 100$
Subtask 2 : (25 pts)
$1 ≤ T ≤ 1000$
$0 ≤ m ≤ 10000$
$0 ≤ n_{1}, n_{2} ≤ 10000$
Subtask 3 : (70 pts)
$1 ≤ T ≤ 10^{5}$
$0 ≤ m ≤ 10^{9}$
$0 ≤ n_{1}, n_{2} ≤ 10^{18}$

----- Sample Input 1 ------ 
3
1 1 1
1 2 1
4 5 2
----- Sample Output 1 ------ 
0
1
3
----- explanation 1 ------ 
Example case 1. : Remove 1 stone from each of the piles. Now 0 stones are remaining, so chef cannot remove any more stones from the piles. Hence, answer is 0+0 = 0
Example case 2. : Again, remove 1 stone from both the piles to get (0,1) stones. Now chef cannot remove any more stones from pile 1, so he stops. Hence, answer is 0+1 = 1.
Example case 3. : First remove 1 stone from both the piles to get (3,4) stones. Now, remove 2 stones from both the piles so that (1,2) stones are remaining. Now chef cannot remove any more stones owing to the condition that he cannot remove the same number of stones twice. So, the answer is 1+2 = 3.

Difficulty: MEDIUM
Tags: Mathematics

Starter code:

Solutions:
for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	most = m * (m + 1)
	if n1 >= most / 2 and n2 >= most / 2:
		print(n1 + n2 - most)
	else:
		spile = min(n1, n2)
		print(n1 + n2 - spile * 2)


for _ in range(int(input())):
	(a, b, m) = map(int, input().split())
	max_remove = m * (m + 1) // 2
	if a >= max_remove and b >= max_remove:
		print(a + b - 2 * max_remove)
	else:
		print(a + b - 2 * min(a, b))


for _ in range(int(input())):
	(n1, n2, m) = list(map(int, input().split()))
	m_max = m * (m + 1) // 2
	sub = min(n1, n2, m_max)
	ans = n1 + n2 - 2 * sub
	print(ans)


from functools import lru_cache
import atexit, io
import sys
from math import log2
import math
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right, insort
from math import gcd
from math import sqrt
from collections import Counter, defaultdict
from heapq import heappush, heappop, heapify
import heapq

class FenwickTree:

	def __init__(self, n):
		self.farr = [0] * (n + 1)

	def prefixSum(self, idx):
		s = 0
		while idx > 0:
			s += self.farr[idx]
			idx -= idx & -idx
		return s

	def update(self, idx, val):
		while idx < len(self.farr):
			self.farr[idx] += val
			idx += idx & -idx

	def find(self, k):
		curr = 0
		ans = 0
		prevSum = 0
		for i in range(log2(n), -1, -1):
			if self.farr[curr + (i << i)] + prevSum < k:
				curr += 1 << i
				prevSum += self.farr[curr]
		return curr + 1

class Trie(object):

	def __init__(self):
		self.trie = {}

	def insert(self, word):
		t = self.trie
		for c in word:
			if c not in t:
				t[c] = {}
			t = t[c]
		t['-'] = True

	def search(self, word):
		t = self.trie
		for c in word:
			if c not in t:
				return False
			t = t[c]
		return '-' in t

	def startsWith(self, prefix):
		t = self.trie
		for c in prefix:
			if c not in t:
				return False
			t = t[c]
		return True

	def query(self, word):
		ans = 0
		t = self.trie
		for i in word:
			if i not in t:
				break
			ans += 1
			t = t[i]
		return ans

class FenvTree:

	def __init__(self, arr):
		arr.insert(0, 0)
		self.farr = [0]
		prefix = [0]
		for i in arr[1:]:
			prefix.append(prefix[-1] + i)
		for i in range(1, len(arr)):
			idash = i - (i & -i)
			self.farr.append(prefix[i] - prefix[idash])

	def query(self, l, r):
		return self.prefixSum(r) - self.prefixSum(l - 1)

	def prefixSum(self, idx):
		s = 0
		while idx > 0:
			s += self.farr[idx]
			idx -= idx & -idx
		return s

	def update(self, idx, val):
		while idx < len(self.farr):
			self.farr[idx] += val
			idx += idx & -idx

class DSU:

	def __init__(self, n):
		self.parent = []
		self.size = []
		for i in range(n + 1):
			self.parent.append(i)
			self.size.append(1)

	def union(self, u, v):
		pu = self.findPar(u)
		pv = self.findPar(v)
		if pu == pv:
			return
		if self.size[pu] < self.size[pv]:
			self.parent[pu] = pv
			self.size[pv] += self.size[pu]
		else:
			self.parent[pv] = pu
			self.size[pu] += self.size[pv]

	def unionByRank(self, u, v):
		pu = self.findPar(u)
		pv = self.findPar(v)
		if pu == pv:
			return
		if self.rank[pu] < self.rank[pv]:
			self.parent[pu] = pv
		elif self.rank[pv] < self.rank[pu]:
			self.parent[pv] = pu
		else:
			self.parent[pu] = pv
			self.rank[pv] += 1

	def findPar(self, node):
		if self.parent[node] == node:
			return node
		self.parent[node] = self.findPar(self.parent[node])
		return self.parent[node]

class info:

	def __init__(self, _open=0, _close=0, _full=0):
		self.open = _open
		self.close = _close
		self.full = _full

class SGTree:

	def __init__(self, n):
		self.seg = [0 for _ in range(4 * n)]

	def build(self, ind, low, high, arr):
		if low == high:
			self.seg[ind] = arr[low]
			return
		mid = (low + high) // 2
		self.build(2 * ind + 1, low, mid, arr)
		self.build(2 * ind + 2, mid + 1, high, arr)
		self.seg[ind] = min(self.seg[2 * ind + 1], self.seg[2 * ind + 2])

	def query(self, ind, low, high, l, r):
		if r < low or l > high:
			return sys.maxsize
		if low <= l and r >= high:
			return self.seg[ind]
		mid = low + high >> 1
		left = self.query(2 * ind + 1, 0, mid, l, r)
		right = self.query(2 * ind + 2, mid + 1, high, l, r)
		return min(left, right)

	def update(self, ind, low, high, i, val):
		if low == high:
			self.seg = val
			return
		mid = low + high >> 1
		if i <= mid:
			self.update(2 * ind + 1, low, mid, i, val)
		else:
			self.update(2 * ind + 1, mid + 1, high, i, val)
		self.seg[ind] = min(self.seg[2 * ind + 1], self.seg[2 * ind + 2])

def isPalindrome(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

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

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

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

def StrList():
	list(sys.stdin.readline().strip())

def FloatList():
	lis = input().split()
	lis = list(map(float, lis))
	return lis

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n + 1):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p]:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1

def findPrimePair(n):
	isPrime = [0] * (n + 1)
	SieveOfEratosthenes(n, isPrime)
	for i in range(0, n):
		if isPrime[i] and isPrime[n - i]:
			print(i, n - i)
			return

def query(ind, low, high, l, r, seg):
	if r < low or l > high:
		return info()
	if low <= l and r >= high:
		return self.seg[ind]
	mid = low + high >> 1
	left = self.query(2 * ind + 1, 0, mid, l, r, seg)
	right = self.query(2 * ind + 2, mid + 1, high, l, r, seg)
	return merge(left, right)

def merge(left, right):
	ans = info()
	ans.full = left.full + right.full + min(left.open, right.close)
	ans.open = left.open + right.open + min(left.open, right.close)
	ans.close = left.close + right.close + min(left.open, right.close)
	return ans

def build(ind, low, high, s, seg):
	if low == high:
		seg[ind] = info(s[low] == '(', s[low] == ')', 0)
		return
	mid = (low + high) // 2
	build(2 * ind + 1, low, mid, s, seg)
	build(2 * ind + 2, mid + 1, high, s, seg)
	seg[ind] = merge(seg[2 * ind + 1], seg[2 * ind + 2])

def countN(lis):
	ans = 0
	cnt = 0
	for i in range(len(lis) - 1, -1, -1):
		if lis[i] == 0:
			cnt += 1
		else:
			ans += cnt
	return ans

class Pair:

	def __init__(self, x, y, gcd):
		self.x = x
		self.y = y
		self.gcd = gcd

def Euclidean(a, b):
	if b == 0:
		return Pair(1, 0, a)
	dash = Euclidean(b, a % b)
	return Pair(dash.y, dash.x - a // b * dash.y, dash.gcd)

def chineseRemainder(a1, n1, a2, n2):
	p = Euclidean(n1, n2)
	x = p.x
	gcd = p.gcd
	if (a1 - a2) % gcd:
		return -1
	k = (a1 - a2) // gcd
	a = a1 - n1 * (k * x % n2 // gcd)
	lcm = n1 * n2 // gcd
	if a < 0:
		a += lcm
	return a

def ncr(n, k, md):
	mod = 998244353
	tab = [[0 for _ in range(k + 1)] for i in range(n + 1)]
	for i in range(1, len(tab)):
		tab[i][0] = 1
	for i in range(1, len(tab)):
		for j in range(1, min(i + 1, len(tab[0]))):
			if i == 1 and j == 1:
				tab[i][j] = 1
			else:
				tab[i][j] = (tab[i - 1][j] + tab[i - 1][j - 1]) % mod
	return tab

def repeat(i, j, arr):
	if i > j:
		return
	cnt1 = i
	cnt2 = j
	while cnt1 < cnt2:
		(arr[cnt1], arr[cnt2]) = (arr[cnt2], arr[cnt1])
		cnt1 += 1
		cnt2 -= 1
	if i - 1 >= 0:
		ele = arr[i - 1]
		if ele > 0:
			s = int(sqrt(ele - 1)) + 1
			first = s * s - ele
			repeat(first, i - 1, arr)
	return
spf = []

def makeSeive(n):
	for i in range(n + 1):
		spf.append(i)

def seive(n):
	s = int(sqrt(n + 1))
	for i in range(2, s + 1):
		if spf[i] == i:
			for j in range(i * i, n + 1, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = set()
	while x != 1:
		ret.add(spf[x])
		x = x // spf[x]
	return ret

def getLPS(s):
	st = '@#' + '#'.join(s) + '#&'
	c = 0
	r = 0
	lps = [0] * len(st)
	for i in range(1, len(st) - 1):
		mirror = c - (i - c)
		if i < r and mirror >= 0:
			lps[i] = min(lps[mirror], r - i)
		while st[i + lps[i] + 1] == st[i - lps[i] - 1]:
			lps[i] += 1
		if i + lps[i] > r:
			r = i + lps[i]
			c = i
	return max(lps)
fact = [1 for _ in range(100002)]
mod = 10 ** 9 + 7

def getFact(n):
	for i in range(1, n + 1):
		fact[i] = fact[i - 1] * i % mod

def getInv(word):
	num = math.factorial(len(word))
	for v in Counter(word).values():
		num = num * pow(math.factorial(v), mod - 2, mod) % mod
	return int(num) % (10 ** 9 + 7)

def subarrayXor(arr, n, m):
	HashTable = defaultdict(bool)
	HashTable[0] = 1
	count = 0
	curSum = 0
	for i in arr:
		curSum ^= i
		if HashTable[curSum ^ m]:
			count += HashTable[curSum ^ m]
		HashTable[curSum] += 1
	return count

def get2dPrefixSum(matrix, mid=0):
	n = len(matrix)
	m = len(matrix[0])
	prefix = [[0 for _ in range(m + 1)] for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + matrix[i - 1][j - 1]
	return prefix

def get2dPrefixSumCnt(matrix, mid=0):
	n = len(matrix)
	m = len(matrix[0])
	prefix = [[0 for _ in range(m + 1)] for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + matrix[i - 1][j - 1]
	return prefix

def getSumRange(r1, c1, r2, c2, prefix):
	cnt = prefix[r2][c2] - prefix[r2][c1 - 1] - prefix[r1 - 1][c2] + prefix[r1 - 1][c1 - 1]
	return cnt

def getPrefix(arr):
	prefix = [0]
	for i in arr:
		prefix.append(prefix[-1] + i)
	return prefix

def getInv(arr):
	cnt = 0
	ans = []
	for i in arr:
		ind = bisect_right(ans, i)
		cnt += len(ans) - ind
		insort(ans, i)
	return cnt
M = 10 ** 5

def getFactors(x):
	temp = []
	k = 1
	while k * k <= x:
		if x % k == 0:
			temp.append(k)
			if k * k != x:
				temp.append(x // k)
		k += 1
	return temp

def grayCode(n):
	if not n:
		return [0]
	res = [0, 1]
	for i in range(2, n + 1):
		for j in range(len(res) - 1, -1, -1):
			res.append(res[j] | 1 << i - 1)
	return res

def threeSum(nums, target):
	ans = -1
	d = dict()
	for (i, j) in enumerate(nums):
		d[j] = i + 1
	nums.sort()
	for i in range(len(nums) - 2):
		low = i + 1
		high = len(nums) - 1
		while low < high:
			s = nums[i] + nums[low] + nums[high]
			if s == target:
				print(d[nums[low]], d[nums[high]], d[nums[i]])
				return
				low += 1
				high -= 1
			elif s < 0:
				low = low + 1
			else:
				high -= 1
	print('IMPOSSIBLE')
	return

def medianSlidingWindow(nums, k):
	(low, high) = ([], [])
	for i in range(k):
		heapq.heappush(high, (nums[i], i))
	for _ in range(k >> 1):
		convert(high, low)
	ans = {high[0][0] if k & 1 else min(high[0][0], low[0][0])}
	for i in range(len(nums[k:])):
		if nums[i + k] >= high[0][0]:
			heapq.heappush(high, (nums[i + k], i + k))
			if nums[i] <= high[0][0]:
				convert(high, low)
		else:
			heapq.heappush(low, (-nums[i + k], i + k))
			if nums[i] >= high[0][0]:
				convert(low, high)
		while low and low[0][1] <= i:
			heapq.heappop(low)
		while high and high[0][1] <= i:
			heapq.heappop(high)
		ans.append(high[0][0] if k & 1 else min(high[0][0], low[0][0]))
	return [abs(i) for i in ans]

def convert(heap1, heap2):
	(element, index) = heapq.heappop(heap1)
	heapq.heappush(heap2, (-element, index))

def PrateekGoel(s, x):
	A = (s - x) // 2
	first = 0
	second = 0
	for i in range(32):
		Xi = 1 << i & x
		Ai = 1 << i & A
		if Xi == 0 and Ai == 0:
			continue
		elif Xi == 0 and Ai > 0:
			first |= 1 << i
			second |= 1 << i
		elif Xi > 0 and Ai == 0:
			first |= 1 << i
		else:
			return [-1]
	return [first, second]

def FUCKCF():
	(n1, n2, m) = getInts()
	val = m * (m + 1) // 2
	mn = min(n1, n2)
	mnn = min(mn, val)
	print(n1 + n2 - 2 * mnn)
t = 1
t = int(input())
for i in range(t):
	FUCKCF()


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	total = m * (m + 1) // 2
	p = min(total, min(n1, n2))
	print(abs(n1 + n2 - 2 * p))


for t in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	sum = m * (m + 1) // 2
	if sum > min(n1, n2):
		print(abs(n1 - n2))
	else:
		print(int(n1 + n2 - sum * 2))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = c
	x = 0
	ans = 0
	if a < b:
		x = a
	else:
		x = b
	summ = c * (c + 1)
	summ = summ // 2
	subt_val = min(x, summ)
	print(a - subt_val + (b - subt_val))


for _ in range(int(input())):
	mone = input()
	lst = mone.split()
	n1 = int(lst[0])
	n2 = int(lst[1])
	m = int(lst[2])
	if m * (m + 1) / 2 > n1 and m * (m + 1) / 2 > n2:
		print(abs(n1 - n2))
	elif m * (m + 1) / 2 > n1:
		print(n2 - n1)
	elif m * (m + 1) / 2 > n2:
		print(n1 - n2)
	else:
		print(n1 + n2 - m * (m + 1))


from collections import Counter, UserString
mod = lambda n: n % (10 ** 9 + 7)
fc_ = [1]
for i in range(1, 1000001):
	fc_.append(i * fc_[i - 1])
	fc_[i] = mod(fc_[i])

def fact(n):
	return fc_[n]

def printm(n):
	print(mod(n))

def isPrime(n):
	if n > 1:
		for i in range(2, int(n ** 0.5) + 1):
			if not n % i:
				return False
		else:
			return True
	return True

class mutableStr(UserString):

	def ins(self, n, s):
		if n < 0:
			self.data = self.data = ''.join(list(self.data)[:n + 1]) + s + ''.join(list(self.data)[n + 1:])
		else:
			self.data = ''.join(list(self.data)[:n]) + s + ''.join(list(self.data)[n:])

	def rem(self, s):
		self.data = self.data.replace(s, '')
alphabetOrd = [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122]
alphabet = list('abcdefghijklmnopqrstuvwxyz')
r1 = lambda n: range(n)
r2 = lambda n: range(1, n + 1)
alph = lambda s: s.isalpha()
sl = lambda l: list(set(l))
inf = float('inf')
soi = lambda : sorted(input())
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
si = lambda : mutableStr(input())
lsi = lambda : list(input())
sepi = lambda : map(int, input().split())
seti = lambda : set(map(int, input().split()))
for t in range(int(input())):
	(n1, n2, m) = sepi()
	j = m * (m + 1) // 2
	if j >= n1 or j >= n2:
		print(abs(n1 - n2))
	else:
		print(n1 + n2 - 2 * j)


t = int(input())
for i in range(t):
	(n1, n2, m) = map(int, input().split(' '))
	total = m * (m + 1) // 2
	if total >= min(n1, n2):
		print(max(n1, n2) - min(n1, n2))
	else:
		p1 = n1 - total
		p2 = n2 - total
		sum = p1 + p2
		print(sum)


for t in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	n = m * (m + 1) // 2
	a = min(n1, n2, n)
	print(n1 + n2 - 2 * a)


t = int(input())
for z in range(t):
	(n, m, a) = map(int, input().split())
	s = a * (a + 1) // 2
	l = min(n, m, s)
	la = n + m - l - l
	print(la)


T = int(input())
for i in range(T):
	(n1, n2, m) = map(int, input().split())
	j = m * (m + 1) // 2
	if j >= n1 or j >= n2:
		print(abs(n1 - n2))
	else:
		print(n1 + n2 - 2 * j)


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	m_tot = m * (m + 1) // 2
	low = min(n1, n2)
	if m_tot > low:
		v = low
	else:
		v = m_tot
	print(n1 + n2 - v * 2)


tests = int(input())
for i in range(tests):
	(a, b, m) = map(int, input().split())
	max_removed = m * (m + 1) // 2
	minimum = min(a, b, max_removed)
	print(a + b - 2 * minimum)


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	max_val = m * (m + 1) // 2
	min_val = min(n1, n2, max_val)
	print(n1 - min_val + (n2 - min_val))


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	mini = min(n1, n2)
	maxi = max(n1, n2)
	del n2
	if mini <= m:
		maxi -= mini
		mini = 0
		print(mini + maxi)
	else:
		n1 = m * (m + 1) // 2
		if n1 >= mini:
			maxi -= mini
			mini = 0
		else:
			mini -= n1
			maxi -= n1
		print(mini + maxi)


for _ in range(int(input())):
	(a, b, m) = map(int, input().split())
	n = min(a, b)
	m = m * (m + 1) // 2
	if m <= n:
		c = a + b - 2 * m
	else:
		c = a + b - n - n
	print(c)


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	a = m * (m + 1) // 2
	b = min(n1, n2)
	if b >= a:
		print(n1 + n2 - 2 * a)
	else:
		print(n1 + n2 - 2 * b)


a = int(input())
inputbag = []
for i in range(0, a):
	temp = list(map(int, input().split(' ')))
	inputbag.append(temp)
	(a, b, c) = temp
	temp1 = max(a + b - c * (c + 1), a - b, b - a)
	print(int(temp1))


for xxxxxxxx in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	print(max(n1 + n2 - m * (m + 1), n1 - n2, n2 - n1))


for _ in range(int(input())):
	(a, b, m) = [int(s) for s in input().split()]
	mc2 = m * (m + 1) // 2
	if min(a, b) > mc2:
		print(a + b - (mc2 << 1))
	else:
		print(abs(a - b))


t = int(input())
for i in range(t):
	(n1, n2, m) = map(int, input().split())
	z = m * (m + 1) // 2
	if z > min(n1, n2):
		print(n1 + n2 - 2 * min(n1, n2))
	else:
		print(n1 + n2 - 2 * z)


tc = int(input())
for _ in range(1, 1 + tc):
	(n1, n2, m) = map(int, input().split())
	x = min(m * (m + 1) // 2, n1, n2)
	ans = n1 + n2 - 2 * x
	print(ans)


t = int(input())
for _ in range(t):
	(n1, n2, m) = map(int, input().split())
	maxi = m * (m + 1)
	if n1 >= maxi // 2 and n2 >= maxi // 2:
		ans = n1 + n2 - maxi
	else:
		ans = abs(n1 - n2)
	print(ans)


t = int(input())
for _ in range(t):
	(n1, n2, m) = map(int, input().split())
	res = max(n1 + n2 - m * (m + 1), abs(n1 - n2))
	print(res)


for i in range(int(input())):
	(pile1, pile2, m) = map(int, input().split(' '))
	min_ = min(pile1, pile2)
	max_ = m * (m + 1) // 2
	if min_ <= max_:
		print(pile1 + pile2 - 2 * min_)
	else:
		print(pile1 + pile2 - 2 * max_)


n = int(input())
for i in range(n):
	(n1, n2, n3) = map(int, input().split())
	n4 = min(n1, n2)
	n5 = n3 * (n3 + 1) // 2
	n6 = n1 + n2
	if n4 > n5:
		print(n6 - 2 * n5)
	else:
		print(max(n1, n2) - min(n1, n2))


test = int(input())
for _ in range(test):
	(p, q, m) = list(map(int, input().split()))
	t = min(p, q)
	s = m * (m + 1) // 2
	if t > s:
		print(p + q - 2 * s)
	else:
		print(max(p, q) - min(p, q))


tc = int(input())
for i in range(tc):
	(x, y, m) = map(int, input().split())
	min_ = min(x, y)
	m = m * (m + 1) // 2
	if m <= min_:
		res = x + y - 2 * m
	else:
		res = x + y - 2 * min_
	print(res)


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	mini = min(n1, n2)
	s = m * (m + 1) // 2
	if s >= mini:
		print(abs(n2 - n1))
	else:
		print(n2 + n1 - 2 * s)


for i in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	k = min(n1, n2, m * (m + 1) // 2)
	print(n1 + n2 - 2 * k)


for _ in range(int(input())):
	(n1, n2, val) = map(int, input().split())
	mn = min(n1, n2)
	val = val * (val + 1) // 2
	if val <= mn:
		res = n1 + n2 - val - val
	else:
		res = n1 + n2 - mn - mn
	print(res)


for _ in range(int(input())):
	(n1, n2, m) = map(int, input().split())
	ap = m * (1 + m) // 2
	if n1 >= ap and n2 >= ap:
		print(n1 + n2 - 2 * ap)
	else:
		print(abs(n1 - n2))


for _ in range(int(input())):
	(stonesInPileOne, stonesInPileTwo, m) = map(int, input().split())
	smallestPile = min(stonesInPileOne, stonesInPileTwo)
	maxPossibleStoneRemovable = 0
	if smallestPile > m:
		maxPossibleStoneRemovable = min(m * (m + 1) // 2, smallestPile)
	else:
		maxPossibleStoneRemovable = smallestPile
	print(stonesInPileOne + stonesInPileTwo - 2 * maxPossibleStoneRemovable)


t = int(input())
for i in range(t):
	(x, y, m) = map(int, input().split())
	n = min(x, y)
	if m * (m + 1) / 2 > n:
		print(x + y - 2 * n)
	else:
		print(x + y - m * (m + 1))


T = int(input())
while T > 0:
	(n1, n2, M) = map(int, input().split())
	maxRemoval = M * (M + 1) // 2
	currentRemoval = min(n1, n2)
	if currentRemoval < maxRemoval:
		print(n1 + n2 - 2 * currentRemoval)
	else:
		print(n1 + n2 - 2 * maxRemoval)
	T -= 1


try:
	for _ in range(int(input())):
		(a, b, m) = map(int, input().split())
		(a, b) = (min(a, b), max(a, b))
		m = m * (m + 1) // 2
		if a > m:
			print(a + b - 2 * m)
		else:
			print(b - a)
except:
	pass


numTest = int(input())
for _ in range(numTest):
	(n1, n2, m) = tuple(map(int, input().split()))
	mn = min(n1, n2)
	m = int(m * (m + 1) // 2)
	if mn >= m:
		print(n1 + n2 - 2 * m)
	else:
		print(n1 + n2 - 2 * mn)


for t in range(0, int(input())):
	(n1, n2, m) = map(int, input().split())
	total = 0
	mini = min(n1, n2)
	total = m * (m + 1) // 2
	if total >= mini:
		if n1 == mini:
			print(n2 - mini)
		else:
			print(n1 - mini)
	else:
		print(n1 - total + n2 - total)


import numpy as np
T = int(input())
output = []
for t in range(T):
	(n1, n2, m) = [int(x) for x in input().split()]
	n_min = min(n1, n2)
	n_max = max(n1, n2)
	diff = n_max - n_min
	tmp = m * (m + 1) // 2
	if tmp <= n_min:
		stones_left = n_min - tmp
		output.append(2 * stones_left + diff)
	else:
		k = int(np.sqrt(2 * n_min))
		while k * (k + 1) / 2 > n_min:
			k -= 1
		initial_sum = k * (k + 1) // 2
		if initial_sum == n_min:
			output.append(diff)
		else:
			max_gain = m - 1
			if n_min - initial_sum <= max_gain:
				output.append(diff)
			else:
				output.append(2 * (n_min - initial_sum - max_gain) + diff)
for o in output:
	print(o)


t = int(input())
for _ in range(t):
	(x, y, m) = map(int, input().split())
	m = m * (m + 1) // 2
	if min(x, y) <= m:
		print(abs(x - y))
	else:
		print(x + y - 2 * m)