def main(): import sys N, K = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) if K == 0: print(' '.join(map(str, A))) return history = {} current = A.copy() history[tuple(current)] = 0 steps = 0 found_cycle = False while steps < K: s_prev = current[0] m = s_prev + 1 next_arr = current[1:m] + [current[0]] + current[m:] steps += 1 key = tuple(next_arr) if key in history: prev_step = history[key] cycle_len = steps - prev_step remaining = K - steps remaining %= cycle_len K = prev_step + remaining current = next_arr.copy() for _ in range(K - prev_step): s_prev = current[0] m = s_prev + 1 next_arr = current[1:m] + [current[0]] + current[m:] current = next_arr.copy() print(' '.join(map(str, current))) return else: history[key] = steps current = next_arr.copy() print(' '.join(map(str, current))) if __name__ == "__main__": main()