# Problem Description
- The problem involves calculating the total number of hexagonal cells in a specific pattern for a given value of n
- Input n is an integer between 1 and 1000
- The pattern grows symmetrically from the center, forming an hourglass-like shape
- Need to find a formula that gives the total count of hexagonal cells for any valid n

# Visual Facts
1. The image shows three different patterns for n=1, 2, and 3
2. For n=1:
   - Total cells: 5
   - Central column has 1 cell
   - Left and right columns each have 2 cells

3. For n=2:
   - Total cells: 11
   - Pattern has 5 columns
   - Outer columns have 3 cells each

4. For n=3:
   - Total cells: 19
   - Pattern has 7 columns
   - Outer columns have 4 cells each

# Visual Patterns
1. Growth Pattern:
   - Each increment of n adds 2 new columns (one on each side)
   - Number of columns = 2n + 1
   - For n=1: 3 columns
   - For n=2: 5 columns
   - For n=3: 7 columns

2. Cell Count Pattern:
   - For n=1: 5 cells
   - For n=2: 11 cells = 5 + 6
   - For n=3: 19 cells = 11 + 8
   - The increment between consecutive n values follows: +6, +8

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 input_n, expected_output in test_cases:
        try:
            output = solution(input_n)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`n`: {input_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`: {input_n}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()