You are given an unordered array of unique integers incrementing from $\mbox{1}$.  You can swap any two elements a limited number of times.  Determine the largest lexicographical value array that can be created by executing no more than the limited number of swaps.  

Example 

$arr=[1,2,3,4]$ 

$k=1$    

The following arrays can be formed by swapping the $\mbox{I}$ with the other elements: 

[2,1,3,4]
[3,2,1,4]
[4,2,3,1]

The highest value of the four (including the original) is $[4,2,3,1]$.  If $k\geq2$, we can swap to the highest possible value: $[4,3,2,1]$.

Function Description  

Complete the largestPermutation function in the editor below.  It must return an array that represents the highest value permutation that can be formed.  

largestPermutation has the following parameter(s):  

int k: the maximum number of swaps  
int arr[n]: an array of integers  

Input Format

The first line contains two space-separated integers $n$ and $\boldsymbol{\mbox{k}}$, the length of $\textbf{arr}$ and the maximum swaps that can be performed.
The second line contains $n$ distinct space-separated integers from $\mbox{1}$ to $n$ as $arr\left[i\right]$ where $1\leq ar r[i]\leq n$.

Constraints

$1\leq n\leq10^5$ 

$1\leq k\leq10^9$  

Output Format

Print the lexicographically largest permutation you can make with at most $\boldsymbol{\mbox{k}}$ swaps. 

Sample Input 0  

STDIN       Function
-----       --------
5 1         n = 5, k = 1
4 2 3 5 1   arr = [4, 2, 3, 5, 1]

Sample Output 0  

5 2 3 4 1

Explanation 0  

You can swap any two numbers in $[4,2,3,5,1]$ and see the largest permutation is $[5,2,3,4,1]$

Sample Input 1

3 1
2 1 3

Sample Output 1  

3 1 2

Explanation 1  

With 1 swap we can get $[1,2,3]$, $[3,1,2]$ and $[2,3,1]$.  Of these, $[3,1,2]$ is the largest permutation.  

Sample Input 2

2 1
2 1

Sample Output 2  

2 1

Explanation 2  

We can see that $[2,1]$ is already the largest permutation.  We don't make any swaps.

Difficulty: EASY

Solutions:
(n, k) = map(int, input().split())
p = list(map(lambda s: int(s) - 1, input().split()))
where = [-1] * n
for (i, x) in enumerate(p):
	where[x] = i
for i in range(n):
	if k == 0:
		break
	if p[i] != n - 1 - i:
		bad_pos = where[n - 1 - i]
		bad_num = p[i]
		(p[i], p[bad_pos]) = (p[bad_pos], p[i])
		(where[bad_num], where[n - 1 - i]) = (where[n - 1 - i], where[bad_num])
		k -= 1
print(' '.join(map(lambda x: str(x + 1), p)))


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
current_max = max(a)
i = 0
while k > 0 and i < len(a):
	current_max = max(a[i:])
	for index in range(i + 1, n):
		if a[index] == current_max:
			temp = a[i]
			a[i] = current_max
			a[index] = temp
			k -= 1
			break
	i += 1
print(' '.join((str(x) for x in a)))


(n, k) = input().split()
n = int(n)
k = int(k)
i = 0
arr = [int(x) for x in input().split()]
j = 0
while i < k and j < n - 1:
	m = max(arr[j + 1:])
	if m > arr[j]:
		(arr[arr.index(m)], arr[j]) = (arr[j], arr[arr.index(m)])
		i += 1
	j += 1
for i in arr:
	print(i, end=' ')


s = list(map(int, input().strip().split()))
n = s[0]
k = s[1]
l = list(map(int, input().strip().split()))
ind = [0] * n
for i in range(n):
	ind[l[i] - 1] = i
i = 0
m = n
while i < n and k > 0:
	if l[i] == m:
		i += 1
		m -= 1
	else:
		j = ind[m - 1]
		(ind[m - 1], ind[l[i] - 1]) = (i, j)
		(l[i], l[j]) = (l[j], l[i])
		i += 1
		m -= 1
		k -= 1
ans = list(map(str, l))
print(' '.join(ans))


(n, k) = str(input()).split()
n = int(n)
k = int(k)
d = input().split()
d = list(map(int, d))
for (i, e) in enumerate(d):
	if e != n:
		(d[d.index(n)], d[i]) = (d[i], d[d.index(n)])
		k -= 1
	if k == 0:
		break
	n -= 1
d = map(str, d)
print(' '.join(d))


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
if k >= n:
	k = n - 1
(i, count) = (0, 0)
while count != k and i != n:
	ind = l.index(n - i)
	(l[i], l[ind]) = (l[ind], l[i])
	if ind != i:
		count += 1
	i += 1
print(' '.join(map(str, l)))


import operator
(N, K) = map(int, input().split())
num_list = list(map(int, input().split()))
offset = 0
for i in range(K):
	if i + offset >= N:
		break
	(index, max_num) = max(enumerate(num_list[i + offset:]), key=operator.itemgetter(1))
	while max_num == num_list[i + offset]:
		offset += 1
		if i + offset >= N:
			break
		(index, max_num) = max(enumerate(num_list[i + offset:]), key=operator.itemgetter(1))
	else:
		index += i + offset
		(num_list[i + offset], num_list[index]) = (num_list[index], num_list[i + offset])
print(' '.join(map(str, num_list)))


(n, kk) = list(map(int, input().split()))
a = list(map(int, input().split()))
k = 0
for i in range(n):
	if a[i] != n - i:
		for p in range(i, n):
			if a[p] == n - i:
				break
		(a[i], a[p]) = (a[p], a[i])
		k += 1
	if k == kk:
		break
for i in a:
	print(i, end=' ')


import operator

def f(n, k, l):
	d = dict()
	swap_num = 0
	for idx in range(len(l)):
		exp_num = n - idx
		while l[idx] in d.keys():
			l[idx] = d[l[idx]]
		if exp_num != l[idx]:
			if swap_num < k:
				d[exp_num] = l[idx]
				l[idx] = exp_num
				swap_num += 1
	print(*l)
