





from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_lowerCAmelCase							:      List[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      __snake_case						(					_lowerCAmelCase : int	) ->						list[int]:
   return [int(_lowerCAmelCase	) for c in f"{ruleset:08}"[:8]]

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

def      __snake_case						(					_lowerCAmelCase : list[list[int]]	) ->						Image.Image:
   A_					:				List[str]          =			Image.new("RGB"				,				(len(cells[0]	), len(_lowerCAmelCase	))	)
   A_					:				str          =			img.load()
   # Generates image
   for w in range(img.width	):
      for h in range(img.height	):
         A_					:				List[Any]          =			255 - int(255 * cells[h][w]	)
         A_					:				Dict          =			(color, color, color)
   return img


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







def      __snake_case						(					_lowerCAmelCase : float				,				_lowerCAmelCase : float				,				_lowerCAmelCase : int	) ->						float:
   A_					:				List[str]          =			[1 / first_term]
   A_					:				Tuple          =			1 / first_term
   for _ in range(number_of_terms - 1	):
      first_term += common_difference
      arithmetic_progression.append(_lowerCAmelCase	)
   A_					:				List[str]          =			[1 / step for step in arithmetic_progression]
   return sum(_lowerCAmelCase	)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(sum_of_harmonic_progression(1 / 2, 2, 2))
