
"""simple docstring"""
from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_a   :      Dict       =				[[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 					a__ ( a :					Dict		):

  """simple docstring"""







  return [int(__lowercase		) for c in f'{ruleset:08}'[:8]]
def 					a__ ( a :					Optional[int]							,  a :					str							,  a :					Any		):

  """simple docstring"""







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

  """simple docstring"""







  _snake_case  :    int            = Image.new("RGB"							,  (len(cells[0]		), len(__lowercase		))		)
  _snake_case  :    List[str]            = img.load()
  # Generates image
  for w in range(img.width		):
    for h in range(img.height		):
      _snake_case  :    Union[str, Any]            = 255 - int(255 * cells[h][w]		)
      _snake_case  :    Tuple            = (color, color, color)
  return img


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





"""simple docstring"""


def   a__			(					__lowercase  ,      __lowercase )						->						Tuple:
				_A       	=      1
				while b > 0:
								if b & 1:
												res *= a

								a *= a
								b >>= 1

				return res






def   a__			(					__lowercase  ,      __lowercase  ,      __lowercase )						->						Optional[Any]:
				_A       	=      1
				while b > 0:
								if b & 1:
												_A       	=      ((res % c) * (a % c)) % c

								a *= a
								b >>= 1

				return res