# Problem Description
This appears to be a block transformation problem where:
- We start with an initial vertical stack of blocks labeled with letters
- We need to perform a series of transformations based on given operations
- Each operation appears to involve some form of block movement or swapping
- The goal is to determine the final arrangement of blocks after all operations

# Visual Facts
1. Each example shows step-by-step transformations of blocks
2. Blocks are arranged vertically and labeled with letters (A, B, C, D)
3. Each position has an index starting from 0 at the top
4. Operations are represented as a list of integers
5. Example 1 shows Operations=[0]
6. Example 2 shows Operations=[0]
7. Example 3 shows Operations=[2,0,2]
8. Blue highlighting appears around certain blocks during transformations
9. Dotted arrows show where blocks move to
10. Each transformation step maintains the total number of blocks

# Visual Patterns
1. Block Movement Pattern:
   - When an operation occurs, the block at the specified index gets "highlighted" (blue borders)
   - The single block directly below the highlighted block shifts up to the top, all other blocks remain in place

2. Operation Index Pattern:
   - The operation number indicates which block position (0-based index) initiates the transformation
   - In Example 1: operation [0] moves block A to the top
   - In Example 2: operation [0] moves block B to top
   - In Example 3: sequence [2,0,2] shows multiple transformations

3. Transformation Rules:
   - Only one block moves per operation. Suppose the operation is at index i, then the block at position i+1 moves to the top (index 0), and the blocks from 0 to i are moved to 1 to i+1.
   - Original relative order of non-moved blocks is preserved
   - The total height of the stack remains constant


# Solution
from typing import List

def solution(initial_blocks: List[str], operations: List[int]) -> List[str]:
    """
    Calculates the final arrangement of blocks after applying a series of transformation operations.   

    Args:
        initial_blocks: List of strings representing the initial order of blocks from top to bottom
        operations: List of integers, indicating 0-based index positions involved in a transformation

    Returns:
        List of strings representing the final arrangement of blocks after all operations
    """
    current_stack = initial_blocks[:]

    for op in operations:
        # Determine the range of blue blocks based on the last block's index
        k = op + 1  # Include the block at index `op`
        
        if k > len(current_stack):
            raise ValueError(f"Operation {op} cannot be performed on the current stack: {current_stack}")

        # Split the current stack into blue blocks and remaining stack
        blue_blocks = current_stack[:k]
        remaining_stack = current_stack[k:]

        # Move the first block of the remaining stack to the top (if any)
        if remaining_stack:
            block_to_move = remaining_stack.pop(0)
            current_stack = [block_to_move] + blue_blocks + remaining_stack
        else:
            current_stack = blue_blocks

    return current_stack


# Test Script
def test():
    test_cases = [
        (
            ["A", "B", "C"],
            [],
            ["A", "B", "C"]
        ),
        
        (
            ["B1", "C"],
            [0],
            ["C", "B1"]
        ),
        
        (
            ["B1", "B2", "C", "D"],
            [1],
            ["C", "B1", "B2", "D"]
        ),
        
        (
            ["B1", "B2", "C", "D", "E"],
            [1, 1],
            ["B2", "C", "B1", "D", "E"]
        ),
        
        (
            ["B1", "B2"],
            [1],
            ["B1", "B2"]
        ),
        
        (
            ["B1", "B2", "C", "D", "E"],
            [1, 1],
            ["B2", "C", "B1", "D", "E"]
        ),
        
        (
            ["B1", "B2", "C", "D", "E", "F"],
            [1, 1, 1],
            ["B1", "B2", "C", "D", "E", "F"]
        ),
        
        (
            ["C", "A", "B", "D"],
            [1, 1],
            ["A", "B", "C", "D"]
        ),
        (
            ["C","B","D","A"],
            [0,2,1],
            ['C', 'A', 'B', 'D']
        )
    ]

    for idx, (initial_blocks, operations, expected_output) in enumerate(test_cases, 1):
        try:
            output = solution(initial_blocks, operations)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`initial_blocks`: {initial_blocks}\n"
                f"`operations`: {operations}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`initial_blocks`: {initial_blocks}\n"
                f"`operations`: {operations}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()