'''simple docstring'''




class 	__UpperCAmelCase				:





       '''simple docstring'''



       def __init__(      self    ,     _SCREAMING_SNAKE_CASE )		->     None:
           A_     =   data
           A_     =   42
           A_     =   42





def      _UpperCAmelCase    (							_UpperCamelCase    :	Node   )	->      None:
    A_     =   0
    A_     =   x





def      _UpperCAmelCase    (							_UpperCamelCase    :	Node,   _UpperCamelCase    :	Node   )	->      None:
    A_   ,A_     =   find_set(_UpperCamelCase   ), find_set(_UpperCamelCase   )
    if x == y:
        return

    elif x.rank > y.rank:
        A_     =   x
    else:
        A_     =   y
        if x.rank == y.rank:
            y.rank += 1





def      _UpperCAmelCase    (							_UpperCamelCase    :	Node   )	->      Node:
    if x != x.parent:
        A_     =   find_set(x.parent   )
    return x.parent





def      _UpperCAmelCase    (							_UpperCamelCase    :	Node   )	->      set:
    A_     =   ({0, 1, 2}, {3, 4, 5})
    for s in sets:
        if node.data in s:
            return s
    A_     =   F'''{node.data} is not in {sets}'''
    raise ValueError(_UpperCamelCase   )





def      _UpperCAmelCase    (							)	->      None:
    A_     =   [Node(_UpperCamelCase   ) for i in range(6   )]
    for v in vertex:
        make_set(_UpperCamelCase   )

    union_set(vertex[0],   vertex[1]   )
    union_set(vertex[1],   vertex[2]   )
    union_set(vertex[3],   vertex[4]   )
    union_set(vertex[3],   vertex[5]   )

    for nodea in vertex:
        for nodea in vertex:
            if find_python_set(_UpperCamelCase   ).isdisjoint(find_python_set(_UpperCamelCase   )   ):
                assert find_set(_UpperCamelCase   ) != find_set(_UpperCamelCase   )
            else:
                assert find_set(_UpperCamelCase   ) == find_set(_UpperCamelCase   )


if __name__ == "__main__":
  test_disjoint_set()









'''simple docstring'''






from __future__ import annotations

from PIL import Image

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

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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	list[list[int]]  ,  SCREAMING_SNAKE_CASE_     :	list[int]  ,  SCREAMING_SNAKE_CASE_     :	int    )							->   list[int]:
      """simple docstring"""

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


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	list[list[int]]    )							->   Image.Image:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			List[Any]     =       Image.new("RGB"  ,  (len(cells[0]    ), len(SCREAMING_SNAKE_CASE_    ))    )
      SCREAMING_SNAKE_CASE_      :			Optional[int]     =       img.load()
      # Generates image
      for w in range(img.width    ):
            for h in range(img.height    ):
                  SCREAMING_SNAKE_CASE_      :			List[str]     =       2_5_5 - int(2_5_5 * cells[h][w]    )
                  SCREAMING_SNAKE_CASE_      :			str     =       (color, color, color)
      return img


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

