





import inspect

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
   import jax




@require_flax
class    _a  :

      """simple docstring"""


      def 	UpperCAmelCase_   (						self:	int			):
          '''simple docstring'''


          UpperCamelCase__							,				UpperCamelCase__:					Optional[int]												=      self.prepare_init_args_and_inputs_for_common()

          UpperCamelCase__:					Tuple												=      self.model_class(**__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      model.init(inputs_dict["prng_key"]					,  inputs_dict["sample"]			)
          jax.lax.stop_gradient(__lowerCamelCase			)

          UpperCamelCase__:					int												=      model.apply(__lowerCamelCase					,  inputs_dict["sample"]			)

          if isinstance(__lowerCamelCase					,  __lowerCamelCase			):
              UpperCamelCase__:					str												=      output.sample

          self.assertIsNotNone(__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      inputs_dict["sample"].shape
          self.assertEqual(output.shape					,  __lowerCamelCase					,  "Input and output shapes do not match"			)






      def 	UpperCAmelCase_   (						self:	Union[str, Any]			):
          '''simple docstring'''


          UpperCamelCase__							,				UpperCamelCase__:					List[str]												=      self.prepare_init_args_and_inputs_for_common()

          UpperCamelCase__:					List[Any]												=      16
          UpperCamelCase__:					int												=      (16, 32)

          UpperCamelCase__:					Tuple												=      self.model_class(**__lowerCamelCase			)
          UpperCamelCase__:					Union[str, Any]												=      model.init(inputs_dict["prng_key"]					,  inputs_dict["sample"]			)
          jax.lax.stop_gradient(__lowerCamelCase			)

          UpperCamelCase__:					Union[str, Any]												=      model.apply(__lowerCamelCase					,  inputs_dict["sample"]			)

          if isinstance(__lowerCamelCase					,  __lowerCamelCase			):
              UpperCamelCase__:					Dict												=      output.sample

          self.assertIsNotNone(__lowerCamelCase			)
          UpperCamelCase__:					Optional[Any]												=      inputs_dict["sample"].shape
          self.assertEqual(output.shape					,  __lowerCamelCase					,  "Input and output shapes do not match"			)






      def 	UpperCAmelCase_   (						self:	Tuple			):
          '''simple docstring'''


          UpperCamelCase__:					List[str]												=      "kwargs" in inspect.signature(self.model_class.__init__			).parameters
          UpperCamelCase__:					Any												=      len(self.model_class._deprecated_kwargs			) > 0

          if has_kwarg_in_model_class and not has_deprecated_kwarg:
              raise ValueError(
                  F"{self.model_class} has `**kwargs` in its __init__ method but has not defined any deprecated kwargs"
                  " under the `_deprecated_kwargs` class attribute. Make sure to either remove `**kwargs` if there are"
                  " no deprecated arguments or add the deprecated argument with `_deprecated_kwargs ="
                  " [<deprecated_argument>]`"			)

          if not has_kwarg_in_model_class and has_deprecated_kwarg:
              raise ValueError(
                  F"{self.model_class} doesn't have `**kwargs` in its __init__ method but has defined deprecated kwargs"
                  " under the `_deprecated_kwargs` class attribute. Make sure to either add the `**kwargs` argument to"
                  F" {self.model_class}.__init__ if there are deprecated arguments or remove the deprecated argument"
                  " from `_deprecated_kwargs = [<deprecated_argument>]`"			)








from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
A__:  Tuple       					=					[[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_				(    A_):
    return [int(A_) for c in F"{ruleset:08}"[:8]]



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



def 							lowerCAmelCase_				(    A_):
    UpperCamelCase__:					int												=      Image.new("RGB"  ,(len(cells[0]), len(A_)))
    UpperCamelCase__:					Dict												=      img.load()
    # Generates image
    for w in range(img.width):
        for h in range(img.height):
            UpperCamelCase__:					List[str]												=      2_55 - int(2_55 * cells[h][w])
            UpperCamelCase__:					Union[str, Any]												=      (color, color, color)
    return img


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

