






"""simple docstring"""





# Lint as: python3

import hashlib
from typing import Union







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						bytes:
    """simple docstring"""

    if isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ):
        # Data already in bytes, returns as it as
        return hash_data
    elif isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ):
        # We keep the data as it as for it ot be later encoded to UTF-8
        # However replace `\\` with `/` for Windows compatibility
        UpperCamelCase__								=     hash_data.replace('\\'			,						'/'       )
    elif isinstance(SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       ):
        UpperCamelCase__								=     str(SCREAMING_SNAKE_CASE       )
    else:
        # If data is not of the required type, raise error
        raise InvalidKeyError(SCREAMING_SNAKE_CASE       )

    return hash_data.encode('utf-8'       )
class  __lowerCamelCase     (	_a	):

   def __init__(       self			,					snake_case_   )		->							Union[str, Any]:
       UpperCamelCase__								=     '\nFAILURE TO GENERATE DATASET: Invalid key type detected'
       UpperCamelCase__								=     F'\nFound Key {hash_data} of type {type(snake_case_   )}'
       UpperCamelCase__								=     '\nKeys should be either str, int or bytes type'
       super().__init__(F'{self.prefix}{self.err_msg}{self.suffix}'   )







class  __lowerCamelCase     (	_a	):

   def __init__(       self			,					snake_case_			,					snake_case_			,					snake_case_=""   )		->							int:
       UpperCamelCase__								=     key
       UpperCamelCase__								=     duplicate_key_indices
       UpperCamelCase__								=     fix_msg
       UpperCamelCase__								=     'Found multiple examples generated with the same key'
       if len(snake_case_   ) <= 20:
           UpperCamelCase__								=     F'\nThe examples at index {", ".join(snake_case_   )} have the key {key}'
       else:
           UpperCamelCase__								=     F'\nThe examples at index {", ".join(duplicate_key_indices[:20]   )}... ({len(snake_case_   ) - 20} more) have the key {key}'
       UpperCamelCase__								=     '\n' + fix_msg if fix_msg else ''
       super().__init__(F'{self.prefix}{self.err_msg}{self.suffix}'   )







class  __lowerCamelCase     :

   def __init__(       self			,					snake_case_   )		->							str:
       UpperCamelCase__								=     hashlib.mda(_as_bytes(snake_case_   )   )







   def     SCREAMING_SNAKE_CASE__			(       self			,					snake_case_   )		->							int:
       UpperCamelCase__								=     self._split_mda.copy()
       UpperCamelCase__								=     _as_bytes(snake_case_   )
       mda.update(snake_case_   )
       # Convert to integer with hexadecimal conversion
       return int(mda.hexdigest()			,					16   )












"""simple docstring"""





from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
A__       :			str=						[[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_(			SCREAMING_SNAKE_CASE       )       ->						list[int]:
    """simple docstring"""

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







def 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE			,						SCREAMING_SNAKE_CASE       )       ->						list[int]:
    """simple docstring"""

    UpperCamelCase__								=     len(cells[0]       )  # 31
    UpperCamelCase__								=     []
    for i in range(SCREAMING_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 	lowerCAmelCase_(			SCREAMING_SNAKE_CASE       )       ->						Image.Image:
    """simple docstring"""

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


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




