# Problem Description
- The problem involves calculating the total number of hexagonal cells in a triangular-like pattern for a given value of n
- Input n is an integer between 1 and 1000
- The pattern grows vertically, forming a triangular structure that expands both upward and downward
- Need to find the total count of hexagonal cells for any valid n

# Visual Facts
1. Three patterns are shown for n=1, 2, and 3
2. n=1 pattern:
   - Total of 5 hexagonal cells
   - Forms a butterfly-like shape
   - 2 cells on top, 1 in middle, 2 on bottom

3. n=2 pattern:
   - Total of 11 hexagonal cells
   - 3 cells on top row
   - 5 cells in middle section
   - 3 cells on bottom row

4. n=3 pattern:
   - Total of 19 hexagonal cells
   - 4 cells on top row
   - 11 cells in middle section
   - 4 cells on bottom row

# Visual Patterns
1. Growth Pattern:
   - Top and bottom rows are always symmetrical
   - Number of cells in top/bottom rows = n + 1
   - Middle section expands with each n

2. Recursive Pattern:
   - Middle section of nth pattern contains the entire (n-1)th pattern
   - For n=2: middle section = total cells from n=1 (5)
   - For n=3: middle section = total cells from n=2 (11)

3. Mathematical Pattern:
   - The total number of cells follows the sequence: 5, 11, 19, ...
   - This formula generates the correct sequence:
     - n=1: 1+2*2 = 5
     - n=2: 1+2*2+2*3 = 11
     - n=3: 1+2*2+2*3+2*4 = 19
   - The formula for total cells = 1 + 2*2 + 2*3 + 2*4 + ... + 2*(n+1)


# Solution
def solution(n: int) -> int:
    """
    Refer to the pattern in the figure, calculate the number of cells with the specified n.

    Args:
        n: integer in [1, 1000] 

    Returns:
        int: The number of cells
    """
    return n*(n+3)+1


# Test Script
def test():
    x = lambda x: x*(x+3)+1
    
    test_cases = [
        (1, x(1)),
        (2, x(2)),
        (3, x(3)),
        (8, x(8)),
        (10, x(10)),
        (20, x(20)),
        (21, x(21)),
        (50, x(50)),
        (100, x(100)),
        (1000, x(1000))
    ]
    for n, expected_output in test_cases:
        try:
            output = solution(n)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`n`: {n}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

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

test()