Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.

Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on. 

For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5 and the fourth one had 4 balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one.

At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls.

He asks you to help to find the initial arrangement of the balls in the boxes.


-----Input-----

The first line of the input contains two integers n and x (2 ≤ n ≤ 10^5, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a_1, a_2, ..., a_{n}, where integer a_{i} (0 ≤ a_{i} ≤ 10^9, a_{x} ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions. 

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Output-----

Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.


-----Examples-----
Input
4 4
4 3 1 6

Output
3 2 5 4 
Input
5 2
3 2 0 2 7

Output
2 1 4 1 6 
Input
3 3
2 3 1

Output
1 2 3

Difficulty: MEDIUM_HARD

Solutions:
from sys import stdin, setrecursionlimit
import math
from collections import defaultdict, deque
setrecursionlimit(15000)

def transform(arr, ans):
	for i in range(len(arr)):
		arr[i] -= ans

def find_index(x, arr):
	i = x - 1
	while True:
		if arr[i] == 0:
			break
		arr[i] -= 1
		i -= 1
		if i == -1:
			i = n - 1
	return i

def add_remain(x, arr, index):
	i = x - 1
	count = 0
	while True:
		if i == index:
			break
		count += 1
		i -= 1
		if i == -1:
			i = len(arr) - 1
	return count
(n, x) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
carr = arr[:]
mn = min(arr)
transform(carr, mn)
ans = mn * n
index = find_index(x, carr)
ans += add_remain(x, arr, index)
for i in range(n):
	arr[i] -= mn
arr[index] = ans
i = x - 1
while True:
	if i == index:
		break
	arr[i] -= 1
	i -= 1
	if i < 0:
		i = n - 1
print(*arr)


(n, dest) = list(map(int, input().split()))
dest -= 1
a = list(map(int, input().split()))
m1 = float('inf')
m2 = float('inf')
pos1 = -1
pos2 = -1
for i in range(dest + 1):
	if a[i] <= m1:
		m1 = a[i]
		pos1 = i
for i in range(dest + 1, n):
	if a[i] <= m2:
		m2 = a[i]
		pos2 = i
if m2 < m1:
	c = 0
	for i in range(n):
		if dest + 1 <= i <= pos2:
			c += m2
			a[i] -= m2
		else:
			c += m2 + 1
			a[i] -= m2 + 1
	a[pos2] = c
else:
	c = 0
	for i in range(n):
		if pos1 + 1 <= i <= dest:
			c += m1 + 1
			a[i] -= m1 + 1
		else:
			c += m1
			a[i] -= m1
	a[pos1] = c
print(*a)


def solve(n, x, seq):
	x -= 1
	_min = min(seq)
	s = sum(seq)
	idx = -1
	for i in range(x, -1, -1):
		if seq[i] == _min:
			idx = i
			break
	else:
		for j in range(n - 1, x, -1):
			if seq[j] == _min:
				idx = j
				break
	for i in range(n):
		seq[i] -= _min
	if idx <= x:
		for j in range(idx + 1, x + 1):
			seq[j] -= 1
	else:
		for j in range(x, -1, -1):
			seq[j] -= 1
		for j in range(n - 1, idx, -1):
			seq[j] -= 1
	seq[idx] = s - sum(seq)
	return seq

def main():
	(n, x) = map(int, input().split())
	seq = [int(c) for c in input().split()]
	ans = solve(n, x, seq)
	print(*ans)
main()


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
m = min(a)
f = x - 1
for i in range(n):
	if a[f] == m:
		st = f
		break
	f = (f - 1) % n
c = m + 1
ct = 0
for i in range(n):
	a[st] -= c
	ct += c
	if st == x - 1:
		c -= 1
	st = (st + 1) % n
a[st] = ct - 1
print(*a)


(n, x) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
m = min(a)
x -= 1
pos = -1
for i in range(n):
	if a[i] == m:
		pos = i
	if i == x and pos != -1:
		break
for i in range(n):
	a[i] -= m
	a[pos] += m
if x != pos:
	i = (pos + 1) % n
	while i != x:
		a[i] -= 1
		a[pos] += 1
		i = (i + 1) % n
	a[pos] += 1
	a[i] -= 1
for i in a:
	print(i, end=' ')


def main():
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	j = x - 1
	z = min(a)
	while a[j] != z:
		if j == 0:
			j = n - 1
		else:
			j -= 1
	m = a[j]
	k = 0
	if x - 1 > j:
		for i in range(n):
			if j < i <= x - 1:
				a[i] -= m + 1
				k += m + 1
			else:
				a[i] -= m
				k += m
		a[j] += k
	elif x - 1 < j:
		for i in range(n):
			if x - 1 < i <= j:
				a[i] -= m
				k += m
			else:
				a[i] -= m + 1
				k += m + 1
		a[j] += k
	else:
		for i in range(n):
			a[i] -= m
			k += m
		a[j] += k
	print(*a)
main()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, x) = value()
x -= 1
a = array()
dif = min(a)
ind = x
for _ in range(n):
	if a[ind] == dif:
		break
	ind = (ind - 1 + n) % n
for i in range(n):
	if i != ind:
		a[i] -= dif
i = ind
a[ind] *= n
while True and ind != x:
	i = (i + 1) % n
	a[i] -= 1
	a[ind] += 1
	if i == x:
		break
print(*a)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = l.index(min(l))
m = l[a] + 1
c = 0
f = k - 1
for i in range(n):
	if l[f] == l[a]:
		d = f
		break
	f = (f - 1) % n
for i in range(n):
	l[d] -= m
	c += m
	if d == k - 1:
		m -= 1
	d = (d + 1) % n
l[d] = c - 1
print(*l)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
t = min(a)
if t != 0:
	for i in range(n):
		a[i] -= t - 1
i = x - 1
c = 0
while a[i] != 0:
	a[i] -= 1
	c += 1
	i -= 1
	if i == -1:
		i = n - 1
a[i] += c + max(t - 1, 0) * n
for i in a:
	print(i, end=' ')


(n, x) = map(int, input().split())
t = list(map(int, input().split()))
m = min(t[:x])
if m == 0:
	i = x - 1
	while t[i]:
		i -= 1
	t[i + 1:x] = [j - 1 for j in t[i + 1:x]]
	t[i] = x - i - 1
else:
	t[:x] = [i - 1 for i in t[:x]]
	m = min(t)
	if m:
		t = [i - m for i in t]
	i = n - 1
	while t[i]:
		i -= 1
	t[i + 1:] = [j - 1 for j in t[i + 1:]]
	t[i] = x + m * n + n - i - 1
print(' '.join(map(str, t)))


import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65

def getInt():
	return int(sys.stdin.readline().rstrip())

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

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	for ele in ans:
		sys.stdout.write(str(ele) + ' ')
	sys.stdout.write('\n')

def solve(init, balls):
	mn = MAXNUM
	k = 0
	dist = 0
	for i in range(len(balls)):
		curdist = (init - i) % len(balls)
		if balls[i] < mn:
			mn = balls[i]
			k = i
			dist = (init - i) % len(balls)
		elif balls[i] == mn and curdist < dist:
			mn = balls[i]
			k = i
			dist = curdist
	rounds = balls[k]
	cur = (k + 1) % len(balls)
	while cur != (init + 1) % len(balls):
		balls[cur] -= rounds + 1
		balls[k] += rounds + 1
		cur += 1
		cur %= len(balls)
	cur = (init + 1) % len(balls)
	while cur != k:
		balls[cur] -= rounds
		balls[k] += rounds
		cur += 1
		cur %= len(balls)
	return balls

def readinput():
	(n, x) = getInts()
	balls = list(getInts())
	printOutput(solve(x - 1, balls))
readinput()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, x) = L()
A = L()
x -= 1
if 0 in A[:x]:
	cnt = 0
	while A[x] != 0:
		cnt += 1
		A[x] -= 1
		x -= 1
	A[x] = cnt
