

'''simple docstring'''



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
UpperCAmelCase				: Optional[Any]         =  [[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__ (						a__		):




     """simple docstring"""


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







def      a__ (						a__   ,					a__   ,					a__		):




     """simple docstring"""


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







def      a__ (						a__		):




     """simple docstring"""


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


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









'''simple docstring'''



def      a__ (						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   1

     while True:
          if (
              sorted(str(a__		)		)
              == sorted(str(2 * i		)		)
              == sorted(str(3 * i		)		)
              == sorted(str(4 * i		)		)
              == sorted(str(5 * i		)		)
              == sorted(str(6 * i		)		)
          ):
               return i

          i += 1


if __name__ == "__main__":
  print(solution())