(n, k) = [int(v) for v in input().split()]
l = [int(v) for v in input().split()]
f(n, k, l)


(n, k) = map(int, input().split())
lst = [int(x) for x in input().split()]
slst = sorted(lst, reverse=True)
d = {}
for (i, j) in enumerate(lst):
	d[j] = i
i = 0
while i < k:
	if i >= n - 1:
		break
	s = slst[i]
	if lst[i] == s:
		k += 1
	else:
		d[lst[i]] = d[s]
		lst[d[lst[i]]] = lst[i]
		lst[i] = s
		d[s] = i
	i += 1
print(' '.join([str(x) for x in lst]))


def worstPermutation(seq, swaps):
	sortedseq = list(reversed(sorted(seq)))
	pos = {seq[i]: i for i in range(len(seq))}
	for i in range(len(seq)):
		if swaps == 0:
			break
		if seq[i] == sortedseq[i]:
			continue
		j = pos[sortedseq[i]]
		(seq[i], seq[j]) = (seq[j], seq[i])
		(pos[seq[i]], pos[seq[j]]) = (pos[seq[j]], pos[seq[i]])
		swaps -= 1
	return seq
(_, swaps) = map(int, input().split())
seq = [int(entry) for entry in input().split()]
print(' '.join(map(str, worstPermutation(seq, swaps))))


(N, K) = map(int, input().split(' '))
a = map(int, input().split(' '))
if K >= N - 1:
	print(' '.join(map(str, range(N, 0, -1))))
else:
	result = []
	changewith = []
	willchange = []
	a = list(a)
	for e in range(len(a)):
		if K == 0:
			result = result + a[e:]
			break
		if N - e == a[e]:
			continue
		elif K > 0:
			index = a.index(N - e)
			(a[index], a[e]) = (a[e], a[index])
			K -= 1
	print(' '.join(map(str, a)))


import sys
(N, K) = (int(_) for _ in input().split())
A = list((int(_) for _ in input().split()))
for i in range(N):
	if K == 0:
		break
	m = max(A[i:])
	if A[i] != m:
		im = A.index(m)
		(A[i], A[im]) = (A[im], A[i])
		K -= 1
print(' '.join((str(_) for _ in A)))


(n, k) = [int(c) for c in input().split()]
A = [int(c) for c in input().split()]
index_of_item = {}
for (pos, a) in enumerate(A):
	index_of_item[a] = pos
cnt = 0
for i in range(n):
	if A[i] == n - i:
		continue
	idx = index_of_item[n - i]
	A[idx] = A[i]
	A[i] = n - i
	index_of_item[n - i] = i
	index_of_item[A[idx]] = idx
	cnt += 1
	if cnt == k:
		break
print(' '.join([str(c) for c in A]))


def swap(arr, k):
	n = len(arr)
	if k >= n:
		return reversed(range(1, n + 1))
	indexes = [-1] * (n + 1)
	for (i, el) in enumerate(arr):
		assert indexes[el] == -1
		indexes[el] = i
	remaining_swaps = k
	i = 0
	while remaining_swaps > 0 and i < n:
		looking_for = n - i
		if arr[i] != looking_for:
			remaining_swaps -= 1
			i2 = indexes[looking_for]
			(arr[i], arr[i2]) = (arr[i2], arr[i])
			indexes[arr[i2]] = i2
		i += 1
	return arr
(n, k) = [int(s) for s in input().split()]
arr = [int(s) for s in input().split()]
arr = swap(arr, k)
print(' '.join([str(el) for el in arr]))


(n, k) = map(int, input().split())
mylist = list(map(int, input().split()))
if k > n:
	mylist.sort(reverse=True)
	print(' '.join((str(x) for x in mylist)))
else:
	newlist = sorted(mylist, reverse=True)
	for i in range(0, n):
		if mylist[i] != newlist[i] and k > 0:
			x = mylist.index(newlist[i])
			(mylist[i], mylist[x]) = (mylist[x], mylist[i])
			k -= 1
	print(' '.join((str(x) for x in mylist)))


import sys

def main():

	def get_worst_perm(perm, k, n):
		d = [0] * n
		for (i, x) in enumerate(perm):
			d[x] = i
		swapcount = 0
		for x in range(n):
			if perm[x] == perm[d[n - x - 1]]:
				continue
			if swapcount >= k:
				break
			(perm[x], perm[d[n - x - 1]]) = (perm[d[n - x - 1]], perm[x])
			d[perm[d[n - x - 1]]] = d[n - x - 1]
			d[n - x - 1] = x
			swapcount += 1
		return perm
	dstream = map(int, sys.stdin.read().split())
	(n, k) = (next(dstream), next(dstream))
	perm = [next(dstream) - 1 for _ in range(n)]
	for x in get_worst_perm(perm, k, n):
		print(x + 1, end=' ')
	print()
main()


(N, K) = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
if N <= K:
	numbers = [int(i) for i in range(N + 1)][::-1]
else:
	_ = 0
	index = 0
	swaps = 0
	while swaps < K and index < N - 1:
		maximum = numbers.index(max(numbers[_:]))
		if maximum == _:
			index = _
			_ += 1
		else:
			(numbers[_], numbers[maximum]) = (numbers[maximum], numbers[_])
			swaps += 1
			_ += 1
for _ in range(N):
	print(str(numbers[_]), end=' ')


ins = list(map(int, input().split()))
N = ins[0]
K = ins[1]
lst = list(map(int, input().split()))
presort = sorted(lst, reverse=True)
if lst == presort:
	for num in lst:
		print(num, end=' ')
elif K < N and K != 0:
	(i, k) = (0, 0)
	while k < K:
		max = lst[i]
		ind = i
		for n in range(i + 1, N):
			if lst[n] > max:
				max = lst[n]
				ind = n
		if ind != i:
			(lst[i], lst[ind]) = (lst[ind], lst[i])
			i += 1
			k += 1
		else:
			i += 1
	for num in lst:
		print(num, end=' ')
