Read problems statements in Mandarin Chinese  and Russian. 
Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem: given array of N integers A and a number K. During a turn the maximal value over all A_{i} is chosen, let's call it MAX. Then A_{i} = 
MAX - A_{i} is done for every 1 ≤ i ≤ N. Help Roman to find out how will the array look like after K turns.

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

The numbers N and K are given in the first line of an input. Then N integers are given in the second line which denote the array A. 

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

Output N numbers on a single line. It should be the array A after K turns.

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

$1 ≤ N ≤ 10^{5}$
$0 ≤ K ≤ 10^{9}$

$A_{i} does not exceed 2 * 10^{9} by it's absolute value.$

----- Sample Input 1 ------ 
4 1
5 -1 7 0
----- Sample Output 1 ------ 
2 8 0 7

Source: codechef | Difficulty: MEDIUM
Tags: Constructive algorithms

Data structures

Mathematics

Ad-hoc


Solutions:
(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
if k != 0:
	if k % 2 != 1:
		l = min(lst)
		lst = [-l + lst[j] for j in range(n)]
	else:
		r = max(lst)
		lst = [r - lst[j] for j in range(n)]
for i in range(n):
	print(lst[i], end=' ')


(n, k) = map(int, input().split())
lst = [int(x) for x in input().split()]
m = max(lst)
n = min(lst)
n = m - n
lst1 = list()
lst2 = list()
for i in lst:
	lst1.append(m - i)
	lst2.append(n - (m - i))
if k % 2 != 0:
	print(*lst1, sep=' ')
elif k == 0:
	print(*lst, sep=' ')
else:
	print(*lst2, sep=' ')


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
max_no = max(arr)
odd_arr = []
for i in range(len(arr)):
	odd_arr.append(max_no - arr[i])
even_arr = []
max_no_2 = max(odd_arr)
for i in range(len(arr)):
	even_arr.append(max_no_2 - odd_arr[i])
if k == 0:
	for i in range(len(arr)):
		print(arr[i], end=' ')
elif k & 1:
	for i in range(len(odd_arr)):
		print(odd_arr[i], end=' ')
else:
	for i in range(len(even_arr)):
		print(even_arr[i], end=' ')


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


l1 = [(), ()]
(N, K) = map(int, input().strip().split())
l = list(map(int, input().split()))
if K == 0:
	print(*l)
else:
	for j in range(2):
		maximum = max(l)
		for k in range(N):
			l[k] = maximum - l[k]
		l1[j] = [i for i in l]
	print(*l1[1 - K % 2])


(m, n) = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
l1 = [m - i for i in a]
m1 = max(l1)
l2 = [m1 - i for i in l1]
if n < 1:
	print(*a)
elif n % 2 == 0:
	print(*l2)
elif n % 2 != 0:
	print(*l1)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
if b == 0:
	print(*l)
elif b % 2 == 0:
	m = max(l)
	for i in range(a):
		l[i] = m - l[i]
	m = max(l)
	for i in range(a):
		l[i] = m - l[i]
	print(*l)
else:
	m = max(l)
	for i in range(a):
		l[i] = m - l[i]
	print(*l)


(n, k) = map(int, input().split())
l = list(map(int, input().strip().split()))[:n]
(b, c) = ([0] * n, [0] * n)
maxe = max(l)
for i in range(n):
	b[i] = maxe - l[i]
maxe = max(b)
for j in range(n):
	c[j] = maxe - b[j]
if k == 0:
	print(*l)
elif k % 2 == 0:
	print(*c)
else:
	print(*b)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
c = [0] * n
m = max(a)
for i in range(n):
	b[i] = m - a[i]
m = max(b)
for i in range(n):
	c[i] = m - b[i]
if k == 0:
	print(*a)
elif k % 2 == 0:
	print(*c)
else:
	print(*b)


(N, K) = map(int, input('').split())
a = list(map(int, input('').split()))[:N]
max1 = max(a)
b = []
c = []
for i in a:
	b.append(max1 - i)
max2 = max(b)
if K == 0:
	for i in a:
		print(i, end=' ')
elif K % 2 == 1:
	for i in b:
		print(i, end=' ')
else:
	for i in b:
		c.append(max2 - i)
	for i in c:
		print(i, end=' ')


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
if K % 2:
	K = 1
elif K == 0:
	pass
else:
	K = 2
for i in range(K):
	s = max(A)
	A1 = [s - i for i in A]
	A = A1
print(*A)


l = [int(i) for i in input().split()]
n = l[0]
k = l[1]
arr = [int(i) for i in input().split()]
mx = max(arr)
if k == 0:
	print(*arr)
elif k & 1 == 1:
	for i in range(len(arr)):
		arr[i] = mx - arr[i]
	print(*arr)
else:
	for i in range(len(arr)):
		arr[i] = mx - arr[i]
	mx = max(arr)
	for i in range(n):
		arr[i] = mx - arr[i]
	print(*arr)


import sys
import numpy as np
[n, k] = list(map(int, sys.stdin.readline().strip().split()))
a = np.array(list(map(int, sys.stdin.readline().strip().split())))
if k == 0:
	pass
elif k % 2 == 1:
	a = max(a) - a
elif k % 2 == 0:
	a = max(a) - a
	a = max(a) - a
for i in a:
	print(i, end=' ')


l = input().split()
n = int(l[0])
k = int(l[1])
a = list(map(int, input().split()))
if k <= 2:
	for i in range(k):
		m = max(a)
		for j in range(n):
			a[j] = m - a[j]
	for i in range(n):
		print(a[i], end=' ')
	print()
elif k % 2 == 0:
	for i in range(2):
		m = max(a)
		for j in range(n):
			a[j] = m - a[j]
	for i in range(n):
		print(a[i], end=' ')
	print()
else:
	for i in range(1):
		m = max(a)
		for j in range(n):
			a[j] = m - a[j]
	for i in range(n):
		print(a[i], end=' ')
	print()


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
q = max(c)
l = [q - i for i in c]
if b == 0:
	print(*c)
elif b % 2 == 0:
	q = max(l)
	l = [q - i for i in l]
	print(*l)
else:
	print(*l)


import numpy as np
(n, k) = map(int, input().split())
arr = np.array(list(map(int, input().split())))
if k == 0:
	print(*arr)
elif k % 2 == 1:
	arr = max(arr) - arr
	print(*arr)
else:
	arr = max(arr) - arr
	arr = max(arr) - arr
	print(*arr)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
if K == 0:
	print(*A)
elif K % 2 == 1:
	m = max(A)
	for i in range(len(A)):
		A[i] = m - A[i]
	print(*A)
else:
	m = max(A)
	for i in range(len(A)):
		A[i] = m - A[i]
	m = max(A)
	for i in range(len(A)):
		A[i] = m - A[i]
	print(*A)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
o = [mx - i for i in a]
mx = max(o)
e = [mx - i for i in o]
if k == 0:
	print(*a)
elif k % 2:
	print(*o)
else:
	print(*e)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
if k == 0:
	print(*a)
else:
	if k % 2 == 1:
		k = 1
	else:
		k = 2
	for i in range(k):
		m = max(a)
		for j in range(len(a)):
			a[j] = m - a[j]
	print(*a)


import numpy as np
(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
if K == 0:
	print(*A)
elif K % 2 == 1:
	A = max(A) - A
	print(*A)
else:
	A = max(A) - A
	A = max(A) - A
	print(*A)


import sys
import numpy as np
[N, K] = list(map(int, sys.stdin.readline().strip().split()))
A = np.array(list(map(int, sys.stdin.readline().strip().split())))
if K == 0:
	pass
elif K % 2 == 1:
	A = max(A) - A
elif K % 2 == 0:
	A = max(A) - A
	A = max(A) - A
answer = ' '.join(list(map(str, A)))
sys.stdout.write(answer + '\n')


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
if b == 0:
	pass
elif b % 2 != 0:
	d = max(l)
	l = [d - x for x in l]
else:
	for i in range(2):
		d = max(l)
		l = [d - x for x in l]
for i in l:
	print(i, end=' ')
print()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 0:
	print(*a)
else:
	maxm1 = 0
	for i in range(n):
		if a[i] > maxm1:
			maxm1 = a[i]
	for i in range(n):
		a[i] = maxm1 - a[i]
	if k % 2 != 0:
		print(*a)
	else:
		maxm2 = 0
		for i in range(n):
			if a[i] > maxm2:
				maxm2 = a[i]
		for i in range(n):
			a[i] = maxm2 - a[i]
		print(*a)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
c = 1
if k == 0:
	k = 0
elif k % 2:
	k = 1
else:
	k = 2
while c <= k:
	if k == 0:
		break
	m = max(l)
	for i in range(n):
		l[i] = m - l[i]
	c += 1
print(*l)


(N, K) = tuple(map(int, input().split()))
A = list(map(int, input().split()))
if K == 0:
	print(' '.join((str(i) for i in A)))
elif K % 2 == 0:
	temp = min(A)
	print(' '.join((str(i - temp) for i in A)))
else:
	temp = max(A)
	print(' '.join((str(temp - i) for i in A)))


(N, K) = map(int, input().split())
l = [int(i) for i in input().split()]
if K == 0:
	print(*l, sep=' ')
else:
	if K % 2 == 0:
		K = 2
	else:
		K = 1
	for i in range(K):
		maxEle = max(l)
		for i in range(N):
			l[i] = maxEle - l[i]
	print(*l, sep=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
maxi = max(a)
mini = min(a)
seven = maxi
eight = maxi - mini
for i in a:
	if k == 0:
		print(i, end=' ')
	elif k % 2 == 1:
		print(seven - i, end=' ')
	else:
		print(eight - seven + i, end=' ')


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if k == 0:
	pass
else:
	m = max(a)
	for i in range(n):
		a[i] = m - a[i]
	if (k - 1) % 2 == 1:
		m2 = max(a)
		for i in range(n):
			a[i] = m2 - a[i]
for i in a:
	print(i, end=' ')


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
MAX = max(li)
odd = [MAX - i for i in li]
MAXODD = max(odd)
even = [MAXODD - i for i in odd]
if k == 0:
	print(*li)
elif k % 2 == 0:
	print(*even)
else:
	print(*odd)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if k > 0:
	maximum = max(arr)
	for j in range(n):
		arr[j] = maximum - arr[j]
	k -= 1
if k & 1:
	maximum = max(arr)
	for j in range(n):
		arr[j] = maximum - arr[j]
print(*arr)


l = list(map(int, input().split()))
(n, k) = (l[0], l[1])
l = list(map(int, input().split()))
if k == 0:
	print(*l)
else:
	maxi = max(l)
	mini = min(l)
	for i in range(n):
		l[i] = maxi - l[i]
	if k % 2:
		print(*l)
	else:
		maxi = maxi - mini
		for i in range(n):
			l[i] = maxi - l[i]
		print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 0:
	print(*a)
elif k % 2 != 0:
	m = max(a)
	for j in range(n):
		a[j] = m - a[j]
	print(*a)
else:
	m = max(a)
	for j in range(n):
		a[j] = m - a[j]
	m = max(a)
	for j in range(n):
		a[j] = m - a[j]
	print(*a)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if k == 0:
	pass
elif k % 2 == 0:
	k = 2
else:
	k = 1
for i in range(k):
	max_ = max(arr)
	for i in range(n):
		arr[i] = max_ - arr[i]
print(*arr)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
re = max(l)
l1 = [re - i for i in l]
hi = max(l1)
l2 = [hi - i for i in l1]
if m <= 0:
	print(*l)
elif m % 2 == 1:
	print(*l1)
elif m % 2 == 0:
	print(*l2)


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
m1 = max(l)
odd = [m1 - i for i in l]
m2 = max(odd)
even = [m2 - i for i in odd]
if y == 0:
	print(*l)
elif y % 2 == 0:
	print(*even)
else:
	print(*odd)


import sys
(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
s = ''
maxi = ~sys.maxsize
if k == 0:
	for i in range(n):
		print(list1[i], end=' ')
else:
	if k % 2 == 0:
		k = 2
	else:
		k = 1
	while k > 0:
		s = ''
		for i in range(n):
			maxi = max(maxi, list1[i])
		for i in range(n):
			list1[i] = maxi - list1[i]
		k = k - 1
	for i in range(n):
		print(list1[i], end=' ')


def print_arr(arr):
	for i in arr:
		print(i, end=' ')
	print()
(n, k) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
if k == 0:
	print_arr(arr)
elif k % 2 != 0:
	m = max(arr)
	for i in range(n):
		arr[i] = m - arr[i]
	print_arr(arr)
else:
	for k in range(2):
		m = max(arr)
		for i in range(n):
			arr[i] = m - arr[i]
	print_arr(arr)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = max(a)
y = min(a)
p = []
for i in range(n):
	p.append(l - a[i])
z = []
for i in range(n):
	z.append(l - y - p[i])
if k == 0:
	print(*a)
elif k % 2 != 0:
	print(*p)
else:
	print(*z)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))[:a]
d = []
e = []
x = max(c)
d = [x - c[i] for i in range(a)]
y = max(d)
e = [y - d[i] for i in range(a)]
if b <= 0:
	print(*c)
elif b % 2 == 0:
	print(*e)
else:
	print(*d)


(c, y) = map(int, input().split())
x = list(map(int, input().split()))
if y == 0:
	y = 0
else:
	y = 1 if y % 2 else 2
for _ in range(y):
	a = max(x)
	x = [a - i for i in x]
print(*x)


import numpy as np
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr = np.array(arr)
if k == 0:
	pass
elif k % 2 == 0:
	k = 2
else:
	k = 1
for i in range(k):
	max_ = max(arr)
	arr = max_ - arr
print(*arr)


(n, k) = input().split()
n = int(n)
k = int(k)
c = list((int(num) for num in input().strip().split()))[:n]
if k == 0:
	print(*c)
elif k % 2 != 0:
	f = max(c)
	for i in range(n):
		c[i] = f - c[i]
	print(*c)
elif k % 2 == 0:
	f = max(c)
	for i in range(n):
		c[i] = f - c[i]
	f = max(c)
	for i in range(n):
		c[i] = f - c[i]
	print(*c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 0:
	print(*a)
else:
	if k % 2 == 0:
		k = 2
	else:
		k = 1
	for _ in range(k):
		maxi = max(a)
		for i in range(n):
			a[i] = maxi - a[i]
	print(*a)


(T, n) = input().split()
T = int(T)
n = int(n)
doit = False
a = input().split()
for j in range(0, T):
	a[j] = int(a[j])
	if a[j] < 0:
		doit = True
if doit and n > 0:
	b = list(a)
	b.sort()
	for j in range(0, T):
		a[j] = b[-1] - a[j]
	n += 1
for i in range(0, n % 2):
	b = list(a)
	b.sort()
	for j in range(0, T):
		a[j] = b[-1] - a[j]
s = ''
for j in range(0, T):
	s += str(a[j]) + ' '
print(s)


(a, k) = map(int, input().split())
n = list(map(int, input().split()))
mx = max(n)
res = list(map(lambda x: mx - x, n))
if k == 0:
	print(*n)
elif k & 1:
	print(*res)
else:
	mx = max(res)
	print(*list(map(lambda x: mx - x, res)))


def getValues(ar, n):
	ma = -100000000000.0
	for i in ar:
		ma = max(ma, i)
	for i in range(n):
		ar[i] = ma - ar[i]
(n, k) = list(map(int, input().split()))
ar = list(map(int, input().split()))
if k != 0:
	getValues(ar, n)
	if k % 2 == 0:
		getValues(ar, n)
print(*ar)


(n, l) = map(int, input().split())
li = list(map(int, input().split()))
if l == 0:
	k = 0
elif l % 2 == 0:
	k = 2
else:
	k = 1
for i in range(k):
	m = max(li)
	li = list(map(lambda x: m - x, li))
for i in li:
	print(i, end=' ')


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
a = max(l)
if m == 0:
	print(*l)
elif m & 1 == 1:
	for i in range(len(l)):
		print(a - l[i], end=' ')
else:
	for i in range(len(l)):
		l[i] = a - l[i]
	a = max(l)
	for i in range(len(l)):
		print(a - l[i], end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 0:
	k = 0
elif k % 2 == 1:
	k = 1
else:
	k = 2
for i in range(k):
	max1 = max(a)
	for i in range(len(a)):
		a[i] = max1 - a[i]
for i in range(len(a)):
	print(a[i], end=' ')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k == 0:
	print(*l)
else:
	max1 = max(l)
	for i in range(n):
		l[i] = max1 - l[i]
	if k & 1 == 1:
		print(*l)
	else:
		Max = max(l)
		for y in range(n):
			l[y] = Max - l[y]
		print(*l)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 0:
	pass
elif k % 2 == 0:
	k = 2
elif k % 2 != 0:
	k = 1
for j in range(k):
	m = max(a)
	for i in range(n):
		a[i] = m - a[i]
print(*a)


(n, k) = [int(d) for d in input().split()]
a = [int(d) for d in input().split()]
if k == 0:
	print(*a)
else:
	if k % 2 == 1:
		k = 1
	else:
		k = 2
	for i in range(k):
		curr_max = max(a)
		for j in range(len(a)):
			a[j] = curr_max - a[j]
	print(*a)


mod = 2 * 10 ** 9
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if k > 0:
	if k % 2 == 0:
		k = 2
	else:
		k = 1
	for pos in range(k):
		maximum = max(arr)
		for i in range(n):
			arr[i] = maximum - arr[i]
for num in arr:
	print(num, end=' ')
print()


import numpy as np
(n, k) = map(int, input().split())
arr = np.array([int(j) for j in input().split()])
if k == 0:
	print(*arr)
elif k % 2 == 1:
	arr = max(arr) - arr
	print(*arr)
elif k % 2 == 0:
	arr = max(arr) - arr
	arr = max(arr) - arr
	print(*arr)


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
if K == 0:
	print(*a)
else:
	Max = max(a)
	for x in range(N):
		a[x] = Max - a[x]
	if K & 1:
		print(*a)
	else:
		Max = max(a)
		for y in range(N):
			a[y] = Max - a[y]
		print(*a)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k == 0:
	print(*l)
elif k % 2 == 0:
	m = max(l)
	for i in range(n):
		l[i] = m - l[i]
	m = max(l)
	for i in range(n):
		l[i] = m - l[i]
	print(*l)
else:
	m = max(l)
	for i in range(n):
		l[i] = m - l[i]
	print(*l)


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
a = max(arr)
arr1 = []
for i in range(0, n, 1):
	arr1.append(a - arr[i])
b = max(arr1)
arr2 = []
for i in range(0, n, 1):
	arr2.append(b - arr1[i])
if k == 0:
	print(*arr)
elif k % 2 == 1:
	print(*arr1)
else:
	print(*arr2)


def roman(a, n, k):
	if k == 0:
		return a
	mx = max(a)
	for i in range(n):
		a[i] = mx - a[i]
	if k % 2 != 0:
		return a
	mx = max(a)
	for i in range(n):
		a[i] = mx - a[i]
	return a
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
print(*roman(a, n, k))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
odd = [mx - i for i in a]
mx1 = max(odd)
even = [mx1 - i for i in odd]
if k == 0:
	print(*a)
elif k % 2:
	print(*odd)
else:
	print(*even)