Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elements had the same value.
Chef still knows the remaining $N$ elements — a sequence $A_1, A_2, \ldots, A_N$. Help him with restoring the original sequence by finding the value of the deleted elements or deciding that there is some mistake and the described scenario is impossible.
Note that the if it is possible for the deleted elements to have the same value, then it can be proven that it is unique. Also note that this value must be a positive integer.

-----Input-----
- 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 line of each test case contains three space-separated integers $N$, $K$ and $V$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer — the value of the deleted elements, or $-1$ if there is a mistake.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N, K \le 100$
- $1 \le V \le 10^5$
- $1 \le A_i \le 10^5$ for each valid $i$

-----Subtasks-----
Subtask #1 (100 points): original constraints

-----Example Input-----
3
3 3 4
2 7 3
3 1 4
7 6 5
3 3 4
2 8 3

-----Example Output-----
4
-1
-1

Source: codechef | Difficulty: EASY
Tags: Mathematics


Solutions:
test = int(input())
for _ in range(test):
	(n, k, v) = tuple(map(int, input().split()))
	nlist = list(map(int, input().split()))
	sumOfList = sum(nlist)
	result = (v * (n + k) - sumOfList) / k
	if result > 0 and result % 1 == 0:
		print(int(result))
	else:
		print(-1)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	size = n + k
	a = list(map(int, input().split()))
	s = size * v
	rem = s - sum(a)
	if rem % k == 0 and rem > 0:
		print(int(rem / k))
	else:
		print(-1)


t = int(input())
while t:
	(n, k, v) = map(int, input().split(' '))
	lst = list(map(int, input().split(' ')))
	tot = sum(lst)
	x = (v * (n + k) - tot) / k
	if int(x) == x and x > 0:
		print(int(x))
	else:
		print(-1)
	t = t - 1