elif K >= N and K != 0:
	lst = sorted(lst, reverse=True)
	for num in lst:
		print(num, end=' ')


def best_swap(n, list):
	start = len(list) - n
	if start == len(list) - 1:
		return 0
	if list[start] == n:
		return best_swap(n - 1, list)
	if list[start] < n:
		i = list.index(n)
		(list[start], list[i]) = (list[i], list[start])
		return n - 1
(N, K) = input().split()
(N, K) = (int(N), int(K))
l = [int(i) for i in input().split()]
last = N
for i in range(min(K, N)):
	last = best_swap(last, l)
	if last <= 1:
		break
print(' '.join([str(i) for i in l]))


def wp():
	(N, K) = [int(x) for x in input().split()]
	numbers = [int(x) for x in input().split()]
	positions = [-1] * (len(numbers) + 1)
	for i in range(len(numbers)):
		positions[numbers[i]] = i
	for i in range(len(numbers)):
		if K <= 0:
			break
		if numbers[i] != N - i:
			numbers[positions[N - i]] = numbers[i]
			positions[numbers[i]] = positions[N - i]
			numbers[i] = N - i
			positions[N - i] = i
			K -= 1
	print(' '.join([str(x) for x in numbers]))
wp()


import heapq

def main():
	(length, max_swaps) = map(int, input().split())
	array = [int(_) for _ in input().split()]
	worst_permuntation = worst_perm(array, max_swaps)
	for elem in worst_permuntation:
		print(elem, end=' ')
	print()

def worst_perm(array, max_swaps):
	visited = set()
	heap = list(zip([-i for i in array], range(len(array))))
	visited = [False] * len(array)
	heapq.heapify(heap)
	elemindex = 0
	swaps = 0
	while elemindex < len(array) and swaps < max_swaps:
		currentmax = heapq.heappop(heap)
		while visited[currentmax[1]]:
			currentmax = heapq.heappop(heap)
		if -currentmax[0] == array[elemindex]:
			elemindex += 1
			continue
		array[currentmax[1]] = array[elemindex]
		array[elemindex] = -currentmax[0]
		visited[elemindex] = True
		heapq.heappush(heap, (-array[currentmax[1]], currentmax[1]))
		swaps += 1
		elemindex += 1
	return array
main()


(N, K) = [int(i) for i in input().split(' ')]
numList = [int(i) for i in input().split(' ')]
sortedList = sorted(numList, reverse=True)
i = 0
maxSwaps = K
if K >= N:
	print(' '.join(map(str, sortedList)))
else:
	while i < maxSwaps:
		index = numList.index(sortedList[i])
		if numList[i] < sortedList[i]:
			temp = numList[i]
			numList[i] = numList[index]
			numList[index] = temp
		else:
			maxSwaps += 1
			if maxSwaps > N:
				break
		i = i + 1
	print(' '.join(map(str, numList)))


d = input().split()
(N, K) = (int(d[0]), int(d[1]))
reference = [x for x in range(N, 0, -1)]
s = input().split()
numbers = [int(i) for i in s]
count = 0
for i in range(N):
	if numbers[i] == reference[i]:
		pass
	elif count < K:
		trueValue = reference[i]
		index = numbers.index(trueValue)
		(numbers[i], numbers[index]) = (trueValue, numbers[i])
		count += 1
	else:
		break
out = ''
for number in numbers:
	out += str(number) + ' '
print(out)


(n, k) = map(int, input().split())
arr = []
for i in map(int, input().split()):
	arr.append(i)
for i in range(0, k):
	if i < len(arr):
		index_of_max = arr.index(max(arr[i:]))
		j = i
		while arr[index_of_max] == arr[j] and j < len(arr) - 1:
			j = j + 1
			index_of_max = arr.index(max(arr[j:]))
		(arr[index_of_max], arr[j]) = (arr[j], arr[index_of_max])
for i in arr:
	print(i, end=' ')


(ArraySize, MaxSwap) = [int(x) for x in input().split()]
MixedArray = [int(x) for x in input().split()]
Complexity = ArraySize - 1
Position = Swap = 0
for i in range(ArraySize):
	if MixedArray[-i] == ArraySize - i:
		Complexity -= 1
if MaxSwap > Complexity:
	MixedArray = range(ArraySize, 0, -1)
else:
	while Swap < MaxSwap:
		Value = ArraySize - Position
		if MixedArray[Position] != Value:
			SwapPosition = MixedArray.index(Value)
			(MixedArray[SwapPosition], MixedArray[Position]) = (MixedArray[Position], MixedArray[SwapPosition])
			Swap += 1
		Position += 1
print(' '.join(map(str, MixedArray)))


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
num_swaps = 0
for i in range(0, n):
	j = ls.index(n - i)
	if i != j:
		(ls[i], ls[j]) = (ls[j], ls[i])
		num_swaps += 1
		if num_swaps >= k:
			break
print(' '.join(map(str, ls)))


(num_ints, num_swaps) = [int(i) for i in input().split()]
array = [int(j) for j in input().split()]
best_possible = list(reversed(sorted(array)))
if num_swaps >= num_ints - 1:
	array = best_possible
else:
	while num_swaps:
		if array == best_possible:
			break
		for i in range(num_ints):
			if array[i] != best_possible[i]:
				largest_int = max(array[i:])
				largest_int_index = array.index(largest_int)
				temp_int = array[i]
				array[i] = largest_int
				array[largest_int_index] = temp_int
				num_swaps = num_swaps - 1
				break
print(' '.join([str(k) for k in array]))


(n, k) = input().split()
n = int(n)
k = int(k)
a = n * [0]
a = input().split()
a = [int(i) for i in a]
b = n * [0]
for i in range(0, n):
	b[a[i] - 1] = i
count = 0
j = 0
while count < k and j < n:
	if a[j] != n - j:
		(a[j], a[b[n - j - 1]]) = (a[b[n - j - 1]], a[j])
		(b[a[b[n - j - 1]] - 1], b[a[j] - 1]) = (b[a[j] - 1], b[a[b[n - j - 1]] - 1])
		count += 1
	j += 1
