Chef has an array consisting of N + K - 1 integers. The array contains only the first N positive odd numbers. Each number appears exactly once, except for one number which appears exactly K times. The sum of integers in Chef's array is equal to S.

For example, for N = 3, K = 2, the possible arrays could be [1, 1, 3, 5], [3, 1, 3, 5], [5, 3, 5, 1]. For N = 1, K = 3, there is only one possible array: [1, 1, 1].

Chef gives you three integers N, K and S and asks you to find the only element which appears K times in his array.

It is guaranteed that for the given input, there exists a valid array consisting of N + K -1 elements with a sum exactly equal to S.

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains three space-separated integers N, K, S.

------ Output Format ------ 

For each test case, print a single line containing the integer which appeared K times in Chef's array.

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

$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{4}$
$1 ≤ S ≤ 10^{9}$
$2 ≤ K ≤ 10^{4}$

----- Sample Input 1 ------ 
3
3 2 14
5 4 28
2 3 10

----- Sample Output 1 ------ 
5
1
3

----- explanation 1 ------ 
Test case $1$:  Chef's array could be $[5, 3, 5, 1]$.

Test case $3$: Chef's array could be $[3, 1, 3, 3]$.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split())
	lst = list(range(1, n * 2, 2))
	su = sum(lst)
	for i in lst:
		if (k - 1) * i + su == s:
			print(i)
			break


