# Problem Description
This is a cellular infection spread simulation on an n×n grid. Given an initial infection point, we need to calculate the total number of infected cells after t days. The infection spreads following a specific pattern with three states: healthy, latent, and infected. This is more complex than a simple infection spread as it includes a latent period before cells become fully infected.

# Visual Facts
1. Grid size is 6×6 in the example
2. Initial infection point is at (3, 5) marked on Day 1
3. Cells have three possible states:
   - Healthy (white)
   - Latent (striped blue)
   - Infected (solid blue)
4. Day 1: Single infected cell at (3, 5)
5. Day 2: One infected cell surrounded by latent cells
6. Day 3: Five infected cells in a cross pattern
7. Day 4: Five infected cells with latent cells around them
8. Each day's state is shown in a separate grid

# Visual Patterns
1. Infection State Transition:
   - Healthy cells first become latent before becoming infected
   - Cells appear to follow a pattern: Healthy → Latent → Infected
   - The latent period lasts exactly one day before cells become infected

2. Spread Pattern:
   - Infection spreads in four directions (up, down, left, right)
   - No diagonal spread
   - Newly affected cells first enter latent state
   - Latent cells become infected in the next day
   - The spread is bounded by grid boundaries (1 to n)


# Solution
from typing import Tuple

def solution(n: int, initial_point: Tuple[int, int], t: int) -> int:
    """
    Calculate the number of infected cells after t days.

    Input:
    - n: An integer representing the size of the grid (n x n).
    - initial_point: A tuple (x, y) representing the coordinates of the initial infection point. (1-indexed)
    - t: An integer representing the elapsed time in days.

    Output:
    - An integer representing the total number of infected cells after t days (day t+1).
    """
    # 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)]
    new_latents = []
    # Iterate for each day
    for day in range(t):
        new_infections = []
        if new_latents:
            for new_latent in new_latents:
                new_infections.append(new_latent)
            new_latents = []
        else:
            for i in range(n):
                for j in range(n):
                    if grid[i][j] != 1:
                        continue
                    # Spread the infection to adjacent cells
                    else:
                        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_latents.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), 0, 1),
        (6, (3, 5), 2, 5),
        (6, (3, 5), 3, 5),
        (9, (3, 8), 2, 5),
        (3, (2, 2), 2, 5),
        (6, (1, 6), 5, 6),
        (6, (1, 6), 6, 10),
        (6, (6, 3), 3, 4),
        (6, (6, 3), 4, 9),
    ]
    for n, initial_point, t, expected_output in test_cases:
        try:
            output = solution(n, initial_point, t)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`n`: {n}\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"`n`: {n}\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()