



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    lowerCAmelCase_  (lowerCAmelCase__:		Any     ):





			"""simple docstring"""


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







def    lowerCAmelCase_  (lowerCAmelCase__:		List[Any]		,	lowerCAmelCase__:		Tuple		,	lowerCAmelCase__:		Union[str, Any]     ):





			"""simple docstring"""


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







def    lowerCAmelCase_  (lowerCAmelCase__:		int     ):





			"""simple docstring"""


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


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











import decimal







def    lowerCAmelCase_  ():





			"""simple docstring"""


			UpperCAmelCase_:		Union[str, Any]       			=    0
			UpperCAmelCase_:		Optional[Any]       			=    decimal.Context(prec=1_0_5     )
			for i in range(2		,	1_0_0     ):
						UpperCAmelCase_:		str       			=    decimal.Decimal(lowerCAmelCase__     )
						UpperCAmelCase_:		Any       			=    number.sqrt(lowerCAmelCase__     )
						if len(str(lowerCAmelCase__     )     ) > 1:
									answer += int(str(lowerCAmelCase__     )[0]     )
									UpperCAmelCase_:		str       			=    str(lowerCAmelCase__     )[2:1_0_1]
									answer += sum(int(lowerCAmelCase__     ) for x in sqrt_number_str     )
			return answer


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	print(F'''{solution() = }''')






