# Problem Description
- Calculate 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 forms a symmetrical hourglass-like shape with hexagonal cells
- Need to find a formula for counting total hexagons for any valid n

# Visual Facts
1. Pattern for n=1:
   - Contains 5 hexagonal cells
   - Forms a compact hourglass shape
   - 2 cells in top row
   - 1 cell in middle
   - 2 cells in bottom row

2. Pattern for n=2:
   - Contains 11 hexagonal cells
   - 3 cells in top row
   - 5 cells in middle section
   - 3 cells in bottom row

3. Pattern for n=3:
   - Contains 19 hexagonal cells
   - 4 cells in top row
   - 11 cells in middle section
   - 4 cells in bottom row

# Visual Patterns
1. Growth Pattern:
   - Each increment of n adds one more cell to top and bottom rows
   - Middle section expands systematically
   - For n=1: top/bottom have 2 cells each
   - For n=2: top/bottom have 3 cells each
   - For n=3: top/bottom have 4 cells each

2. Cell Count Pattern:
   - n=1: 5 cells
   - n=2: 11 cells (increase of 6)
   - n=3: 19 cells (increase of 8)
   - The increment between consecutive n values increases by 2 each time

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()