






"""simple docstring"""





def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						int:
    """simple docstring"""

    return len_board * len_board_column * row + column







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						)       ->						bool:
    """simple docstring"""

    if board[row][column] != word[word_index]:
        return False

    if word_index == len(SCREAMING_SNAKE_CASE       ) - 1:
        return True

    UpperCamelCase__								=     [(0, 1), (0, -1), (-1, 0), (1, 0)]
    UpperCamelCase__								=     len(SCREAMING_SNAKE_CASE       )
    UpperCamelCase__								=     len(board[0]       )
    for direction in traverts_directions:
        UpperCamelCase__								=     row + direction[0]
        UpperCamelCase__								=     column + direction[1]
        if not (0 <= next_i < len_board and 0 <= next_j < len_board_column):
            continue

        UpperCamelCase__								=     get_point_key(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )
        if key in visited_points_set:
            continue

        visited_points_set.add(SCREAMING_SNAKE_CASE       )
        if exits_word(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						word_index + 1			,						SCREAMING_SNAKE_CASE       ):
            return True

        visited_points_set.remove(SCREAMING_SNAKE_CASE       )

    return False







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						bool:
    """simple docstring"""

    UpperCamelCase__								=     (
        'The board should be a non empty matrix of single chars strings.'
    )

    UpperCamelCase__								=     len(SCREAMING_SNAKE_CASE       )
    if not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ) or len(SCREAMING_SNAKE_CASE       ) == 0:
        raise ValueError(SCREAMING_SNAKE_CASE       )

    for row in board:
        if not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ) or len(SCREAMING_SNAKE_CASE       ) == 0:
            raise ValueError(SCREAMING_SNAKE_CASE       )

        for item in row:
            if not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ) or len(SCREAMING_SNAKE_CASE       ) != 1:
                raise ValueError(SCREAMING_SNAKE_CASE       )

    # Validate word
    if not isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ) or len(SCREAMING_SNAKE_CASE       ) == 0:
        raise ValueError(
            'The word parameter should be a string of length greater than 0.'       )

    UpperCamelCase__								=     len(board[0]       )
    for i in range(SCREAMING_SNAKE_CASE       ):
        for j in range(SCREAMING_SNAKE_CASE       ):
            if exits_word(
                SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						0			,						{get_point_key(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )}       ):
                return True

    return False


if __name__ == "__main__":
  import doctest

  doctest.testmod()












"""simple docstring"""





from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
A__       :			str=						[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						list[int]:
    """simple docstring"""

    return [int(SCREAMING_SNAKE_CASE       ) for c in F'{ruleset:08}'[:8]]







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						list[int]:
    """simple docstring"""

    UpperCamelCase__								=     len(cells[0]       )  # 31
    UpperCamelCase__								=     []
    for i in range(SCREAMING_SNAKE_CASE       ):
        # Get the neighbors of each cell
        # Handle neighbours outside bounds by using 0 as their value
        UpperCamelCase__								=     0 if i == 0 else cells[time][i - 1]
        UpperCamelCase__								=     0 if i == population - 1 else cells[time][i + 1]
        # Define a new cell and add it to the new generation
        UpperCamelCase__								=     7 - int(F'{left_neighbor}{cells[time][i]}{right_neighbor}'			,						2       )
        next_generation.append(rule[situation]       )
    return next_generation







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						Image.Image:
    """simple docstring"""

    UpperCamelCase__								=     Image.new('RGB'			,						(len(cells[0]       ), len(SCREAMING_SNAKE_CASE       ))       )
    UpperCamelCase__								=     img.load()
    # Generates image
    for w in range(img.width       ):
        for h in range(img.height       ):
            UpperCamelCase__								=     2_55 - int(2_55 * cells[h][w]       )
            UpperCamelCase__								=     (color, color, color)
    return img


if __name__ == "__main__":
  A__       :			Optional[int]=						bin(int(input("""Rule:\n""").strip()))[2:]
  A__       :			str=						format_ruleset(int(rule_num))
  for time in range(16):
    CELLS.append(new_generation(CELLS, rule, time))
  A__       :			Tuple=						generate_image(CELLS)
  # Uncomment to save the image
  # img.save(f"rule_{rule_num}.png")
  img.show()




