





"""simple docstring"""





from __future__ import annotations

from PIL import Image

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







      '''simple docstring'''




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


def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						list[list[int]]							,						SCREAMING_SNAKE_CASE					:						list[int]							,						SCREAMING_SNAKE_CASE					:						int      ):







      '''simple docstring'''




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


def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						list[list[int]]      ):







      '''simple docstring'''




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


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













"""simple docstring"""





def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						int							,						SCREAMING_SNAKE_CASE					:						int      ):







      '''simple docstring'''




      lowerCAmelCase  						=	1.0
      for i in range(1							,						r + 1      ):
            ret *= (n + 1 - i) / i
      return round(SCREAMING_SNAKE_CASE      )


def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						int      ):







      '''simple docstring'''




      return choose(8 + n							,						SCREAMING_SNAKE_CASE      ) + choose(9 + n							,						SCREAMING_SNAKE_CASE      ) - 10


def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						int      ):







      '''simple docstring'''




      return sum(non_bouncy_exact(SCREAMING_SNAKE_CASE      ) for i in range(1							,						n + 1      )      )


def       UpperCAmelCase__							(  SCREAMING_SNAKE_CASE					:						int = 1_00      ):







      '''simple docstring'''




      return non_bouncy_upto(SCREAMING_SNAKE_CASE      )


if __name__ == "__main__":
       print(f'{solution() = }')






