Chef has an array A of length N.

Let f(i) denote the sum A_{1} + A_{2} + \dots + A_{i} \, and let g(i) denote the sum A_{i} + A_{i + 1} + \dots + A_{N}. 

Chef creates another array B of length N such that B_{i} = f(i) + g(i) for all 1 ≤ i ≤ N.

Now, Chef has lost the original array A and needs your help to recover it, given array B. It is guaranteed that Chef has obtained the array B from a valid array A.

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

- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the size of the array A.
- The second line of each test case contains N space-separated integers B_{1}, B_{2}, \dots, B_{N} denoting the array B.

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

For each testcase, output N space separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. 

Note that 1 ≤ A_{i} ≤ 10^{5} must hold for all 1 ≤ i ≤ N and it is guaranteed that a valid array A that meets these constraints exists.

If there are multiple answers, output any.

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

$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ B_{i} ≤ 2 \cdot 10^{10}$
- Th sum of $N$ over all test cases does not exceed $10^{5}$.
$1 ≤ A_{i} ≤ 10^{5}$
- It is guaranteed that a valid array $A$ always exists.

----- Sample Input 1 ------ 
4
1
6
3
7 8 9
4
13 15 13 14
2
25 20

----- Sample Output 1 ------ 
3 
1 2 3 
2 4 2 3 
10 5 

----- explanation 1 ------ 
Test case 1: For $A = [3]$, $B = [6]$. $B_{1} = f(1) + g(1) = 3 + 3 = 6$.

Test case 2: For $A = [1, 2, 3]$, $B = [7, 8, 9]$.
- $B_{1} = f(1) + g(1) = \underline{1} + \underline{1 + 2 + 3} = 7$
- $B_{2} = f(2) + g(2) = \underline{1 + 2} + \underline{2 + 3} = 8$
- $B_{3} = f(3) + g(3) = \underline{1 + 2 + 3} + \underline{3} = 9$

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	integers = list(map(int, input().split()))
	const = sum(integers) // (n + 1)
	for i in range(n):
		integers[i] -= const
	print(*integers)


for T in range(int(input())):
	N = int(input())
	B = [int(i) for i in input().split()]
	m = sum(B) // (N + 1)
	A = [i - m for i in B]
	print(*A, sep=' ')


T = int(input())
for i in range(T):
	N = int(input())
	B = list(map(int, input().split()))
	sum1 = sum(B)
	alpha = sum1 // (len(B) + 1)
	for i in B:
		print(i - alpha, end=' ')
	print('\n')


from array import *
t = int(input())
for i in range(t):
	n = int(input())
	b_arr = [int(i) for i in input().split()]
	z = 0
	for i in range(n):
		z = z + b_arr[i]
	y = int(z / (n + 1))
	arr = array('i', (a - y for a in b_arr))
	for i in range(n):
		print(arr[i], end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	sumB = sum(array)
	sumA = sumB // (n + 1)
	for j in array:
		print(j - sumA, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l) // (n + 1)
	for i in range(n):
		print(l[i] - s, end=' ')
	print()


n = int(input())
while n > 0:
	n = n - 1
	a = int(input())
	b = list(map(int, input().split()))
	s = int(sum(b) / (a + 1))
	for i in range(a):
		print(b[i] - s, end=' ')
	print()


t = int(input())
for tc in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	c = []
	s = sum(b)
	a = s // (n + 1)
	for j in range(0, n):
		c.append(b[j] - a)
	print(*c)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	sum_a = s // (n + 1)
	for i in range(0, n):
		print(l[i] - sum_a, end=' ')
	print(' ')


for i in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	sum_a = sum(b) / (n + 1)
	a = []
	for i in range(n):
		a.append(b[i] - sum_a)
	for i in a:
		print(int(i), end=' ')
	print()


import random
T = int(input())
for i in range(T):
	N = int(input())
	B = list(map(int, input().split()))
	S = sum(B) / (N + 1)
	A = []
	for j in range(N):
		A.append(B[j] - S)
	for j in A:
		print(int(j), end=' ')
	print()


for tc in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	sumb = sum(b)
	suma = int(sumb / (n + 1))
	a = [i - suma for i in b]
	print(*a)


for _ in range(int(input())):
	N = int(input())
	B = list(map(int, input().split()))
	sumB = int(sum(B) / (N + 1))
	A = []
	for i in range(N):
		A.append(str(B[i] - sumB))
	print(' '.join(A))


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	sum_b = sum(b) / (a + 1)
	arr_a = [str(abs(int(b[i] - sum_b))) for i in range(a)]
	print(' '.join(arr_a))


for i in range(int(input())):
	size = int(input())
	arr_b = list(map(int, input().split()))
	sum_a = sum(arr_b) / (size + 1)
	arr_a = [str(abs(int(arr_b[i] - sum_a))) for i in range(size)]
	print(' '.join(arr_a))


T = int(input(''))
for i in range(0, T, 1):
	N = int(input(''))
	B = input('')
	B = list(map(int, B.split()))
	tot = 0
	for i in B:
		tot = tot + i
	tot = tot / (N + 1)
	newlist = []
	for i in range(0, N, 1):
		newlist.append(int(B[i] - tot))
	print(*newlist, sep=' ')


for _ in range(int(input())):
	n = int(input())
	b = [int(x) for x in input().split()]
	sum_a = sum(b) // (n + 1)
	a = []
	for i in b:
		a.append(i - sum_a)
	print(*a)


T = int(input())
for _ in range(T):
	n = int(input())
	B = list(map(int, input().split()))
	su = sum(B) // (n + 1)
	print(*[i - su for i in B])


for i in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	su = sum(b) // (n + 1)
	print(*[e - su for e in b])


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	sum_b = sum(b)
	a = []
	sum_a = sum_b // (n + 1)
	for i in range(len(b)):
		a.append(b[i] - sum_a)
	print(*a)


for _ in range(int(input())):
	N = int(input())
	B = list(map(int, input().split()))
	total = sum(B) // (N + 1)
	A = [b - total for b in B]
	print(*A)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split(' ')))[:n]
	Asum = sum(arr) // (n + 1)
	Bsum = 0
	for i in arr:
		print(i - Asum, end=' ')
	print()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split(' ')))
	i = 0
	c = 0
	k = 0
	a = []
	for i in range(n):
		c = c + b[i]
	p = c // (n + 1)
	for i in range(n):
		k = b[i] - p
		a.append(k)
	print(*a)


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	s = sum(b) // (n + 1)
	a = [str(b[x] - s) for x in range(n)]
	print(' '.join(a))