t = int(input())
for _ in range(t):
	(n, k, s) = [int(v) for v in input().split()]
	print((s - n * n) // (k - 1))


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	print((s - n ** 2) // (k - 1))


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	k = 1
	l = []
	for i in range(a):
		l.append(k)
		k = k + 2
	s = c - sum(l)
	print(s // (b - 1))


num_test_cases = int(input())
while num_test_cases > 0:
	(n_val, k_val, s_val) = map(int, input().split())
	s_val -= n_val * n_val
	k_val -= 1
	sol_val = s_val // k_val
	print(sol_val)
	num_test_cases -= 1


t = int(input())
for i in range(t):
	(n, k, s) = list(map(int, input().split()))
	S = sum(range(1, n * 2, 2))
	print((s - S) // (k - 1))


for i in range(int(input())):
	t = list(map(int, input().split()))
	n = t[0]
	k = t[1]
	s = t[2]
	sum = 0
	i = 1
	arr = []
	for j in range(n):
		sum += i
		arr.append(i)
		i += 2
	for i in arr:
		if sum + (k - 1) * i == s:
			print(i)
			break


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
T = int(input())
for _ in range(T):
	(N, K, S) = get_ints()
	arr = []
	sum_odd = N * N
	i = int(S - sum_odd) // (K - 1)
	print(i)


n = int(input())
for i in range(0, n):
	arr = [int(i) for i in input().split()]
	sum = 1
	j = 1
	for i in range(0, arr[0] - 1):
		j += 2
		sum += j
	ans = (arr[2] - sum) / (arr[1] - 1)
	print(int(ans))


t = int(input())
for i in range(t):
	(n, k, s) = [int(x) for x in input().split()]
	sum = 0
	j = 1
	a = 1
	while j <= n:
		sum += a
		a += 2
		j += 1
	res = s - sum
	print(int(res / (k - 1)))


t = int(input())
for i in range(t):
	l = []
	l = list(map(int, input().split(' ')))
	sum = l[0] * l[0]
	size = l[0] + l[1] - 1
	diff = l[2] - sum
	ans = diff / (size - l[0])
	print(int(ans))


t = int(input())
for _ in range(t):
	(n, k, s) = [int(x) for x in input().split()]
	odd_sum = 0
	for i in range(n):
		odd_sum += 2 * i + 1
	rem = s - odd_sum
	for i in range(n):
		if rem % (2 * i + 1) == 0 and rem / (2 * i + 1) == k - 1:
			print(2 * i + 1)
			break


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	x = n * n
	for i in range(1, n + 1):
		num = 2 * i - 1
		if x + (k - 1) * num == s:
			print(num)
			break


t = int(input())
while t > 0:
	(n, k, s) = map(int, input().split())
	for i in range(n):
		if s - n * n == (k - 1) * (2 * i + 1):
			print(2 * i + 1)
			break
	t -= 1


for i in range(int(input())):
	(N, K, S) = map(int, input().split())
	print((S - N * N) // (K - 1))


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	a = n * n
	for i in range(1, 2 * (n + k - 1) - 1, 2):
		if a + i * (k - 1) == s:
			print(i)
			break


t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split(' '))
	lst = []
	sums = 0
	for i in range(1, n * 2, 2):
		lst.append(i)
		sums = sums + i
	print(int((s - sums) / (k - 1)))


def odd(a):
	sum = 0
	b = 1
	while a > 0:
		sum = sum + b
		b += 2
		a -= 1
	return sum
for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	ns = odd(n)
	print(int((s - ns) / (k - 1)))


t = int(input())
while t:
	(a, b, c) = map(int, input().split())
	res = int((c - a * a) / (b - 1))
	print(res)
	t = t - 1


for _ in range(int(input())):
	(n, k, s) = map(int, input().strip().split())
	print(int((s - n ** 2) / (k - 1)))


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	ans = 0
	for j in range(n * 2):
		if j & 1:
			ans += j
	print((s - ans) // (k - 1))


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	i = 1
	temp = n
	arr = []
	while temp > 0:
		s = s - i
		arr.append(i)
		i += 2
		temp -= 1
	ans = 0
	for j in arr:
		if j * (k - 1) == s:
			ans = j
			break
	print(ans)


for i in range(int(input())):
	(N, K, S) = map(int, input('').split())
	sum = 0
	for j in range(1, N * 2 + 1, 2):
		sum = sum + j
	a = (S - sum) // (K - 1)
	print(a)


for i in range(int(input())):
	(n, k, ts) = map(int, input().split())
	x = 1
	su = 0
	for i in range(n):
		su += x
		x += 2
	print((ts - su) // (k - 1))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	print((l[2] - l[0] ** 2) // (l[1] - 1))


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	s_um = 0
	cnt = 0
	i = 1
	while cnt < l[0]:
		if i % 2 != 0:
			s_um += i
			cnt += 1
		i += 1
	k = (l[-1] - s_um) // (l[1] - 1)
	print(k)


def sumOfOdd(N):
	sumSoFar = 0
	for oddNum in [2 * i + 1 for i in range(N)]:
		sumSoFar += oddNum
	return sumSoFar
for _ in range(int(input())):
	(N, K, S) = [int(i) for i in input().split()]
	repeatedN = int((S - sumOfOdd(N)) / (K - 1))
	print(repeatedN)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	ans1 = abs(n * n - s)
	print(ans1 // (k - 1))


t = int(input())
for _ in range(t):
	(n, k, s) = map(int, input().split())
	ts = 0
	for i in range(n):
		ts += 2 * i + 1
	rs = (s - ts) // (k - 1)
	print(rs)


for _ in range(int(input())):
	(N, K, S) = map(int, input().split())
	print((S - N ** 2) // (K - 1))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	a = a ** 2
	ans = c - a
	b = b - 1
	print(ans // b)


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	i = 1
	c = 0
	l = []
	for j in range(n):
		l.append(i)
		i = i + 2
	s1 = sum(l)
	d = s - s1
	print(d // (k - 1))


for _ in range(int(input())):
	(N, K, S) = map(int, input().split())
	res = 0
	L = []
	for i in range(1, N * 2, 2):
		res += i
		L.append(i)
	for i in range(len(L)):
		if res + L[i] * (K - 1) == S:
			print(L[i])
			break


t = int(input())
while t > 0:
	t = t - 1
	(n, k, s) = map(int, input().split())
	s = s - n ** 2
	print(s // (k - 1))


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	ans = s - n * n
	l = []
	for i in range(n):
		l.append(2 * i + 1)
	for i in range(n):
		if ans / ((k - 1) * l[i]) == 1:
			print(l[i])


for t in range(int(input())):
	(n, k, s) = map(int, input().split())
	odd_sum = n * n
	print(int((s - odd_sum) / (k - 1)))


T = int(input())
for i in range(T):
	(N, K, S) = input().split()
	N = int(N)
	K = int(K)
	S = int(S)
	s = N * (2 + (N - 1) * 2) / 2
	t = 1 + 10000 * 2
	r = int(S - s)
	for i in range(1, t, 2):
		w = i * (K - 1)
		if w == r:
			print(i)
			break


t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split(' ', 3))
	su = n * n
	rem = s - su
	print(rem // (k - 1))


t = int(input())
for i in range(t):
	n_k_s = input().split(' ')
	(n, k, s, sum_n) = (int(n_k_s[0]), int(n_k_s[1]), int(n_k_s[2]), 0)
	for j in range(1, n + 1):
		sum_n += 2 * j - 1
	print((s - sum_n) // (k - 1))


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	g = []
	j = 0
	for i in range(2 * n + 1):
		if i % 2 != 0:
			g.append(i)
	for i in range(len(g)):
		j += g[i]
	h = int(s - j)
	print(h // (k - 1))


t = int(input())
for tc in range(t):
	(n, k, s) = map(int, input().split())
	l = []
	for j in range(1, n + 1):
		l.append(2 * j - 1)
	x = (s - sum(l)) // (k - 1)
	print(x)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	l = []
	for i in range(1, n + 1):
		l.append(2 * i - 1)
	p = sum(l)
	x = s - sum(l)
	for j in l:
		if (k - 1) * j == x:
			print(j)


import sys
for _ in range(int(sys.stdin.readline())):
	(n, k, s) = map(int, sys.stdin.readline().split())
	sys.stdout.write(str((s - n * n) // (k - 1)) + '\n')


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	l = []
	for j in range(n):
		l.append(2 * j + 1)
	num = (s - sum(l)) // (k - 1)
	print(num)


for _ in range(int(input())):
	(N, K, s) = map(int, input().split())
	print(abs(s - N * N) // (K - 1))


x = int(input())
for i in range(x):
	(n, k, s) = map(int, input().split())
	l = []
	for i in range(1, n + 1):
		b = i * 2 - 1
		l.append(b)
	su = sum(l)
	v = s - su
	for j in l:
		if j * (k - 1) == v:
			print(j)
			break


x = int(input())
p = []
for jjv in range(0, x):
	up = str(input())
	il = up.split(' ')
	th = []
	for mm in il:
		th.append(int(mm))
	p.append(th)
for kke in p:
	ynu = kke[2] - kke[0] ** 2
	um = 1
	for lp in range(0, kke[0]):
		if ynu % um == 0:
			if ynu // um == kke[1] - 1:
				print(um)
				break
		um += 2


for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	odd = 1
	total = 0
	while n:
		total += odd
		odd += 2
		n -= 1
	print((s - total) // (k - 1))


t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split())
	l = []
	for i in range(1, 2 * n, 2):
		l.append(i)
	si = sum(l)
	p = s - si
	r = p // (k - 1)
	print(r)