for i in range(0, n):
	print(a[i], end=' ')


def main():
	(n, k) = readints()
	perm = [i - 1 for i in readints()]
	assert len(perm) == n
	print(' '.join((str(i + 1) for i in worstperm(perm, k))))

def readints():
	return [int(fld) for fld in input().split()]

def worstperm(perm, k):
	n = len(perm)
	locs = [None] * n
	for (i, p) in enumerate(perm):
		locs[p] = i
	for i in range(n):
		if k == 0:
			break
		target = n - i - 1
		current = perm[i]
		if current != target:
			k -= 1
			(perm[i], perm[locs[target]]) = (target, current)
			(locs[target], locs[current]) = (i, locs[target])
	return perm
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
aux = [0] * n
for x in range(n):
	aux[a[x] - 1] = x
sw = 0
i = 0
m = n
while sw < k and i < n:
	if a[i] != m:
		j = a[i]
		a[i] = m
		a[aux[m - 1]] = j
		(aux[m - 1], aux[j - 1]) = (aux[j - 1], aux[m - 1])
		sw += 1
	i += 1
	m -= 1
for x in a:
	print(x, end=' ')


def findWorstPerm(perm, size, maxSwaps):
	if maxSwaps == 0:
		return perm
	swap = 0
	maxSize = len(perm)
	for i in range(size):
		if perm[i] < maxSize:
			for j in range(i + 1, size):
				if perm[j] == maxSize:
					(perm[i], perm[j]) = (perm[j], perm[i])
					maxSize -= 1
					swap += 1
					if swap == maxSwaps:
						return perm
					break
		else:
			maxSize -= 1
	return perm
(size, maxSwaps) = map(int, input().split())
perm = list(map(int, input().split()))
print(' '.join(map(str, findWorstPerm(perm, size, maxSwaps))))


(n, k) = input().split()
(n, k) = (int(n), int(k))
l = input().split()
worst = sorted(l, reverse=True)
for i in range(n):
	if k == 0 or l == worst:
		break
	loc = l.index(str(n - i))
	if loc != i:
		(l[i], l[loc]) = (l[loc], l[i])
		k -= 1
print(' '.join(l))


s = [int(x) for x in input().split()]
(n, k) = (s[0], s[1])
l = [int(x) for x in input().split()]
L = sorted(l)
i = 0
while k > 0 and i < n:
	m = l.index(L.pop(), i)
	if i != m:
		tmp = l[i]
		l[i] = l[m]
		l[m] = tmp
		k -= 1
	i += 1
l = map(str, l)
print(' '.join(l))


__author__ = 'anant'
(no_of_integers, no_of_swaps) = input().split()
no_of_integers = int(no_of_integers)
no_of_swaps = int(no_of_swaps)
integer_list = input().split()

def find_max_index(start, end):
	max_id = -1
	max = integer_list[start]
	for i in range(start, end):
		if integer_list[i] >= max:
			max = integer_list[i]
			max_id = i
	return max_id
for i in range(0, no_of_integers):
	integer_list[i] = int(integer_list[i])
if no_of_swaps > no_of_integers:
	no_of_swaps = no_of_integers
i = -1
while i < no_of_swaps - 1:
	if i + 1 != no_of_integers:
		max_index = find_max_index(i + 1, len(integer_list))
		if max_index == i + 1:
			no_of_swaps += 1
			i += 1
		else:
			temp = integer_list[i + 1]
			integer_list[i + 1] = integer_list[max_index]
			integer_list[max_index] = temp
			i += 1
	else:
		no_of_swaps = i
integer_list_string = ' '.join(map(str, integer_list))
print(integer_list_string)


def largest_perm(arr, k):
	e = len(arr)
	for i in range(len(arr)):
		if arr[i] != e - i:
			idx = arr.index(e - i)
			(arr[i], arr[idx]) = (e - i, arr[i])
			k -= 1
			if k == 0:
				break
	print(' '.join(map(str, arr)))
nk = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
largest_perm(nums, nk[1])


import heapq

def main():
	(length, max_swaps) = map(int, input().split())
	array = [int(_) for _ in input().split()]
	worst_permuntation = worst_perm(array, max_swaps)
	for elem in worst_permuntation:
		print(elem, end=' ')
	print()

def worst_perm(array, max_swaps):
	visited = set()
	heap = list(zip([-i for i in array], range(len(array))))
	heapq.heapify(heap)
	elemindex = 0
	swaps = 0
	while elemindex < len(array) and swaps < max_swaps:
		currentmax = heapq.heappop(heap)
		while currentmax[1] < elemindex:
			currentmax = heapq.heappop(heap)
		if currentmax[1] == elemindex:
			elemindex += 1
			continue
		array[currentmax[1]] = array[elemindex]
		array[elemindex] = -currentmax[0]
		heapq.heappush(heap, (-array[currentmax[1]], currentmax[1]))
		swaps += 1
		elemindex += 1
	return array
main()


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
if k >= n:
	k = n - 1
(i, count) = (0, 0)
while count != k and i != n:
	ind = l.index(n - i)
	(l[i], l[ind]) = (l[ind], l[i])
	if ind != i:
		count += 1
	i += 1
print(' '.join(map(str, l)))


def get_result(n, k, list):
	pos = 0
	for i in range(k):
		while list[pos] == str(n):
			n -= 1
			pos += 1
			if n == 0:
				return list
		tmp = list[pos]
		it = pos + 1
		while list[it] != str(n):
			it += 1
		list[pos] = list[it]
		list[it] = tmp
	return list
inp = input().split()
n = int(inp[0])
k = int(inp[1])
list = input().split()
print(' '.join(get_result(n, k, list)))


k = int(input().split()[-1])
L = input().split()
L = [int(i) for i in L]

def stringify(L):
	s = ''
	for i in L:
		s = s + str(i) + ' '
	return s[:-1]

