single_line = input().split() list_data = [num for num in single_line] command_info = input() list_index = list() elements_to_move = list() new_substrings = list() while command_info != "3:1": command = command_info.split()[0] if command == "merge": start_Index = command_info.split()[1] start_Index = int(start_Index) end_Index = command_info.split()[2] end_Index = int(end_Index) if len(list_data) < start_Index and len(list_data) < end_Index: command_info = input() continue elif start_Index < 0: start_Index == 0 elif end_Index >= len(list_data) > start_Index: end_Index = len(list_data) - 1 # Extract elements by index for i in range(start_Index, end_Index + 1): list_index.append(i) elements_to_move = [list_data[i] for i in sorted(list_index, reverse=True)] elements_to_move.reverse() result = ''.join(str(item) for item in elements_to_move) elements_to_move.clear() # remove elements from list_data for i in sorted(list_index, reverse=True): del list_data[i] list_index.clear() # Insert the extracted elements to list_data list_data.insert(start_Index, result) elif command == "divide": index_data = command_info.split()[1] index_data = int(index_data) partition = command_info.split()[2] partition = int(partition) text = list_data[index_data] list_data.pop(index_data) # Determine the length of each substring chunk_size = len(text)//partition # Divide the string into 'partition' number of substrings substrings = [text[i:i + chunk_size] for i in range(0, len(text), chunk_size)] # If there are any leftover characters, add them to the last substring new_substrings = ' '.join(substrings) if len(substrings) > partition: new_substrings = substrings[: partition - 1] del substrings[: partition -1] result_list = [''.join(str(item) for item in substrings)] new_substrings += result_list result_list.clear() new_substrings = ' '.join(new_substrings) list_data.insert(index_data, new_substrings) new_substrings = list() substrings.clear() command_info = input() joined_string = ' '.join(list_data) print(joined_string)