# Problem Description
The problem involves modifying a string containing paired parentheses by deleting a character at a specified index position. The input string appears to contain regular parentheses "(" and ")" and seems to follow specific pairing rules. The function needs to return the modified string after removing the character at the given index.

# Visual Facts
1. The image shows 4 different test cases labeled Case 1 through Case 4
2. Each case shows:
   - An input string 's'
   - A deletion index (marked in red)
   - The resulting string after deletion
3. The character to be deleted is highlighted in blue in each case
4. All input strings contain only parentheses characters
5. All output strings maintain valid parentheses pairing
6. The deletion indices shown are: 1, 5, 1, and 3 for cases 1-4 respectively

# Visual Patterns
1. Input String Pattern:
   - All input strings contain properly paired parentheses
   - The blue highlighted the paired parentheses character to be deleted
   - The strings maintain balanced parentheses before and after deletion

2. Deletion Pattern:
   - Given an index position, the character at that position is deleted, as well as its paired character
   - The deletion preserves the validity of parentheses pairing
   - For example, in Case 2, the given string is "()(())" and the index is 5. The character at index 5 is ")" and its paired character "(" is at index 2, both are deleted, the resulting string is "()()"


# Solution
def solution(s: str, index: int) -> str:
    """
    Modifies a string based on a given index position.

    Parameters:
        s (str): The input string containing only two distinct character types
        index (int): The zero-based index position where modification occurs

    Returns:
        str: The modified string
    """
    stack = [] 
    for i, char in enumerate(s):
        if char == '(':
            stack.append(i)
        elif char == ')':
            left_index = stack.pop()
            if left_index == index or i == index:
                return s[:left_index] + s[left_index + 1:i] + s[i + 1:]
    return s


# Test Script
def test():
    test_cases = [
        ("()", 0, ""),
        ("()", 1, ""),
        ("(())", 0, "()"),
        ("(())", 3, "()"),
        ("(()())", 1, "(())"),
        ("((()))", 4, "(())"),
        ("(()(()))", 2, "((()))"),
        ("(()(()))", 5, "(()())"),
        ("(()())(()())", 6, "(()())()()"),
        ("(()())(()())", 9, "(()())(())"),
    ]

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

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

test()