

'''simple docstring'''



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
SCREAMING_SNAKE_CASE_    =   [[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__       (      a__)		->    list[int]:



    """simple docstring"""







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

def   lowerCamelCase__       (      a__			,      a__			,      a__)		->    list[int]:



    """simple docstring"""







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

def   lowerCamelCase__       (      a__)		->    Image.Image:



    """simple docstring"""







    _snake_case : Dict												=		Image.new('RGB'			,      (len(cells[0]), len(a__)))
    _snake_case : Optional[int]												=		img.load()
    # Generates image
    for w in range(img.width):
        for h in range(img.height):
            _snake_case : Union[str, Any]												=		2_5_5 - int(2_5_5 * cells[h][w])
            _snake_case : Optional[int]												=		(color, color, color)
    return img


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






'''simple docstring'''



from __future__ import annotations

def   lowerCamelCase__       (      a__)		->    int | float:



    """simple docstring"""







    _snake_case : int												=		sorted(a__)
    _snake_case : List[str]												=		len(a__)
    _snake_case : Union[str, Any]												=		length >> 1
    return (
        (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
        if length % 2 == 0
        else sorted_list[mid_index]
    )

def   lowerCamelCase__       (      )		->    Union[str, Any]:



    """simple docstring"""







    import doctest

    doctest.testmod()


if __name__ == "__main__":
   main()



