from common import parse # , pretty_print def move(stacks: list[list[str]], operation: tuple[int, int, int]) -> list[list[str]]: # print(f"move {operation[0]} from {operation[1]} to {operation[2]}") for i in range(operation[0]): num = stacks[operation[1] - 1].pop() stacks[operation[2] - 1].append(num) return stacks def solve(input: tuple[list[list[str]], list[tuple[int, int, int]]]) -> str: stacks, operations = input # pretty_print(stacks) for operation in operations: stacks = move(stacks, operation) # pretty_print(stacks) return "".join(map(lambda x: x[len(x) - 1] if len(x) != 0 else "", stacks)) def main(): print(solve(parse("input"))) if __name__ == "__main__": main()