'''simple docstring'''
import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_A		:      List[str]						   =logging.get_logger(__name__)

_A		:      int						   ={
    """facebook/sam-vit-huge""": """https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json""",
    """facebook/sam-vit-large""": """https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json""",
    """facebook/sam-vit-base""": """https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json""",
}




class _lowerCAmelCase			(	UpperCAmelCase__					):







      def __init__(  self  ,    lowercase=256  ,    lowercase=1024  ,    lowercase=16  ,    lowercase=16  ,    lowercase=4  ,    lowercase="gelu"  ,    lowercase=1e-6  ,    **lowercase  ,    ):
        super().__init__(**__lowercase     )
        lowercase				:							Optional[Any]									=   hidden_size
        lowercase				:							List[Any]									=   image_size
        lowercase				:							int									=   patch_size
        lowercase				:							List[str]									=   image_size // patch_size
        lowercase				:							Tuple									=   mask_input_channels
        lowercase				:							Optional[Any]									=   num_point_embeddings
        lowercase				:							Optional[Any]									=   hidden_act
        lowercase				:							str									=   layer_norm_eps





class _lowerCAmelCase			(	UpperCAmelCase__					):







      def __init__(  self  ,    lowercase=256  ,    lowercase="relu"  ,    lowercase=2048  ,    lowercase=2  ,    lowercase=8  ,    lowercase=2  ,    lowercase=3  ,    lowercase=3  ,    lowercase=256  ,    lowercase=1e-6  ,    **lowercase  ,    ):
        super().__init__(**__lowercase     )
        lowercase				:							Any									=   hidden_size
        lowercase				:							str									=   hidden_act
        lowercase				:							int									=   mlp_dim
        lowercase				:							List[Any]									=   num_hidden_layers
        lowercase				:							List[Any]									=   num_attention_heads
        lowercase				:							List[Any]									=   attention_downsample_rate
        lowercase				:							List[Any]									=   num_multimask_outputs
        lowercase				:							int									=   iou_head_depth
        lowercase				:							Any									=   iou_head_hidden_dim
        lowercase				:							Union[str, Any]									=   layer_norm_eps





class _lowerCAmelCase			(	UpperCAmelCase__					):







      def __init__(  self  ,    lowercase=768  ,    lowercase=256  ,    lowercase=12  ,    lowercase=12  ,    lowercase=3  ,    lowercase=1024  ,    lowercase=16  ,    lowercase="gelu"  ,    lowercase=1e-06  ,    lowercase=0.0  ,    lowercase=1e-10  ,    lowercase=True  ,    lowercase=4.0  ,    lowercase=True  ,    lowercase=True  ,    lowercase=14  ,    lowercase=[2, 5, 8, 11]  ,    lowercase=128  ,    lowercase=None  ,    **lowercase  ,    ):
        super().__init__(**__lowercase     )

        lowercase				:							List[Any]									=   hidden_size
        lowercase				:							List[str]									=   output_channels
        lowercase				:							List[Any]									=   num_hidden_layers
        lowercase				:							Dict									=   num_attention_heads
        lowercase				:							List[str]									=   num_channels
        lowercase				:							Dict									=   image_size
        lowercase				:							List[Any]									=   patch_size
        lowercase				:							Union[str, Any]									=   hidden_act
        lowercase				:							Dict									=   layer_norm_eps
        lowercase				:							int									=   attention_dropout
        lowercase				:							Optional[int]									=   initializer_range
        lowercase				:							Dict									=   qkv_bias
        lowercase				:							Any									=   mlp_ratio
        lowercase				:							List[Any]									=   use_abs_pos
        lowercase				:							int									=   use_rel_pos
        lowercase				:							Any									=   window_size
        lowercase				:							int									=   global_attn_indexes
        lowercase				:							int									=   num_pos_feats
        lowercase				:							List[Any]									=   int(hidden_size * mlp_ratio     ) if mlp_dim is None else mlp_dim





class _lowerCAmelCase			(	UpperCAmelCase__					):
      UpperCAmelCase_	:						List[str]	 =       """sam"""
      UpperCAmelCase_	:						Dict	 =       True







      def __init__(  self  ,    lowercase=None  ,    lowercase=None  ,    lowercase=None  ,    lowercase=0.02  ,    **lowercase  ,    ):
        super().__init__(**__lowercase     )
        lowercase				:							Tuple									=   vision_config if vision_config is not None else {}
        lowercase				:							Any									=   prompt_encoder_config if prompt_encoder_config is not None else {}
        lowercase				:							Dict									=   mask_decoder_config if mask_decoder_config is not None else {}

        if isinstance(__lowercase  ,    __lowercase     ):
          lowercase				:							Dict									=   vision_config.to_dict()
        if isinstance(__lowercase  ,    __lowercase     ):
          lowercase				:							Optional[Any]									=   prompt_encoder_config.to_dict()
        if isinstance(__lowercase  ,    __lowercase     ):
          lowercase				:							Any									=   mask_decoder_config.to_dict()

        lowercase				:							List[str]									=   SamVisionConfig(**__lowercase     )
        lowercase				:							str									=   SamPromptEncoderConfig(**__lowercase     )
        lowercase				:							Optional[Any]									=   SamMaskDecoderConfig(**__lowercase     )
        lowercase				:							Optional[int]									=   initializer_range







      def      lowerCamelCase__      (  self     ):
        lowercase				:							Dict									=   copy.deepcopy(self.__dict__     )
        lowercase				:							Union[str, Any]									=   self.vision_config.to_dict()
        lowercase				:							Union[str, Any]									=   self.prompt_encoder_config.to_dict()
        lowercase				:							List[str]									=   self.mask_decoder_config.to_dict()
        lowercase				:							Optional[int]									=   self.__class__.model_type
        return output



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_UpperCAmelCase      :	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       lowerCAmelCase			(		lowerCAmelCase_			)->			list[int]:
				return [int(lowerCAmelCase_			) for c in f"""{ruleset:08}"""[:8]]



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



def       lowerCAmelCase			(		lowerCAmelCase_			)->			Image.Image:
				lowerCAmelCase_			:   Optional[Any]     					=					Image.new('''RGB'''			, (len(cells[0]			), len(lowerCAmelCase_			))			)
				lowerCAmelCase_			:   str     					=					img.load()
				# Generates image
				for w in range(img.width			):
								for h in range(img.height			):
												lowerCAmelCase_			:   Optional[Any]     					=					255 - int(255 * cells[h][w]			)
												lowerCAmelCase_			:   List[Any]     					=					(color, color, color)
				return img


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