for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	x = v * (n + k) - s
	if x % k == 0 and x > 0:
		print(x // k)
	else:
		print(-1)


import math
t = int(input())

def do():
	(n, k, v) = list(map(int, input().split()))
	a = [int(d) for d in input().split()]
	r = 0
	r = (v * (n + k) - sum(a)) // k
	if r <= 0:
		print(-1)
	elif (v * (n + k) - sum(a)) % k != 0:
		print(-1)
	else:
		print(r)
	return
for i in range(t):
	do()


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	sn = sum(l)
	v1 = v * (n + k)
	v2 = v1 - sn
	ans = v2 // k
	if v2 % k == 0 and ans > 0:
		print(ans)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	(N, K, V) = map(int, input().split())
	Nl = list(map(int, input().split()))
	val = (N + K) * V
	s = 0
	for j in Nl:
		s += j
	r = (val - s) / K
	q = (val - s) % K
	if r > 0 and q == 0:
		print(int(r))
	elif r <= 0:
		print(-1)
	elif q != 0:
		print(-1)


t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	Sn = sum(a)
	kterm = v * (n + k) - Sn
	ans = kterm % k
	if kterm > 1 and ans == 0:
		print(kterm // k)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, k, v) = map(int, input().split())
	integers = list(map(int, input().split()))
	ans = sum(integers)
	if (v * n + v * k - ans) % k != 0 or v * n + v * k - ans < k:
		print(-1)
	else:
		print((v * n + v * k - ans) // k)


T = int(input())
while T:
	T -= 1
	(N, K, V) = map(int, input().split())
	ns = list(map(int, input().split()))
	s = sum(ns)
	temp = V * (N + K) - s
	if temp > 0 and temp % K == 0:
		print(int(temp / K))
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, k, mean) = map(int, input().split())
	L = list(input().split())
	for i in range(n):
		L[i] = int(L[i])
	partialsum = sum(L)
	totalsum = (n + k) * mean
	difference = totalsum - partialsum
	if difference % k == 0 and difference > 0:
		print(difference // k)
	else:
		print(-1)


for t in range(int(input())):
	(n, k, v) = [int(x) for x in input().rstrip().split()]
	a = [int(x) for x in input().rstrip().split()]
	sums = (n + k) * v
	b = sums - sum(a)
	if b > 0:
		if b % k == 0:
			print(b // k)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	d = (n + k) * v - int(sum(a))
	if d > 0 and d % k == 0:
		print(d // k)
	else:
		print(-1)


T = int(input())
for i in range(T):
	(N, K, V) = list(map(int, input().split()))
	A = list(map(int, input().split()))[:N]
	S = (N + K) * V
	B = S - sum(A)
	if B > 0:
		if B % K == 0:
			print(B // K)
		else:
			print(-1)
	else:
		print(-1)


for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	a = v * (k + n)
	if sum(l) >= a:
		print(-1)
	elif (a - sum(l)) % k != 0:
		print(-1)
	else:
		print((a - sum(l)) // k)


n = int(input())
for i in range(n):
	(a, v, k) = map(int, input().split())
	l = list(map(int, input().split()))
	g = sum(l)
	j = (a + v) * k
	m = j - g
	if m > 0 and m % v == 0:
		print(m // v)
	else:
		print('-1')


for _ in range(int(input())):
	(N, K, V) = map(int, input().split())
	N_list = list(map(int, input().split()))
	total = V * (N + K)
	K_sum = total - sum(N_list)
	K_value = K_sum // K
	print(-1 if K_sum % K or K_value <= 0 else K_value)


T = int(input())
for i in range(T):
	qns = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = sum(arr)
	ans = (qns[0] + qns[1]) * qns[2] - s
	if ans > 0 and ans % qns[1] == 0:
		print(int(ans / qns[1]))
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	z = list(map(int, input().split()))
	if (v * (n + k) - sum(z)) % k == 0 and v * (n + k) - sum(z) > 0:
		x = (v * (n + k) - sum(z)) // k
		print(x)
	else:
		print('-1')


t = int(input())
for _ in range(t):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	x = v * (n + k) - sum(l)
	if x <= 0:
		print(-1)
	elif x % k == 0:
		print(x // k)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	arr = list(map(int, input().split()))
	avg = 0
	for i in arr:
		avg += i
	tot = v * (n + k)
	rem = tot - avg
	if rem % k == 0 and rem > 0:
		print(rem // k)
	else:
		print(-1)


tst = int(input())
for i in range(tst):
	(n, k, v) = map(int, input().split())
	l = sum(map(int, input().split()))
	e = v - (l - n * v) / k
	if int(e) == e and e > 0:
		print(int(e))
	else:
		print('-1')


t = int(input())
for _ in range(t):
	(n, k, v) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	count = sum(l)
	total = v * (n + k)
	num = total - count
	if total <= count:
		print('-1')
	elif num % k != 0:
		print('-1')
	else:
		print(int(num / k))


t = int(input())
R = lambda : map(int, input().split())
for i in range(t):
	(N, K, V) = R()
	A = list(R())
	sumTotal = V * (N + K)
	for i in range(N):
		sumTotal -= A[i]
	if sumTotal % K != 0 or sumTotal <= 0:
		print(-1)
	else:
		print(sumTotal // K)


for i in range(int(input())):
	(n, k, v) = list(map(int, input().split()))
	no = list(map(int, input().split()))
	if (n + k) * v > sum(no) and ((n + k) * v - sum(no)) % k == 0:
		print(((n + k) * v - sum(no)) // k)
	else:
		print(-1)


trials = int(input())
for i in range(trials):
	(remaining, removed, mean) = [int(x) for x in input().split()]
	remain_sum = sum((int(x) for x in input().split()))
	original_total = mean * (remaining + removed)
	value_removed = original_total - remain_sum
	if not value_removed % removed and value_removed > 0:
		print(value_removed // removed)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	b = sum(a)
	c = v * (n + k) - b
	y = c // k
	if c > 0 and c % k == 0:
		print(y)
	else:
		print('-1')


t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	total = (n + k) * v
	curr = sum(a)
	res = (total - curr) / k
	if res % 1 != 0 or res <= 0:
		print(-1)
	else:
		print(int(res))


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	p = sum(l)
	y = v * (n + k)
	r = y - p
	if r % k == 0 and r > 0:
		print(r // k)
	else:
		print(-1)


for t in range(int(input())):
	(n, k, v) = map(int, input().split())
	L = list(map(int, input().split()))
	Y = (n + k) * v - sum(L)
	if Y > 0 and Y % k == 0:
		print(Y // k)
	else:
		print('-1')


T = int(input())
for i in range(T):
	values = input().split()
	N = int(values[0])
	K = int(values[1])
	V = int(values[2])
	n_values = list(map(int, input().split()))
	difference = V * (N + K) - sum(n_values)
	if difference % K == 0 and difference / K > 0:
		print(int(difference / K))
	else:
		print(-1)


for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	ts = v * (n + k)
	rs = ts - s
	if rs % k == 0 and rs // k > 0:
		print(rs // k)
	else:
		print(-1)


for _ in range(int(input())):
	(N, K, v) = list(map(int, input().split()))
	a = list(map(int, input().split()))[:N]
	s = (N + K) * v
	b = s - sum(a)
	if b > 0:
		if b % K == 0:
			print(b // K)
		else:
			print(-1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(N, K, V) = map(int, input().split())
	l = list(map(int, input().split()))
	sum1 = (N + K) * V - sum(l)
	avg = sum1 / K
	avg1 = sum1 // K
	if avg == avg1 and avg >= 1:
		print(avg1)
	else:
		print('-1')


t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	l1 = list(map(int, input().split()))
	if sum(l1) >= (n + k) * v:
		print(-1)
	elif ((n + k) * v - sum(l1)) % k == 0:
		print(((n + k) * v - sum(l1)) // k)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = (n + k) * v - sum(a)
	if sum(a) >= (n + k) * v or s % k != 0:
		print(-1)
	else:
		print(s // k)


for i in range(int(input())):
	(n, k, v) = list(map(int, input().split()))
	gap = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += gap[i]
	ans = ((n + k) * v - s) / k
	if ans > 0 and ans - int(ans) == 0:
		print(int(ans))
	else:
		print('-1')


for i in range(int(input())):
	(N, K, V) = map(int, input().split())
	list1 = []
	list1 = [int(x) for x in input().split()]
	total = (N + K) * V - sum(list1)
	avg = total / K
	average = total // K
	if avg == average and avg >= 1:
		print(average)
	else:
		print('-1')


t = int(input())
for k in range(t):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	b = (v * (n + k) - s) / k
	if b == int(b) and b >= 1:
		print(int(b))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, k, v) = map(int, input().split())
	arr = list(map(int, input().split()))
	r = v * (n + k) - sum(arr)
	x = r // k
	if r > 0 and r % k == 0:
		print(x)
	else:
		print(-1)


for z in range(int(input())):
	(n, k, v) = map(int, input().split())
	arr = list(map(int, input().split()))
	avg1 = sum(arr) / (n + k)
	integer = 1
	avg2 = 0
	chk = 0
	while avg1 + avg2 <= v:
		avg2 = k * integer / (n + k)
		if avg1 + avg2 == v:
			print(integer)
			chk = 1
			break
		integer += 1
	if chk == 0:
		print(-1)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	d = (a + b) * c - sum(l)
	if d % b == 0 and d > 0:
		print(d // b)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = v * (n + k)
	total -= sum(arr)
	if total % k == 0 and total > 0:
		print(total // k)
	else:
		print(-1)


def my(n, k, v, l):
	if (v * (n + k) - sum(l)) / k > 0:
		if int((v * (n + k) - sum(l)) / k) == (v * (n + k) - sum(l)) / k:
			return int((v * (n + k) - sum(l)) / k)
		else:
			return -1
	else:
		return -1
t = int(input())
for i in range(t):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	print(my(n, k, v, l))


n = int(input())
for i in range(n):
	(n, k, v) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = (v * (n + k) - sum(arr)) / k
	y = x * k // k
	if x <= 0 or x != y:
		print('-1')
	else:
		print(int(x))


T = int(input())
while T > 0:
	(N, K, V) = map(int, input().split())
	A = list(map(int, input().split()))
	if V * (N + K) - sum(A) > 0:
		if (V * (N + K) - sum(A)) % K == 0:
			print((V * (N + K) - sum(A)) // K)
		else:
			print('-1')
	else:
		print('-1')
	T = T - 1


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	li = list(map(int, input().split()))
	sum_n = sum(li)
	ans1 = v * (n + k) - sum_n
	if ans1 > 0 and ans1 % k == 0:
		print(ans1 // k)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	for i in a:
		sum += i
	res = (v * (n + k) - sum) / k
	if res > 0 and (v * (n + k) - sum) % k == 0:
		print(int(res))
	else:
		print('-1')


tests = int(input())
for i in range(tests):
	(N, K, V) = list(map(int, input().split()))
	pos_int = list(map(int, input().split()))
	total = V * (N + K)
	for item in pos_int:
		total = total - item
	if total % K == 0 and total > 0:
		print(total // K)
	else:
		print(-1)


for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	l = list(map(int, input().split()))
	p = n + k
	s = sum(l)
	w = p * v
	ans = w - s
	if ans > 0 and ans % k == 0:
		print(ans // k)
	else:
		print('-1')


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	sum_a = sum(a)
	sum_v = v * (n + k)
	sum_deleted = sum_v - sum_a
	deleted_value = sum_deleted // k
	if sum_deleted % k == 0 and deleted_value > 0:
		print(deleted_value)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, k, v) = list(map(int, input().split()))
	arr = list(map(int, input().split()))[:n]
	sums = sum(arr)
	l = v * (n + k)
	a = (l - sums) // k
	if a <= 0:
		print(-1)
	elif (l - sums) % k != 0:
		print(-1)
	else:
		print(a)


cases = int(input())
for case in range(cases):
	(length_remain, length_deleted, average) = map(int, input().split())
	number_remain = map(int, input().split())
	sum_number_remain = sum(number_remain)
	length = length_remain + length_deleted
	total = average * length
	sum_number_deleted = total - sum_number_remain
	number_deleted = sum_number_deleted / length_deleted
	if isinstance(number_deleted, float) and number_deleted.is_integer() and (number_deleted > 0):
		print(int(number_deleted))
	else:
		print('-1')


T = int(input())
while T > 0:
	T -= 1
	(N, K, V) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	ans = V * (K + N) - sum(A)
	if ans <= 0:
		print(-1)
	elif ans % K != 0:
		print(-1)
	else:
		print(int(ans / K))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	l1 = list(map(int, input().split()))
	d = (a + b) * c - sum(l1)
	if d <= 0 or d % b != 0:
		print('-1')
	else:
		print(d // b)


for i in range(int(input())):
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = (a + n) * b - int(sum(arr))
	if c > 0 and c % a == 0:
		print(c // a)
	else:
		print('-1')


t = int(input())
for i in range(t):
	(N, K, V) = map(int, input().split())
	A = list(map(int, input().split()))
	if V * (N + K) - sum(A) > 0:
		if (V * (N + K) - sum(A)) % K == 0:
			print((V * (N + K) - sum(A)) // K)
		else:
			print('-1')
	else:
		print('-1')


import math
for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	nums = list(map(int, input().split()))
	x = v * (n + k)
	y = x - sum(nums)
	z = y / k
	if z == math.floor(z) and z > 0:
		print(int(z))
	else:
		print(-1)


try:
	t = int(input())
	for i in range(t):
		(n, k, v) = list(map(int, input().split()))
		a = [int(x) for x in input().split()]
		p = 0
		A = sum(a)
		p = int((v * (n + k) - A) / k)
		if p > 0 and (v * (n + k) - A) % k == 0:
			print(p)
		else:
			print('-1')
except EOFError:
	pass


for T in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = [int(i) for i in input().split()]
	x = v * (n + k) - sum(a)
	if x % k == 0 and x > 0:
		print(x // k)
		print()
	else:
		print(-1)
		print()


def __starting_point():
	t = int(input())
	for _ in range(t):
		(n, k, v) = map(int, input().split())
		li = list(map(int, input().split()))
		sumn = 0
		for i in range(n):
			sumn = sumn + li[i]
		sumk = v * (n + k) - sumn
		e = int(sumk / k)
		r = sumk % k
		if e <= 0:
			print(-1)
		elif r != 0:
			print(-1)
		else:
			print(e)
__starting_point()


MISTAKE = -1
T = input()
for _ in range(int(T)):
	(N, K, V) = [int(i) for i in input().split(' ')]
	n_integers = [int(i) for i in input().split(' ')]
	res = (V * (N + K) - sum(n_integers)) / K
	ires = int(res)
	print(ires if res == ires and ires > 0 else MISTAKE)


for _ in range(int(input())):
	(n, k, v) = map(int, input().split())
	A = list(map(int, input().split()))
	S1 = sum(A)
	S = (n + k) * v
	c = S - S1
	if c % k == 0 and c > 0:
		print(c // k)
	else:
		print(-1)


tc = int(input())
for _ in range(tc):
	val = map(int, input().split(' '))
	(n, k, v) = val
	liss = tuple(map(int, input().split()))
	liss_sum = sum(liss)
	result = v * (n + k) - liss_sum
	if result <= 0:
		print(-1)
	elif result % k == 0:
		print(result // k)
	else:
		print(-1)


total = 0
for i in range(int(input())):
	(n, k, v) = map(int, input().split())
	a = list(map(int, input().split()))
	avgn = (n + k) * v - int(sum(a))
	if avgn > 0 and avgn % k == 0:
		print(avgn // k)
	else:
		print(-1)