


def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:int   ,    lowercase__	:Tuple					)							->	list:
						__magic_name__					:				int				=   sorted(lowerCAmelCase_   ,    key=lambda lowercase__					: value[2]   ,    reverse=lowerCAmelCase_					)

						# Create a list of size equal to the maximum deadline
						# and initialize it with -1
						__magic_name__					:				Tuple				=   max(lowerCAmelCase_   ,    key=lambda lowercase__					: value[1]					)[1]
						__magic_name__					:				List[Any]				=   [-1] * max_deadline

						# Finding the maximum profit and the count of jobs
						__magic_name__					:				Any				=   0
						__magic_name__					:				Dict				=   0
						for job in jobs:
												# Find a free time slot for this job
												# (Note that we start from the last possible slot)
												for i in range(job[1] - 1   ,    -1   ,    -1					):
																		if time_slots[i] == -1:
																								__magic_name__					:				Optional[Any]				=   job[0]
																								count += 1
																								max_profit += job[2]
																								break
						return [count, max_profit]


if __name__ == "__main__":
			import doctest

			doctest.testmod()






from __future__ import annotations

from PIL import Image

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



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



def       lowerCAmelCase			(		lowerCAmelCase_			)->			Image.Image:
				lowerCAmelCase_			:   Optional[Any]     					=					Image.new('''RGB'''			, (len(cells[0]			), len(lowerCAmelCase_			))			)
				lowerCAmelCase_			:   str     					=					img.load()
				# Generates image
				for w in range(img.width			):
								for h in range(img.height			):
												lowerCAmelCase_			:   Optional[Any]     					=					255 - int(255 * cells[h][w]			)
												lowerCAmelCase_			:   List[Any]     					=					(color, color, color)
				return img


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