elif 0 in A[x + 1:]:
	cnt = 0
	for i in range(x + 1):
		A[i] -= 1
		cnt += 1
	for i in range(n - 1, -1, -1):
		if A[i] == 0:
			A[i] += cnt
			break
		A[i] -= 1
		cnt += 1
else:
	m = min(A)
	idx = -1
	for i in range(x, -1, -1):
		if A[i] == m:
			idx = i
			break
	if idx == -1:
		for i in range(x + 1, n):
			if A[i] == m:
				idx = i
				break
	cnt = 0
	for i in range(n):
		A[i] -= m
		cnt += m
		if idx <= x and idx <= i <= x or (idx > x and (not x < i <= idx)):
			A[i] -= 1
			cnt += 1
	A[idx] += cnt
print(*A)
endtime = time.time()


import sys
from math import *

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

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))
(n, x) = mints()
x -= 1
a = list(mints())
m = min(a)
d = max(0, m - 2)
if d != 0:
	for i in range(n):
		a[i] -= d
t = n * d
while True:
	a[x] -= 1
	t += 1
	x = (x + n - 1) % n
	if a[x] == 0:
		break
a[x] = t
print(*a)


from math import inf
(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
x -= 1
mx = inf
mi = None
for i in range(x, x - n, -1):
	if a[i] < mx:
		mx = a[i]
		mi = i
mi %= n
for i in range(n):
	a[i] -= mx
a[mi] = mx * n + (x - mi) % n
for i in range(mi + 1 - (n if x < mi else 0), x + 1):
	a[i] -= 1
print(' '.join(map(str, a)))


import math
(n, x) = map(int, input().split())
a = list(map(int, input().split()))
x -= 1
c = (x + 1) % n
min1 = math.inf
min2 = -1
min3 = -1
for i in range(n):
	if min1 >= a[c]:
		min1 = a[c]
		min2 = c
		min3 = n - i - 1
	c = (c + 1) % n
flag = False
c = min2
for i in range(n):
	a[i] -= min1
for i in range(n):
	a[c] -= 1
	if x == c:
		break
	c = (c + 1) % n
a[min2] = min3 + min1 * n
print(*a)


import sys
input = sys.stdin.readline

def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	(n, x) = read_ints()
	a = read_ints()
	last_min_j = x % n
	for j in range(x, x + n):
		if a[j % n] <= a[last_min_j]:
			last_min_j = j % n
	temp = a[last_min_j]
	a[last_min_j] += n * temp
	a = [a0 - temp for a0 in a]
	j = last_min_j + 1
	while j % n != x % n:
		a[j % n] -= 1
		j += 1
		a[last_min_j] += 1
	print(*a)
solve()


n = [int(num) for num in input().split()]
x = [int(num) for num in input().split()]
i = n[1] - 1
j = (i - 1) % n[0]
while j != n[1] - 1:
	if x[j] < x[i]:
		i = j
	j = (j - 1) % n[0]
p = x[i]
j = (n[1] - i - 1) % n[0]
if p != x[n[1] - 1]:
	x[i] = p * n[0] + j
	i = i + 1
else:
	x[n[1] - 1] = p * n[0]
	j = 0
	i = n[1]
t = i - 1
while True:
	if j != 0:
		j = j - 1
		x[i % n[0]] = x[i % n[0]] - 1 - p
	else:
		x[i % n[0]] = x[i % n[0]] - p
	if (i + 1) % n[0] == t:
		break
	else:
		i = i + 1
for i in x:
	print(i, end=' ')


l = input().split()
n = int(l[0])
x = int(l[1])
l = input().split()
li = [int(i) for i in l]
mina = li[0]
ind = 0
for i in range(1, n):
	if li[i] <= mina:
		ind = i
		mina = li[i]
indexofx = x - 1
for i in range(n):
	if li[(indexofx + n - i) % n] == mina:
		ind = (indexofx + n - i) % n
		break
quot = li[ind]
indexofx = x - 1
if indexofx >= ind:
	rem = indexofx - ind
else:
	rem = n - 1 - ind + indexofx + 1
l = [0 for i in range(n)]
for i in range(n):
	if i != ind:
		l[i] = li[i] - quot
l[ind] = quot * n + rem
for i in range(1, rem + 1):
	l[(ind + i) % n] -= 1
for i in l:
	print(i, end=' ')
print()


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
m = min(a)
a = [i - m for i in a]
x = x - 1
d = m * n
while a[x] > 0:
	d += 1
	a[x] -= 1
	x -= 1
	if x < 0:
		x = n - 1
a[x] = d
print(*a)


(n, l) = input().split()
n = int(n)
l = int(l)
l = l - 1
a = list(map(int, input().split()))
min = float('inf')
for i in range(n - 1, -1, -1):
	if a[i] < min:
		min = a[i]
		pos = i
if a[l] == min:
	pos = l
if l >= pos:
	for i in range(0, n):
		a[i] -= min
	for i in range(pos + 1, l + 1):
		a[i] -= 1
	a[pos] = n * min + l - pos
else:
	found = 0
	for i in range(l, -1, -1):
		if a[i] == min:
			pos = i
			found = 1
			break
	if found == 1:
		for i in range(0, n):
			a[i] -= min
		for i in range(pos + 1, l + 1):
			a[i] -= 1
		a[pos] = n * min + l - pos
	else:
		for i in range(0, n):
			a[i] -= min
		for i in range(pos + 1, n):
			a[i] -= 1
		for i in range(0, l + 1):
			a[i] -= 1
		a[pos] = n * min + n - pos + l
for i in range(0, n):
	print(a[i], end=' ')


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
m = min(a)
a = [v - m for v in a]
d = m * n
x = x - 1
while a[x] > 0:
	d = d + 1
	a[x] = a[x] - 1
	x = x - 1
	if x < 0:
		x = n - 1
a[x] = d
print(' '.join(map(str, a)))


(n, x) = map(int, input().split())
A = {}
L = list(map(int, input().split()))
minn = min(L)
ind = x - 1
while L[ind] != minn:
	ind -= 1
	if ind == -1:
		ind = n - 1
iterations = L[ind]
Diff = [0] * n
r = 1
inc = True
if x - 1 == ind:
	inc = False
i = ind + 1
start = True
rem = 0
while i != ind + 1 or start:
	start = False
	if i == n:
		i = 0
	if i == x - 1 and inc:
		rem += 1
		inc = False
		L[i] -= iterations + r
		i += 1
		continue
	if inc:
		rem += 1
		L[i] -= iterations + r
	else:
		L[i] -= iterations
	i += 1
if ind != 0:
	if L[0] < 0:
		while 1:
			x = 1
	print(L[0], end='')
else:
	print(iterations * n + rem, end='')
for i in range(1, n):
	if i == ind:
		print(' ' + str(iterations * n + rem), end='')
		continue
	if L[i] < 0:
		while 1:
			x = 1
	print(' ' + str(L[i]), end='')
print()


(n, x) = list(map(int, input().split()))
a = list(map(int, input().split()))
idx = x % n
for j in range(x, x + n):
	if a[j % n] <= a[idx]:
		idx = j % n
temp = a[idx]
a[idx] += n * temp
a = [i - temp for i in a]
j = idx + 1
while j % n != x % n:
	a[j % n] -= 1
	j += 1
	a[idx] += 1
print(*a)


(n, x) = map(int, input().split())
x = x - 1
l = list(map(int, input().split()))
(min_index, min_value) = (-1, 10 ** 9 + 7)
nb_seen = 0
cur = x
while nb_seen != n:
	if min_value > l[cur]:
		min_value = l[cur]
		min_index = cur
	cur = (n - 1 + cur) % n
	nb_seen += 1
min_value = l[min_index]
for i in range(n):
	l[i] -= min_value
nb_el = 0
cur = x
while l[cur] != 0:
	l[cur] -= 1
	cur = (n - 1 + cur) % n
	nb_el += 1
l[min_index] += n * min_value + nb_el
print(' '.join(list(map(str, l))))


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
x -= 1
y = max(0, min(a))
for i in range(n):
	a[i] -= y
flag = False
cnt = 0
for i in range(x, -1, -1):
	if a[i] == 0:
		a[i] = cnt + y * n
		flag = True
		break
	a[i] -= 1
	cnt += 1
for i in range(n - 1, x, -1):
	if flag:
		break
	if a[i] == 0:
		a[i] = cnt + y * n
		break
	a[i] -= 1
	cnt += 1
print(*a)


import sys
lines = sys.stdin.readlines()
(n, x) = map(int, lines[0].strip().split(' '))
nums = list(map(int, lines[1].strip().split(' ')))
minSoFar = min(nums)
index = -1
for i in range(x + n - 1, x - 1, -1):
	if nums[i % n] == minSoFar:
		index = i % n
		break
tmp = nums[index]
num = tmp * n + (x - 1 + n - index) % n
for i in range(n):
	nums[i] -= tmp
for i in range(1, (x - 1 + n - index) % n + 1):
	nums[(i + index) % n] -= 1
nums[index] = num
print(' '.join(map(str, nums)))


(n, x) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
m = min(l)
x -= 1
p = -1
for i in range(n):
	if l[i] == m:
		p = i
	if i == x and p != -1:
		break
for i in range(n):
	l[i] -= m
	l[p] += m
if x != p:
	i = (p + 1) % n
	while i != x:
		l[i] -= 1
		l[p] += 1
		i = (i + 1) % n
	l[p] += 1
	l[i] -= 1
for i in l:
	print(i, end=' ')


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	k = min(a)
	init = k * n
	for i in range(n):
		if a[i] == k:
			ind = i
			break
	for i in range(n):
		a[i] -= k
	store = ind
	while 1:
		if a[(x - 1 + n) % n] == 0:
			a[(x - 1 + n) % n] = init
			break
		x = (x - 1 + n) % n
		a[x] -= 1
		init += 1
	print(*a)
	return
main()