
from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
lowercase__				:				List[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 						A_			(				snake_case				: int			)   ->     list[int]:



						'''simple docstring'''

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




def 						A_			(				snake_case				: list[list[int]]			,   snake_case				: list[int]			,   snake_case				: int			)   ->     list[int]:



						'''simple docstring'''

						__UpperCamelCase  	=      len(cells[0]			)  # 31
						__UpperCamelCase  	=      []
						for i in range(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 						A_			(				snake_case				: list[list[int]]			)   ->     Image.Image:



						'''simple docstring'''

						__UpperCamelCase  	=      Image.new('''RGB'''			,   (len(cells[0]			), len(snake_case			))			)
						__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__":
				lowercase__				:				Dict						=      bin(int(input("Rule:\n").strip()))[2:]
				lowercase__				:				Optional[int]						=      format_ruleset(int(rule_num))
				for time in range(1_6):
								CELLS.append(new_generation(CELLS, rule, time))
				lowercase__				:				Union[str, Any]						=      generate_image(CELLS)
				# Uncomment to save the image
				# img.save(f"rule_{rule_num}.png")
				img.show()






"""simple docstring"""







def        __lowerCAmelCase							(_UpperCamelCase = 10**6						):

	if n <= 0:
		raise ValueError('Please enter an integer greater than 0'						)

	__lowerCAmelCase     :		Optional[Any]		     = list(range(n + 1						)						)
	for number in range(2			,    n + 1						):
		if phi[number] == number:
			phi[number] -= 1
			for multiple in range(number * 2			,    n + 1			,    _UpperCamelCase						):
				__lowerCAmelCase     :		Tuple		     = (phi[multiple] // number) * (number - 1)

	__lowerCAmelCase     :		Any		     = 1
	for number in range(1			,    n + 1						):
		if (answer / phi[answer]) < (number / phi[number]):
			__lowerCAmelCase     :		List[Any]		     = number

	return answer


if __name__ == "__main__":
							print(solution())