def largest_perm(L, k):
	swaps = 0
	for i in range(0, len(L)):
		maximum = i
		for j in range(i + 1, len(L)):
			if L[maximum] < L[j]:
				maximum = j
		if maximum != i:
			(L[i], L[maximum]) = (L[maximum], L[i])
			swaps += 1
		if swaps == k:
			break
	return stringify(L)
print(largest_perm(L, k))


(N, K) = (int(x) for x in input().split())
Numbers = [int(x) for x in input().split()]
swap = 0
for i in range(N):
	if swap == K:
		break
	else:
		index = Numbers.index(max(Numbers[i:]))
		if index == i:
			continue
		else:
			temp = Numbers[index]
			Numbers[index] = Numbers[i]
			Numbers[i] = temp
			swap += 1
for x in Numbers:
	print(x, end=' ')


(N, K) = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
if N <= K:
	numbers = [int(i) for i in range(N + 1)][::-1]
else:
	_ = 0
	swaps = 0
	while swaps < K:
		maximum = numbers.index(max(numbers[_:]))
		if maximum == _:
			if maximum == N - 1:
				break
			index = _
			_ += 1
		else:
			(numbers[_], numbers[maximum]) = (numbers[maximum], numbers[_])
			swaps += 1
			_ += 1
for _ in range(N):
	print(numbers[_], end=' ')


(n, k) = input().split()
n = int(n)
k = int(k)
i = 0
arr = [int(x) for x in input().split()]
j = 0
while i < k and j < n - 1:
	m = max(arr[j + 1:])
	if m > arr[j]:
		(arr[arr.index(m)], arr[j]) = (arr[j], arr[arr.index(m)])
		i += 1
	j += 1
for i in arr:
	print(i, end=' ')


(n, k) = [int(ns) for ns in str(input()).split()]
c = [int(ns) for ns in str(input()).split()]
s = p = 0
while s < k and p < n - 1:
	while c[p] == max(c[p:]) and p < n - 1:
		p += 1
	m = max(c[p:])
	res = c.index(m)
	c[res] = c[p]
	c[p] = m
	s += 1
print(' '.join([str(a) for a in c]))


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
remain = k
for i in range(n, 0, -1):
	if remain <= 0:
		break
	now = arr.index(i)
	should = n - i
	if not now == should:
		tmp = arr[now]
		arr[now] = arr[should]
		arr[should] = tmp
		remain -= 1
print(' '.join((str(x) for x in arr)))


(N, K) = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

def swap(array, i, j):
	(array[i], array[j]) = (array[j], array[i])
for i in range(N):
	if not numbers[i] == N - i:
		K -= 1
		swap(numbers, i, numbers.index(N - i))
	if K == 0:
		break
for elem in numbers:
	print(elem, end=' ')


def maxind(a, st):
	m = a[st]
	ind = st
	for i in range(st, len(a)):
		if a[i] > m:
			m = a[i]
			ind = i
	return ind

def foo(a, t):
	for st in range(len(a)):
		if t > 0 and st < len(a):
			ind = maxind(a, st)
			if ind > st:
				(a[st], a[ind]) = (a[ind], a[st])
				t -= 1
