def main(): import sys input = sys.stdin.read().split() idx = 0 n = int(input[idx]) idx += 1 k = int(input[idx]) idx += 1 a = list(map(int, input[idx:idx + n])) idx += n if k == 0: print(' '.join(map(str, a))) return states = {} history = [a.copy()] states[tuple(a)] = 0 current = a.copy() step = 0 while step < k: s = current[0] next_arr = current[1:s+1] + [current[0]] + current[s+1:] step += 1 current = next_arr current_tuple = tuple(current) if current_tuple in states: prev_step = states[current_tuple] cycle_length = step - prev_step remaining_steps = k - prev_step effective_step = prev_step + (remaining_steps % cycle_length) print(' '.join(map(str, history[effective_step]))) return else: states[current_tuple] = step history.append(current.copy()) print(' '.join(map(str, current))) if __name__ == "__main__": main()