
from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
A__       :   Optional[int]   						=					[[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     (   __UpperCamelCase       :  int    ):
			return [int(__UpperCamelCase    ) for c in f'''{ruleset:08}'''[:8]]



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



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


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





import abc
import copy
import dataclasses
from dataclasses import dataclass
from typing import ClassVar, Dict, Type, TypeVar

from ..features import Features


A__       :   Tuple   						=					TypeVar("""T""", bound="""TaskTemplate""")





@dataclass(frozen=__UpperCamelCase					)
class 						lowercase       (  abc.ABC					):
					# `task` is not a ClassVar since we want it to be part of the `asdict` output for JSON serialization
					__a					=    42
					__a					=    42
					__a					=    42
					def lowercase_			(		self ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								return copy.deepcopy(self    )
					@property
					def lowercase_			(		self    ):
								"""simple docstring"""







								return Features(**self.input_schema ,	**self.label_schema    )
					@property
					@abc.abstractmethod
					def lowercase_			(		self    ):
								"""simple docstring"""







								raise NotImplementedError
					@classmethod
					def lowercase_			(		cls ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								lowerCAmelCase__ :    List[Any]				      =			{f.name for f in dataclasses.fields(cls    )}
								return cls(**{k: v for k, v in template_dict.items() if k in field_names}    )



