



'''simple docstring'''



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
a__						:			Optional[Any]										=			[[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 _lowercase   (  __A       ):



	'''simple docstring'''



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







def _lowercase   (  __A							,__A							,__A       ):



	'''simple docstring'''



	__UpperCamelCase				      =  len(cells[0]       )  # 31
	__UpperCamelCase				      =  []
	for i in range(__A       ):
		# 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 _lowercase   (  __A       ):



	'''simple docstring'''



	__UpperCamelCase				      =  Image.new("""RGB"""							,(len(cells[0]       ), len(__A       ))       )
	__UpperCamelCase				      =  img.load()
	# Generates image
	for w in range(img.width       ):
		for h in range(img.height       ):
			__UpperCamelCase				      =  255 - int(255 * cells[h][w]       )
			__UpperCamelCase				      =  (color, color, color)
	return img


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










'''simple docstring'''



def _lowercase   (  __A							,__A       ):



 '''simple docstring'''



 __UpperCamelCase				      =  1
 while b > 0:
  if b & 1:
   res *= a

  a *= a
  b >>= 1

 return res







def _lowercase   (  __A							,__A							,__A       ):



 '''simple docstring'''



 __UpperCamelCase				      =  1
 while b > 0:
  if b & 1:
   __UpperCamelCase				      =  ((res % c) * (a % c)) % c

  a *= a
  b >>= 1

 return res





