import itertools


def count_alive_neighbors(alive_cells: set, coords: tuple) -> int:
    """return the number of alive neighbors of a given cell"""
    alive = 0
    ranges = ((c-1, c, c+1) for c in coords)
    for cell in itertools.product(*ranges):
        if cell in alive_cells:
            alive += 1
    if coords in alive_cells:
        alive -= 1
    return alive