[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
foo(a, k)
for i in a:
	print(i, end=' ')


(n, k) = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
i = 0
while i < n:
	ind = v.index(max(v[i:]))
	if ind != i:
		(v[i], v[ind]) = (v[ind], v[i])
		k = k - 1
	if k == 0:
		break
	i = i + 1
for i in v:
	print(i, end=' ')


(n, k) = list(map(int, input().split()))
nums = list(map(int, input().split()))
if k >= n - 1:
	ans = [n - i for i in range(0, n)]
	print(' '.join(list(map(str, ans))))
	quit()
for i in range(0, n):
	if nums[i] != n - i:
		sliced = nums[i:]
		maxIdx = nums.index(max(sliced))
		maxNum = nums[maxIdx]
		if maxIdx != i and k > 0:
			k -= 1
			nums[maxIdx] = nums[i]
			nums[i] = maxNum
print(' '.join(list(map(str, nums))))


def swap(a, b):
	(lis[a], lis[b]) = (lis[b], lis[a])
(n, k) = list(map(int, input().split()))
lis = list(map(int, input().split()))
p = [0 for x in range(n + 1)]
for (i, x) in enumerate(lis):
	p[x] = i
for i in range(n):
	if k <= 0:
		break
	if lis[i] == n - i:
		continue
	temp = p[n - i]
	x = lis[i]
	swap(i, p[n - i])
	p[x] = temp
	k -= 1
print(' '.join(map(str, lis)))


temp = input().split(' ')
[N, K] = list(map(int, temp))
temp = input().split(' ')
A = list(map(int, temp))
A_sorted = sorted(A, reverse=True)
for i in range(0, N):
	if K > 0:
		if A[i] != A_sorted[i]:
			j = A.index(A_sorted[i])
			(A[i], A[j]) = (A[j], A[i])
			K -= 1
A = ' '.join((str(i) for i in A))
print(A)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
swaps = 0
for i in range(N):
	if A[i] != N - i:
		j = A.index(N - i)
		(A[i], A[j]) = (A[j], A[i])
		swaps += 1
	if swaps >= K:
		break
print(' '.join(map(str, A)))


(N, K) = input().split()
N = int(N)
K = min(int(K), N - 1)
ip = input().split()
order = []
for idx in range(N):
	order.append(int(ip[idx]))
placement = list(range(N))
for idx in range(N):
	placement[order[idx] - 1] = idx
swaps = 0
idx = N - 1
while swaps < K:
	if placement[idx] != N - 1 - idx:
		temp1 = order[N - 1 - idx]
		order[placement[idx]] = temp1
		order[N - 1 - idx] = idx + 1
		temp = placement[idx]
		placement[idx] = N - 1 - idx
		placement[temp1 - 1] = temp
		swaps = swaps + 1
	idx = idx - 1
	if idx < 0:
		break
op = ''
for idx in range(N):
	op = op + str(order[idx]) + ' '
print(op)


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


def find_index(x, start, arr_len, array):
	for j in range(start, arr_len):
		if int(array[j]) == x:
			return j
	return None
(N, K) = str(input()).split()
N = int(N)
K = int(K)
array = str(input()).split()
for i in range(0, N):
	if K == 0:
		break
	if int(array[i]) != N - i:
		j = find_index(N - i, i + 1, N, array)
		temp = array[i]
		array[i] = array[j]
		array[j] = temp
		K -= 1
print(' '.join(array))


def largest_permutation(numbers, k, n):
	index = {num: i for (i, num) in enumerate(numbers)}
	maxn = n
	(i, j) = (0, min(k, n))
	while i < j:
		if maxn == 0:
			break
		max_ind = index[maxn]
		if max_ind == n - maxn:
			maxn -= 1
			i += 1
			j += 1
			continue
		(numbers[max_ind], numbers[i]) = (numbers[i], numbers[max_ind])
		(index[numbers[max_ind]], index[numbers[i]]) = (index[numbers[i]], index[numbers[max_ind]])
		maxn -= 1
		i += 1
	return numbers
(n, k) = [int(el) for el in input().split()]
numbers = [int(el) for el in input().split()]
print(' '.join((str(num) for num in largest_permutation(numbers, k, n))))


(N, K) = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
swps = K
d = {}
for i in range(N):
	if swps <= 0 and len(d) == 0:
		break
	cur = arr[i]
	while cur in d:
		cur = d.pop(cur)
	arr[i] = cur
	if arr[i] != N - i and swps > 0:
		d[N - i] = arr[i]
		arr[i] = N - i
		swps -= 1
for x in arr:
	print(x, end=' ')


line = input().split()
(n, k) = (int(line[0]), int(line[1]))
numlist = list(map(int, input().split()))
sortednumlist = sorted(numlist, reverse=True)
pivot = 0
while k > 0 and pivot < len(numlist):
	max = sortednumlist[pivot]
	while pivot < len(numlist) - 1 and max == numlist[pivot]:
		pivot += 1
		max = sortednumlist[pivot]
	numlist[numlist.index(max)] = numlist[pivot]
	numlist[pivot] = max
	pivot += 1
	k -= 1
print(' '.join((str(x) for x in numlist)))


def swap(nums, a, b):
	(nums[b], nums[a]) = (nums[a], nums[b])

def run():
	(n, k) = list(map(int, input().split(' ')))
	nums = list(map(int, input().split(' ')))
	sortlist = sorted(nums, reverse=True)
	l = len(nums)
	i = j = 0
	while k > 0:
		while nums[i] == sortlist[j]:
			i += 1
			j += 1
			if i >= l:
				return map(str, nums)
		x = i + 1
		while nums[x] != sortlist[j]:
			x += 1
		swap(nums, i, x)
		k -= 1
	return map(str, nums)
print(' '.join(run()))


(n, k) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
(i, swaps) = (0, 0)
while swaps < k and i < n:
	(maxa, maxidx) = (a[i], i)
	for j in range(i + 1, n):
		if a[j] > maxa:
			maxa = a[j]
			maxidx = j
	if maxidx != i:
		t = a[i]
		a[i] = maxa
		a[maxidx] = t
		swaps += 1
	i += 1
print(' '.join(map(str, a)))


def foo(in_1, in_2):
	x = in_1.split(' ')
	N = int(x[0])
	K = int(x[1])
	nums = in_2.split(' ')
	y = list(map(int, nums))
	sub = list(y)
	swaps_left = K
	for i in range(N):
		element = y[i]
		m = max(sub)
		m_index = y.index(m)
		if element != m and swaps_left != 0:
			y[i] = m
			y[m_index] = element
			swaps_left -= 1
		sub = y[i + 1:]
	print(' '.join(list(map(str, y))))
input_1 = input()
input_2 = input()
foo(input_1, input_2)


(N, K) = map(int, input().split())
array = list(map(int, input().split()))
i = 0
swapped = 0
while swapped < K:
	arr = array[i:]
	if len(arr) == 0:
		break
	maximum = max(arr)
	l = array.index(maximum)
	if l != i:
		temp = array[i]
		array[i] = array[l]
		array[l] = temp
		swapped += 1
	i += 1
print(' '.join(map(str, array)))


(N, K) = map(int, input().split())
data = list(map(int, input().split()))
for i in range(N):
	if K == 0:
		break
	index = data.index(N)
	temp = data[i]
	if index != i:
		data[i] = N
		data[index] = temp
		K -= 1
	N -= 1
print(' '.join(map(str, data)))


(n, k) = map(int, input().split())
L = list(map(lambda x: int(x) - 1, input().split()))
P = [0] * n
for i in range(n):
	P[L[i]] = i
i = 0
p = 0
s = 0
while p < k and i < n:
	if P[n - 1 - i] == i:
		i += 1
	else:
		t = L[i]
		L[i] = L[P[n - 1 - i]]
		L[P[n - 1 - i]] = t
		x = P[t]
		P[t] = P[n - 1 - i]
		P[n - 1 - i] = x
		p += 1
		i += 1
print(' '.join(map(lambda x: str(x + 1), L)))


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
for i in range(n - 1):
	if k == 0:
		break
	ind = i + 1
	maxi = a[ind]
	for j in range(i + 1, n):
		if a[j] > maxi:
			ind = j
			maxi = a[j]
	if a[i] < maxi:
		(a[i], a[ind]) = (a[ind], a[i])
		k -= 1
print(' '.join(map(str, a)))


def largest_permutation(array, swaps):
	curr_start = 0
	while swaps != 0 and curr_start < len(array):
		largest = max(array[curr_start:])
		position = array.index(largest)
		if position != curr_start:
			temp = array[curr_start]
			array[curr_start] = largest
			array[position] = temp
			swaps -= 1
		curr_start += 1
	return array
(elements, swaps) = (int(x) for x in input().split())
array = [int(x) for x in input().split()]
print(' '.join((str(x) for x in largest_permutation(array, swaps))))


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
p = 0
i = 0
while p < k and i < n:
	m = n - i
	if a[i] != m:
		j = a.index(m)
		(a[i], a[j]) = (a[j], a[i])
		p += 1
	i += 1
print(' '.join((str(x) for x in a)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))

def findIndexOfMax(l):
	max = -1
	index = -1
	for i in range(len(l)):
		if l[i] > max:
			max = l[i]
			index = i
	return index
moves = min(n, k)
for i in range(n):
	index = findIndexOfMax(l[i:]) + i
	if index != i:
		t = l[i]
		l[i] = l[index]
		l[index] = t
		moves -= 1
		if moves == 0:
			break
print(*l)


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


__author__ = 'chamathsilva'
(N, K) = map(int, input().split())
number = list(map(int, input().split()))
indexx = 0
exchange = 0
while exchange < K:
	max_index = number.index(max(number[indexx:]))
	if max_index != indexx:
		(number[indexx], number[max_index]) = (number[max_index], number[indexx])
		exchange += 1
	indexx += 1
	if indexx == N:
		break
print(' '.join(map(str, number)))


def largest_permutation(N, K, P):
	Q = [i for i in range(N, 0, -1)]
	if P != sorted(P):
		for i in range(N):
			if K > 0:
				if Q[i] != P[i]:
					j = P.index(max(P[i + 1:]))
					(P[i], P[j]) = (P[j], P[i])
					K -= 1
			else:
				break
	return P

def main():
	(N, K) = [int(i) for i in input().split()]
	P = [int(i) for i in input().split()]
	print(' '.join((str(i) for i in largest_permutation(N, K, P))))
main()


def solve():
	(n, t) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	c = 0
	for i in range(n):
		selection = i
		if i > 1:
			if a[i] == a[i - 1]:
				continue
		for j in range(i + 1, n):
			if a[selection] <= a[j]:
				selection = j
		if selection != i:
			(a[i], a[selection]) = (a[selection], a[i])
			c += 1
		if c == t:
			break
	print(' '.join(list(map(str, a))))
solve()


(sz_arr, kval) = list(map(int, input().split()))
arr = list(map(int, input().split()))
if kval >= sz_arr:
	arr_sorted = sorted(arr, reverse=True)
	print(' '.join(map(str, arr_sorted)))
else:
	arr_sorted = sorted(arr)
	i = 0
	while kval > 0 and i < sz_arr and (len(arr_sorted) > 0):
		ele = arr_sorted.pop()
		if arr[i] < ele:
			arr[arr.index(ele, i)] = arr[i]
			arr[i] = ele
			kval -= 1
		i += 1
	print(' '.join(map(str, arr)))


n_k = input().split()
(n, k) = (int(n_k[0]), int(n_k[1]))
nums = list(map(int, input().split()))
sorted = nums[:]
sorted.sort(reverse=True)
pos = 0
for _ in range(k):
	while pos < n and nums[pos] == sorted[pos]:
		pos += 1
	if pos == n:
		break
	other = nums.index(sorted[pos])
	(nums[pos], nums[other]) = (nums[other], nums[pos])
print(' '.join(map(str, nums)))


def largest_permutation(arr, swaps):
	for walk in range(len(arr)):
		if swaps > 0:
			ind = arr[walk:].index(max(arr[walk:])) + walk
			if ind != walk:
				(arr[ind], arr[walk]) = (arr[walk], arr[ind])
				swaps -= 1
	return arr
[_, swaps] = [int(s) for s in input('').split()]
arr = [int(s) for s in input('').split()]
print(' '.join((str(n) for n in largest_permutation(arr, swaps))))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
pos = 0
c = 0
while pos < n and c < k:
	m = max(a[pos:])
	p = a.index(m)
	if pos == p:
		pos += 1
		continue
	c += 1
	t = a[pos]
	a[pos] = a[p]
	a[p] = t
	pos += 1
for x in a:
	print(x, end=' ')


(n, k) = map(int, input().strip().split())
array = list(map(int, input().strip().split()))
(i, tt) = (0, min(n, k))
r = []
while i < tt:
	elt = array.pop(0)
	if array:
		max_elt = max(array)
		if max_elt > elt:
			index = array.index(max_elt)
			(array[index], elt) = (elt, array[index])
		else:
			tt = min(tt + 1, n)
	r.append(elt)
	i += 1
print(' '.join(map(str, r + array)))


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
i = 0
while k > 0 and i < n:
	x = nums.index(max(nums[i:]))
	(nums[i], nums[x]) = (nums[x], nums[i])
	if i != x:
		k = k - 1
	i = i + 1
print(' '.join(map(str, nums)))


(n, k) = list(map(int, str(input()).split()))
nums = list(map(int, str(input()).split()))
for i in range(1, n + 1)[::-1]:
	if nums[n - i] == i:
		continue
	for j in range(n - i, n):
		if nums[j] == i:
			(nums[j], nums[n - i]) = (nums[n - i], nums[j])
			break
	k -= 1
	if k == 0:
		break
print(' '.join(list(map(str, nums))))


import sys
(N, K) = (int(_) for _ in input().split())
A = list((int(_) for _ in input().split()))
for i in range(N):
	if K == 0:
		break
	m = max(A[i:])
	if A[i] != m:
		im = A.index(m)
		(A[i], A[im]) = (A[im], A[i])
		K -= 1
print(' '.join((str(_) for _ in A)))


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


def largeP(A, N, K):
	c = 0
	for i in range(0, N):
		if c == K:
			break
		v = max(A[i:])
		si = A.index(v)
		if A[i] != v:
			(A[i], A[si]) = (A[si], A[i])
			c += 1
	return ' '.join([str(item) for item in A])
(N, K) = [int(item) for item in input().split(' ')]
A = [int(item) for item in input().split(' ')]
print(largeP(A, N, K))


def largest_permutation(perm, swaps):
	if swaps >= len(perm):
		return list(reversed(range(1, len(perm) + 1)))
	i = 0
	while i < swaps < len(perm):
		ind = perm.index(len(perm) - i)
		if ind == i:
			swaps += 1
		else:
			(perm[i], perm[ind]) = (perm[ind], perm[i])
		i += 1
	return perm
(N, K) = (int(s) for s in input().split(' '))
p = [int(s) for s in input().split(' ')]
print(' '.join((str(s) for s in largest_permutation(p, K))))


def get_data():
	(n, k) = map(int, input().split())
	perm = [int(x) for x in input().split()]
	i = 0
	while k > 0 and i < n:
		p_m = max(perm[i:])
		if p_m == perm[i]:
			i += 1
		else:
			tmp = p_m
			perm[perm.index(p_m)] = perm[i]
			perm[i] = p_m
			k -= 1
			i += 1
	for e in perm:
		print(e, end=' ')
get_data()


def main():
	var = input().split()
	(N, K) = (int(var[0]), int(var[1]))
	var = input().split()
	arr = []
	for i in range(0, N):
		arr.append(int(var[i]))
	idx1 = 0
	count = 0
	while count < K and idx1 < N:
		idx2 = N - 1
		for i in range(N - 1, idx1 - 1, -1):
			if arr[idx2] < arr[i]:
				idx2 = i
				if arr[i] == '9':
					break
		if arr[idx1] < arr[idx2]:
			(arr[idx1], arr[idx2]) = (arr[idx2], arr[idx1])
			count += 1
		idx1 += 1
	st = ''
	for i in range(0, N):
		st += str(arr[i]) + ' '
	print(st)
main()


temp = list(map(int, input().split()))
n = temp[0]
k = temp[1]
values = list(map(int, input().split()))
tempo = values[:]
tempo.sort(reverse=True)
if k > n:
	k = n
count = 0
i = 0
while count < k and i < n:
	l = tempo[i]
	j = values.index(l)
	if j != i:
		dummy = values[j]
		values[j] = values[i]
		values[i] = dummy
		count = count + 1
	i = i + 1
c = ' '.join((str(x) for x in values))
print(c)


[N, K] = list(map(int, input().split()))
arr = list(map(int, input().split()))
sorted_arr = sorted(arr, reverse=True)
i = 0
while i < N and K > 0:
	if sorted_arr[i] != arr[i]:
		arr[arr.index(sorted_arr[i])] = arr[i]
		arr[i] = sorted_arr[i]
		K = K - 1
	i = i + 1
print(' '.join(map(str, arr)))


(n, k) = map(int, input().split())
l = [int(a) for a in input().split()]
p = [0 for i in range(n)]
for i in range(n):
	p[n - l[i]] = i
i = 0
while k > 0 and i < n:
	if p[i] != i:
		t = l[i]
		l[i] = l[p[i]]
		l[p[i]] = t
		p[n - t] = p[i]
		p[i] = i
		k -= 1
	i += 1
print(' '.join((str(e) for e in l)))


(n, k) = input().split()
(n, k) = (int(n), int(k))
perm = input().split()
perm = [int(i) for i in perm]
ind = 0
while k > 0 and ind < n:
	largest = max(perm[ind:])
	largest_index = perm.index(largest)
	if largest > perm[ind]:
		(perm[ind], perm[largest_index]) = (perm[largest_index], perm[ind])
		k -= 1
	ind += 1
perm = [str(i) for i in perm]
perm = ' '.join(perm)
print(perm)


inf = list(map(int, input().split()))
k = inf[1]
arr = list(map(int, input().split()))
req = sorted(arr, reverse=True)
a = 0
for i in range(len(arr)):
	if arr[i] != req[i]:
		for j in range(i, len(arr)):
			if arr[j] == req[i]:
				break
		(arr[i], arr[j]) = (arr[j], arr[i])
		k -= 1
	if k == 0:
		break
for i in arr:
	print(i, end=' ')


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
if K >= N - 1:
	print(*sorted(A, reverse=True), sep=' ')
else:
	X = sorted(A)
	(i, swaps) = (0, 0)
	while swaps < K:
		x = X.pop()
		if A[i] != x:
			A[A.index(x)] = A[i]
			A[i] = x
			swaps += 1
		i += 1
	print(*A, sep=' ')


(size, swaps) = [int(i) for i in input().split()]
array = [int(i) for i in input().split()]
start = 0
while start < size and swaps:
	largest = max(array[start:])
	max_index = [a for (a, j) in enumerate(array) if j == largest]
	if max_index[0] > start:
		(array[start], array[max_index[0]]) = (array[max_index[0]], array[start])
		swaps -= 1
	start += 1
print(' '.join([str(i) for i in array]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ind = n * [0]
for i in range(n):
	val = arr[i]
	ind[val - 1] = i
for i in range(n):
	if arr[i] == n - i:
		continue
	else:
		temp = arr[i]
		i1 = ind[n - 1 - i]
		arr[i] = n - i
		arr[i1] = temp
		ind[temp - 1] = i1
		ind[n - 1 - i] = i
		k -= 1
		if k == 0:
			break
print(' '.join([str(i) for i in arr]))


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] != n - i:
		max_idx = arr.index(n - i, i)
		(arr[i], arr[max_idx]) = (arr[max_idx], arr[i])
		k -= 1
	if k == 0:
		break
print(' '.join(map(str, arr)))


(n, swaps) = [int(x) for x in input().split(' ')]
array = [int(x) for x in input().split(' ')]
i = 0
k = 0
while k < swaps and i < len(array):
	m = max(array[i:])
	j = array.index(m)
	if m > array[i]:
		temp = array[j]
		array[j] = array[i]
		array[i] = temp
		k = k + 1
	i = i + 1
output = [str(x) for x in array]
print(' '.join(output))


(N, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(N):
	if A[i] != N - i:
		x = A.index(N - i)
		(A[x], A[i]) = (A[i], A[x])
		k -= 1
		if k == 0:
			break
for i in range(N):
	print(A[i], end=' ')
print()