#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the rotLeft function below.
def rotLeft(a, d):
    list=[]
    swap1 =a[0:(d)]
    swap2=a[d:]
    list= swap2+swap1
    return(list)

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    nd = input().split()

    n = int(nd[0])

    d = int(nd[1])

    a = list(map(int, input().rstrip().split()))

    result = rotLeft(a, d)
    
    #convert result to string
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    
    #convert result list to string method 1
    str2 = ' '.join(map(str,result))
    print(str2)
    #convert result list to string method 2
    str1 = ' '.join(str(e) for e in result)
    print(str1)

    fptr.close()
