



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
UpperCamelCase_      			=  [[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     (						__UpperCAmelCase      )			->			list[int]:



						'''simple docstring'''






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







def 							A     (						__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase      )			->			list[int]:



						'''simple docstring'''






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







def 							A     (						__UpperCAmelCase      )			->			Image.Image:



						'''simple docstring'''






						UpperCAmelCase_					=	Image.new('''RGB'''				,   (len(cells[0]      ), len(__UpperCAmelCase      ))      )
						UpperCAmelCase_					=	img.load()
						# Generates image
						for w in range(img.width      ):
												for h in range(img.height      ):
																		UpperCAmelCase_					=	255 - int(255 * cells[h][w]      )
																		UpperCAmelCase_					=	(color, color, color)
						return img


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










def 							A     (						__UpperCAmelCase				,   __UpperCAmelCase      )			->			int:



						'''simple docstring'''






						print('''\nVertex Distance'''      )
						for i in range(__UpperCAmelCase      ):
												if dist[i] != float('''inf'''      ):
																		print(__UpperCAmelCase				,   '''\t'''				,   int(dist[i]      )				,   end='''\t'''      )
												else:
																		print(__UpperCAmelCase				,   '''\t'''				,   '''INF'''				,   end='''\t'''      )
												print()







def 							A     (						__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase      )			->			str:



						'''simple docstring'''






						UpperCAmelCase_					=	float('''inf'''      )
						UpperCAmelCase_					=	-1
						for i in range(__UpperCAmelCase      ):
												if (not vset[i]) and mdist[i] < min_val:
																		UpperCAmelCase_					=	i
																		UpperCAmelCase_					=	mdist[i]
						return min_ind







def 							A     (						__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase      )			->			Optional[Any]:



						'''simple docstring'''






						UpperCAmelCase_					=	[float('''inf'''      ) for _ in range(__UpperCAmelCase      )]
						UpperCAmelCase_					=	[False for _ in range(__UpperCAmelCase      )]
						UpperCAmelCase_					=	0.0

						for _ in range(v - 1      ):
												UpperCAmelCase_					=	min_dist(__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase      )
												UpperCAmelCase_					=	True

												for i in range(__UpperCAmelCase      ):
																		if (
																		    (not vset[i])
																		    and graph[u][i] != float('''inf'''      )
																		    and mdist[u] + graph[u][i] < mdist[i]
																		):
																								UpperCAmelCase_					=	mdist[u] + graph[u][i]

						print_dist(__UpperCAmelCase				,   __UpperCAmelCase      )


if __name__ == "__main__":
							UpperCamelCase_      			=  int(input("Enter number of vertices: ").strip())
							UpperCamelCase_      			=  int(input("Enter number of edges: ").strip())

							UpperCamelCase_      			=  [[float("inf") for i in range(V)] for j in range(V)]

							for i in range(V):
														UpperCamelCase_      			=  0.0

							for i in range(E):
														print("\nEdge ", i + 1)
														UpperCamelCase_      			=  int(input("Enter source:").strip())
														UpperCamelCase_      			=  int(input("Enter destination:").strip())
														UpperCamelCase_      			=  float(input("Enter weight:").strip())
														UpperCamelCase_      			=  weight

							UpperCamelCase_      			=  int(input("\nEnter shortest path source:").strip())
							dijkstra(graph, V, gsrc)





