def neighbors4(grid, x, y) -> list[tuple[int, int]]:
    """Return the horizontal and vertical neighbors of the given
    position on the given grid. This function ignores diagonal
    neighbors.
    """
    max_y = len(grid)
    max_x = len(grid[0])
    result = [(x-1, y), (x, y-1), (x, y+1), (x+1, y)]
    result = [(x, y) for x, y in result if 0 <= x < max_x and 0 <= y < max_y]
    return result