# Problem Description
This is a list transformation problem where we need to implement a special swapping mechanism. Given an input list and a sequence of swap locations, we perform a series of swap operations. Each swap operation, starting from a given index, performs multiple swaps that "reverse" a portion of the list from that index onwards. The operation maintains a specific mathematical pattern for determining which elements to swap.

# Visual Facts
1. Input List: [6, 3, 7, 9, 2, 3, 7, 0]
2. Swap Locations: [2, 1, 6, 3]
3. Four distinct steps are shown, each corresponding to a swap location
4. Each step shows:
   - Current state of the list
   - Location where swap starts (marked with red line)
   - Arrows showing element movements
   - Resulting state after the swap
5. List length remains constant at 8
6. All elements are preserved during swaps
7. Red vertical lines mark the starting position of each swap
8. Double-headed arrows indicate which elements are being swapped

# Visual Patterns
1. Swap Operation Pattern:
   - For each swap location i, multiple pairs of elements are swapped
   - The swaps "mirror" elements around the middle of the remaining sublist
   - Elements between position i and end of list get reversed

2. Mathematical Pattern for Swaps:
   - For swap location i:
     * First pair: swap(i, n-1)
     * Second pair: swap(i+1, n-2)
     * Third pair: swap(i+2, n-3)
     * Continue until reaching middle
   - Where n is the length of the list


# Solution
from typing import List

def solution(l: List[int], swap_locations: List[int]) -> List[int]:
    """
    Modifies a list by swapping elements according to the specified swap locations.

    Parameters:
        l (List[int]): The input list to be modified
        swap_locations (List[int]): A list of indices indicating where elements should be swapped

    Returns:
        List[int]: The modified list after performing the swaps.
    """
    for loc in swap_locations:
        l = l[:loc] + l[loc:][::-1]
        
    return l


# Test Script
def test():
    test_cases = [
        ([10, 20, 30, 40, 50], [2, 3], [10, 20, 50, 30, 40]),
        ([5, 15, 25, 35, 45, 55], [1, 4], [5, 55, 45, 35, 15, 25]),
        ([7, 14, 21, 28, 35, 42, 49], [2, 5, 3], [7, 14, 49, 28, 21, 35, 42]),
        ([8, 16, 24, 32, 40, 48, 56, 64], [6, 2], [8, 16, 56, 64, 48, 40, 32, 24]),
        ([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [4, 7, 2], [1, 3, 13, 11, 9, 15, 17, 19, 7, 5]),
        ([99, 88, 77, 66, 55, 44, 33, 22, 11], [3, 6, 0], [44, 55, 66, 33, 22, 11, 77, 88, 99]),
        ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [9, 0, 5], [10, 9, 8, 7, 6, 1, 2, 3, 4, 5]),
        ([100, 200, 300, 400, 500], [1, 3, 0], [300, 200, 400, 500, 100]),
        ([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [4, 2, 7, 1], [9, 0, 6, 7, 1, 2, 3, 4, 5, 8]),
        ([1, 4, 9, 16, 25, 36, 49, 64, 81, 100], [2, 4, 6, 8], [1, 4, 100, 81, 9, 16, 64, 49, 25, 36])
    ]

    for l, swap_locations, expected_output in test_cases:
        try:
            output = solution(l, swap_locations)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`l`: {l}\n"
                f"`swap_locations`: {swap_locations}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`l`: {l}\n"
                f"`swap_locations`: {swap_locations}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()