


'''simple docstring'''



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
__UpperCAmelCase     :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      (		_lowercase   :      int    ):





     '''simple docstring'''






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




def       _a      (		_lowercase   :      list[list[int]]     ,   _lowercase   :      list[int]     ,   _lowercase   :      int    ):





     '''simple docstring'''






     __UpperCAmelCase      :					List[Any]    				=     len(cells[0]    )  # 31
     __UpperCAmelCase      :					Tuple    				=     []
     for i in range(_lowercase    ):
          # Get the neighbors of each cell
          # Handle neighbours outside bounds by using 0 as their value
          __UpperCAmelCase      :					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      :					Optional[int]    				=     7 - int(F'{left_neighbor}{cells[time][i]}{right_neighbor}'     ,   2    )
          next_generation.append(rule[situation]    )
     return next_generation




def       _a      (		_lowercase   :      list[list[int]]    ):





     '''simple docstring'''






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


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



'''simple docstring'''



def       _a      (		_lowercase   :      str    ):





     '''simple docstring'''






     __UpperCAmelCase      :					Union[str, Any]    				=     5381
     for x in s:
          __UpperCAmelCase      :					Union[str, Any]    				=     ((hash_value << 5) + hash_value) + ord(_lowercase    )
     return hash_value & 0XFFFFFFFF