for t in range(int(input())):
	N = int(input())
	B = list(map(int, input().split()))
	sum_B = sum(B)
	modifier = sum(B) / (N + 1)
	A = []
	for x in range(N):
		A.append(B[x] - modifier)
	A = map(int, A)
	print(*A, sep=' ')


t = int(input())
for i in range(t):
	n = int(input())
	list_a = list(map(int, input().split()))
	x = sum(list_a) / (n + 1)
	for each in list_a:
		print(abs(int(x - each)), end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	d = s // (n + 1)
	for f in a:
		print(f - d, end=' ')
	print()


t = int(input())
for i in range(t):
	length = int(input())
	l = list(map(int, input().split()))
	B_sum = sum(l)
	A_sum = B_sum // (length + 1)
	for i in range(length):
		print(l[i] - A_sum, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = sum(a) // (n + 1)
	for i in a:
		print(i - c, end=' ')
	print()


T = int(input())
for i in range(0, T, 1):
	n = int(input())
	a = list(map(int, input().split()))
	c = sum(a) // (n + 1)
	for f in a:
		print(f - c, end=' ')
	print()


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	c = sum(a) // (n + 1)
	for i in a:
		print(i - c, end=' ')
	print()
	t = t - 1


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	x = sum(l) // (a + 1)
	for i in l:
		print(i - x, end=' ')
	print()


T = int(input())
for t in range(T):
	N = int(input())
	B = list((int(i) for i in input().split()))
	sumB = sum((b for b in B))
	sumA = int(sumB / (N + 1))
	A = [int(b - sumA) for b in B]
	print(*A)


t = int(input())
for v in range(0, t, 1):
	n = int(input())
	b = input()
	blist = b.split(' ')
	blist2 = list(map(int, blist))
	bsum = 0
	for w in blist2:
		bsum += int(w)
	s = bsum / (n + 1)
	a = [int(v - s) for v in blist2]
	print(*a)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = sum(l) // (n + 1)
	for i in range(n):
		l[i] -= x
	print(*l)


tests = int(input())
for i in range(tests):
	elen = int(input())
	ele = [int(x) for x in input().split(' ')]
	const = int(sum(ele) / (elen + 1))
	result = [e - const for e in ele]
	print(*result)


cases = int(input())
for case in range(cases):
	a_len = int(input())
	b_array = input().split()
	b_array = [int(i) for i in b_array]
	sum_a_array = int(sum(b_array) / (a_len + 1))
	a_array = [i - sum_a_array for i in b_array]
	print(*a_array)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	x = list(map(int, input().split()))
	for i in range(len(x) - 1):
		l.append(x[i + 1] - x[0])
	a = int((x[0] - sum(l)) / (len(x) + 1))
	z = [a + i for i in l]
	z.insert(0, a)
	for b in z:
		print(b, end=' ')
	print()


m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a) / (n + 1)
	for i in range(n):
		a[i] = a[i] - s
	for i in a:
		print(int(i), end=' ')
	print()


for t in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	m = int(sum(b) / (n + 1))
	a = [i - m for i in b]
	print(*a)


T = int(input())
for i in range(T):
	flag = False
	N = int(input())
	initial = input()
	B = [int(i) for i in initial.split()]
	s = int(sum(B) / (N + 1))
	A = [i - s for i in B]
	print(*A)


for i in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	d = sum(b) // (n + 1)
	a = []
	for j in range(n):
		a.append(abs(d - b[j]))
	for k in a:
		print(k, end=' ')
	print()


T = int(input())
for i in range(T):
	N = int(input())
	B = list(map(int, input().split(' ')))
	temp = sum(B) // (N + 1)
	A = []
	for x in B:
		A.append(x - temp)
	[print(x, end=' ') for x in A]
	print()


t = int(input())
for ni in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	s = sum(l)
	l2 = list()
	for i in range(n):
		l2.append(l[i] - int(s / (n + 1)))
	print(*l2, sep=' ')


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	asum = int(sum(b) / (n + 1))
	a = []
	for j in range(n):
		a.append(b[j] - asum)
	print(*a)


n = int(input())
for _ in range(n):
	length = int(input())
	string = list(map(int, input().split()))
	temp = sum(string) // (length + 1)
	result = ''
	for i in string:
		result = result + str(i - temp) + ' '
	print(result[:-1])


k = int(input())
while k > 0:
	N = int(input())
	a = list()
	p = list(map(int, input().split(' ')))
	s = sum(p)
	s1 = s // (N + 1)
	for i in range(0, N):
		a.append(p[i] - s1)
	for i in a:
		print(str(i), end=' ')
	print()
	k = k - 1


for _ in range(int(input())):
	N = int(input())
	b = list(map(int, input().split()))
	a = []
	bsum = 0
	for i in range(N):
		bsum = bsum + b[i]
	for j in range(N):
		a.append(b[j] - int(bsum / (N + 1)))
	print(*a)


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	orig_sum = sum(b) // (n + 1)
	a = [v - orig_sum for v in b]
	print(*a)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = sum(lis)
	ans //= n + 1
	for i in lis:
		print(abs(ans - i), end=' ')
	print()


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	s = 0
	for j in l:
		s = s + j
	s = s // (a + 1)
	for j in range(len(l)):
		l[j] = l[j] - s
	print(*l)


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	sum = 0
	for x in b:
		sum += x
	sum //= n + 1
	for y in range(n):
		print(b[y] - sum, end=' ')
	print()


for _ in range(int(input())):
	N = int(input())
	B = list(map(int, input().split()))
	m = sum(B) // (N + 1)
	A = []
	A.append(abs(m - B[0]))
	for i in range(1, N):
		A.append(A[i - 1] + (B[i] - B[i - 1]))
	print(' '.join([str(A[i]) for i in range(N)]))


for _ in range(int(input())):
	n = int(input())
	b_arr = list(map(int, input().split()))
	s = sum(b_arr) / (n + 1)
	for i in range(n):
		print(int(b_arr[i] - s), end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))[:n]
	base = sum(b) // (n + 1)
	for item in b:
		print(item - base, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	b_sum = sum(b)
	a_sum = b_sum // (n + 1)
	a = []
	if n > 1:
		for i in b:
			j = i - a_sum
			a.append(j)
	else:
		a.append(b[0] // 2)
	print(' '.join(map(str, a)))


for _ in range(int(input())):
	N = int(input())
	B = list(map(int, input().split()))
	if N == 1:
		print(B[0] // 2)
		continue
	m = sum(B) // (N + 1)
	A = [0] * N
	A[0] = abs(m - B[0])
	for i in range(1, N):
		A[i] = A[i - 1] + (B[i] - B[i - 1])
	print(' '.join([str(A[i]) for i in range(N)]))


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	a = []
	s = int(sum(b) / (n + 1))
	for i in range(n):
		a.append(b[i] - s)
	print(*a, sep=' ')


for i in range(int(input())):
	k = int(input())
	l1 = []
	l = list(map(int, input().split(' ')))
	sum_a = int(sum(l) / (k + 1))
	for i in range(k):
		l1.append(l[i] - sum_a)
	for i in range(k):
		print(l1[i], end=' ')
	print('\n')