

from __future__ import annotations

from PIL import Image

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




	'''simple docstring'''




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






def        lowerCamelCase_  (				UpperCAmelCase_				:  list[list[int]]				,							UpperCAmelCase_				:  list[int]				,							UpperCAmelCase_				:  int						)    ->					list[int]:




	'''simple docstring'''




	_UpperCamelCase :		Union[str, Any]								=    len(cells[0]						)  # 31
	_UpperCamelCase :		List[str]								=    []
	for i in range(snake_case_						):
		# 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 :		int								=    0 if i == population - 1 else cells[time][i + 1]
		# Define a new cell and add it to the new generation
		_UpperCamelCase :		Any								=    7 - int(F'''{left_neighbor}{cells[time][i]}{right_neighbor}'''				,							2						)
		next_generation.append(rule[situation]						)
	return next_generation






def        lowerCamelCase_  (				UpperCAmelCase_				:  list[list[int]]						)    ->					Image.Image:




	'''simple docstring'''




	_UpperCamelCase :		str								=    Image.new('RGB'				,							(len(cells[0]						), len(snake_case_						))						)
	_UpperCamelCase :		int								=    img.load()
	# Generates image
	for w in range(img.width						):
		for h in range(img.height						):
			_UpperCamelCase :		List[str]								=    2_5_5 - int(2_5_5 * cells[h][w]						)
			_UpperCamelCase :		List[str]								=    (color, color, color)
	return img


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









'''simple docstring'''






class 	_lowerCAmelCase     :






		'''simple docstring'''
		def __init__(						self							:       int      ,		UpperCamelCase_							:       int		)      ->			None:







									'''simple docstring'''





									_lowercase							:		Optional[Any]				=   data
									_lowercase							:		int
									_lowercase							:		Node





def 				_SCREAMING_SNAKE_CASE(					snake_case_    :     Node  )		->None:






							'''simple docstring'''
							_lowercase							:		str				=   0
							_lowercase							:		List[Any]				=   x





def 				_SCREAMING_SNAKE_CASE(					snake_case_    :     Node ,       snake_case_    :     Node  )		->None:






							'''simple docstring'''
							_lowercase			, _lowercase							:		Union[str, Any]				=   find_set(snake_case_  ), find_set(snake_case_  )
							if x == y:
														return

							elif x.rank > y.rank:
														_lowercase							:		Optional[Any]				=   x
							else:
														_lowercase							:		Optional[int]				=   y
														if x.rank == y.rank:
																					y.rank += 1





def 				_SCREAMING_SNAKE_CASE(					snake_case_    :     Node  )		->Node:






							'''simple docstring'''
							if x != x.parent:
														_lowercase							:		str				=   find_set(x.parent  )
							return x.parent





def 				_SCREAMING_SNAKE_CASE(					snake_case_    :     Node  )		->set:






							'''simple docstring'''
							_lowercase							:		str				=   ({0, 1, 2}, {3, 4, 5})
							for s in sets:
														if node.data in s:
																					return s
							_lowercase							:		Optional[Any]				=   F"{node.data} is not in {sets}"
							raise ValueError(snake_case_  )





def 				_SCREAMING_SNAKE_CASE(					)		->None:






							'''simple docstring'''
							_lowercase							:		Any				=   [Node(snake_case_  ) for i in range(6  )]
							for v in vertex:
														make_set(snake_case_  )

							union_set(vertex[0] ,       vertex[1]  )
							union_set(vertex[1] ,       vertex[2]  )
							union_set(vertex[3] ,       vertex[4]  )
							union_set(vertex[3] ,       vertex[5]  )

							for nodea in vertex:
														for nodea in vertex:
																					if find_python_set(snake_case_  ).isdisjoint(find_python_set(snake_case_  )  ):
																												assert find_set(snake_case_  ) != find_set(snake_case_  )
																					else:
																												assert find_set(snake_case_  ) == find_set(snake_case_  )


if __name__ == "__main__":
						test_disjoint_set()



