# Problem Description
This is a grid infection spread simulation problem. Given an n×n grid with an initial infection point, we need to calculate how many cells will be infected at the given `day`. The infection spreads to adjacent cells (up, down, left, right) each day, but cannot spread beyond the grid boundaries.

# Visual Facts
1. The image shows a 6×6 grid over 4 days of infection spread
2. Initial infection point is at coordinate (3, 5) on Day 1
3. White cells represent healthy cells
4. Blue cells represent infected cells
5. Grid coordinates are labeled from 1 to 6 for both rows and columns
6. The number of infected cells per day:
   - Day 1: 1 cell
   - Day 2: 5 cells
   - Day 3: 12 cells
   - Day 4: 20 cells

# Visual Patterns
1. Infection Spread Pattern:
   - Each infected cell spreads to its four adjacent cells (up, down, left, right) the next day
   - Diagonal spread is not possible
   - Already infected cells remain infected
   - Cells can't spread infection beyond grid boundaries

2. Mathematical Patterns:
   - Without boundary constraints, the number of newly infected cells would follow:
     * Day 1: 1 cell
     * Day 2: 4 new cells (total 5)
     * Day 3: 8 new cells (total 13)
     * Day 4: 12 new cells (total 25)
   - Growth is limited by:
     * Grid boundaries (if n=6, the coordinates of cells are 1 to 6)
     * Previously infected cells (can't infect already infected cells)


# Solution
from typing import Tuple

def solution(n: int, initial_point: Tuple[int, int], day: int) -> int:
    """
    Calculate the area of the blue region.

    Args:
        n: The size of the n x n grid.
        initial_point: A tuple (x, y) representing the starting coordinates of the blue region (1-indexed).
        day: The given status condition.

    Returns:
        The total area of the blue region.
    """
    # Initialize the grid
    grid = [[0] * n for _ in range(n)]

    # Convert initial_point to 0-indexed
    x, y = initial_point[0] - 1, initial_point[1] - 1

    # Set the initial infection point
    grid[x][y] = 1

    # Directions for up, down, left, right
    directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    # Iterate for each day
    for _ in range(day-1):
        new_infections = []
        for i in range(n):
            for j in range(n):
                if grid[i][j] != 1:
                    continue
                # Spread the infection to adjacent cells
                for dx, dy in directions:
                    ni, nj = i + dx, j + dy
                    if 0 <= ni < n and 0 <= nj < n and grid[ni][nj] == 0:
                        new_infections.append((ni, nj))

        # Mark new infections
        for ni, nj in new_infections:
            grid[ni][nj] = 1

    # Count the number of infected cells
    infected_cells = sum(sum(row) for row in grid)

    return infected_cells


# Test Script
def test():
    test_cases = [
        (6, (3, 5), 1, 1),
        (6, (3, 5), 3, 12),
        (6, (3, 5), 4, 20),
        (9, (3, 8), 3, 12),
        (3, (2, 2), 3, 9),
        (6, (1, 6), 6, 21),
        (6, (1, 6), 7, 26),
        (6, (6, 3), 4, 15),
        (6, (6, 3), 5, 21),
    ]
    for grid_size, initial_point, t, expected_output in test_cases:
        try:
            output = solution(grid_size, initial_point, t)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`grid_size`: {grid_size}\n"
                f"`initial_point`: {initial_point}\n"
                f"`t`: {t}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

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

test()