

"""simple docstring"""





from manim import *







class        SCREAMING_SNAKE_CASE      (	a_ ):






					"""simple docstring"""



					def  __lowerCAmelCase				( self    :       Optional[int]	):
						lowerCAmelCase__			:		int						       =			Rectangle(height=0.5     ,width=0.5	)
						lowerCAmelCase__			:		Optional[Any]						       =			Rectangle(height=0.46     ,width=0.46	).set_stroke(width=0	)
						lowerCAmelCase__			:		Tuple						       =			Rectangle(height=0.25     ,width=0.25	)

						lowerCAmelCase__			:		str						       =			[mem.copy() for i in range(6	)]
						lowerCAmelCase__			:		Optional[Any]						       =			[mem.copy() for i in range(6	)]
						lowerCAmelCase__			:		Tuple						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		List[Any]						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		str						       =			VGroup(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		int						       =			Text('''CPU'''     ,font_size=2_4	)
						lowerCAmelCase__			:		List[str]						       =			Group(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0.5     ,aligned_edge=lowercase_	)
						cpu.move_to([-2.5, -0.5, 0]	)
						self.add(lowercase_	)

						lowerCAmelCase__			:		Union[str, Any]						       =			[mem.copy() for i in range(4	)]
						lowerCAmelCase__			:		List[str]						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		Optional[int]						       =			Text('''GPU'''     ,font_size=2_4	)
						lowerCAmelCase__			:		Union[str, Any]						       =			Group(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0.5     ,aligned_edge=lowercase_	)
						gpu.move_to([-1, -1, 0]	)
						self.add(lowercase_	)

						lowerCAmelCase__			:		int						       =			[mem.copy() for i in range(6	)]
						lowerCAmelCase__			:		Optional[Any]						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)

						lowerCAmelCase__			:		Any						       =			Text('''Model'''     ,font_size=2_4	)
						lowerCAmelCase__			:		Tuple						       =			Group(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0.5     ,aligned_edge=lowercase_	)
						model.move_to([3, -1.0, 0]	)
						self.add(lowercase_	)

						lowerCAmelCase__			:		Optional[int]						       =			[]
						lowerCAmelCase__			:		Any						       =			[]

						for i, rect in enumerate(lowercase_	):
							rect.set_stroke(lowercase_	)

							lowerCAmelCase__			:		Optional[Any]						       =			Rectangle(height=0.46 / 4     ,width=0.46 / 3	).set_stroke(width=0.0	).set_fill(lowercase_     ,opacity=0.7	)

							if i == 0:
								cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT	)     ,buff=0.02     ,direction=lowercase_	)
								cpu_target.set_x(cpu_target.get_x() + 0.1	)
							elif i == 3:
								cpu_target.next_to(model_cpu_arr[0]     ,direction=lowercase_     ,buff=0.0	)
							else:
								cpu_target.next_to(model_cpu_arr[i - 1]     ,direction=lowercase_     ,buff=0.0	)
							self.add(lowercase_	)
							model_cpu_arr.append(lowercase_	)

						self.add(*lowercase_     ,*lowercase_	)

						lowerCAmelCase__			:		int						       =			[meta_mem.copy() for i in range(6	)]
						lowerCAmelCase__			:		Any						       =			[meta_mem.copy() for i in range(6	)]
						lowerCAmelCase__			:		List[str]						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		List[Any]						       =			VGroup(*lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		Optional[Any]						       =			VGroup(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0	)
						lowerCAmelCase__			:		Union[str, Any]						       =			Text('''Disk'''     ,font_size=2_4	)
						lowerCAmelCase__			:		Tuple						       =			Group(lowercase_     ,lowercase_	).arrange(lowercase_     ,buff=0.5     ,aligned_edge=lowercase_	)
						disk.move_to([-4.0, -1.25, 0]	)
						self.add(lowercase_     ,lowercase_	)

						lowerCAmelCase__			:		Dict						       =			[]

						for i in range(6	):
							lowerCAmelCase__			:		Tuple						       =			fill.copy().set_fill(lowercase_     ,opacity=0.8	)
							target.move_to(disk_left_col_base[i]	).scale(0.5	)
							cpu_disk_arr.append(lowercase_	)

						self.add(*lowercase_	)

						lowerCAmelCase__			:		Union[str, Any]						       =			Square(side_length=2.2	)
						key.move_to([-5, 2, 0]	)

						lowerCAmelCase__			:		List[str]						       =			MarkupText(
						    F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'     ,font_size=1_8     ,)

						key_text.move_to([-5, 2.4, 0]	)

						self.add(lowercase_     ,lowercase_	)

						lowerCAmelCase__			:		str						       =			MarkupText(
						    F'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'     ,font_size=1_8     ,)

						blue_text.next_to(lowercase_     ,DOWN * 2.4     ,aligned_edge=key_text.get_left()	)
						self.add(lowercase_	)

						lowerCAmelCase__			:		Dict						       =			MarkupText(F'The offloaded weights are all sent to the CPU.'     ,font_size=2_4	)
						step_a.move_to([2, 2, 0]	)

						self.play(Write(lowercase_     ,run_time=3	)	)

						for i in range(6	):
							lowerCAmelCase__			:		Optional[Any]						       =			cpu_disk_arr[i]
							lowerCAmelCase__			:		Optional[int]						       =			rect.copy().set_fill(lowercase_     ,opacity=0.8	).scale(2.0	)
							cpa.generate_target()
							cpa.target.move_to(model_base[i]	)

							if i == 0:
								rect.set_fill(lowercase_     ,opacity=0.8	)
								rect.generate_target()
								rect.target.move_to(cpu_left_col_base[0]	).scale(2.0	)

								self.remove(
								    *lowercase_     ,*lowercase_     ,)

							else:
								rect.generate_target()
								rect.target.move_to(cpu_left_col_base[i]	).scale(2.0	)
							self.play(MoveToTarget(lowercase_	)     ,MoveToTarget(lowercase_	)     ,model_base[i].animate.set_stroke(lowercase_	)	)
						self.play(FadeOut(lowercase_	)	)

						lowerCAmelCase__			:		Optional[Any]						       =			MarkupText(
						    F'Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed.'     ,font_size=2_4     ,)
						step_a.move_to([2, 2, 0]	)

						self.play(Write(lowercase_     ,run_time=3	)	)

						lowerCAmelCase__			:		Optional[int]						       =			[]
						lowerCAmelCase__			:		Optional[int]						       =			[]
						for i in range(6	):
							lowerCAmelCase__			:		Optional[Any]						       =			Arrow(start=lowercase_     ,end=lowercase_     ,color=lowercase_     ,buff=0.5	)
							a.next_to(model_base[i].get_left()     ,lowercase_     ,buff=0.2	)
							arrows.append(lowercase_	)
							animations.append(Write(lowercase_	)	)
						self.play(*lowercase_	)
						self.wait()







"""simple docstring"""





from itertools import permutations

def 						__SCREAMING_SNAKE_CASE						(   A_ = 5				):
	if gon_side < 3 or gon_side > 5:
		raise ValueError('''gon_side must be in the range [3, 5]'''				)

	# Since it's 16, we know 10 is on the outer ring
	# Put the big numbers at the end so that they are never the first number
	lowerCAmelCase__			:		str						       =			list(range(gon_side + 1		,  0		,  -1				)				)
	lowerCAmelCase__			:		int						       =			list(range(gon_side + 2		,  gon_side * 2 + 1				)				)

	for perm in permutations(small_numbers + big_numbers				):
		lowerCAmelCase__			:		Optional[Any]						       =			generate_gon_ring(A_		,  list(A_				)				)
		if is_magic_gon(A_				):
			return int(''''''.join(str(A_				) for n in numbers				)				)

	lowerCAmelCase__			:		Tuple						       =			f'Magic {gon_side}-gon ring is impossible'
	raise ValueError(A_				)

def 						__SCREAMING_SNAKE_CASE						(   A_		,  A_				):
	lowerCAmelCase__			:		Dict						       =			[0] * (gon_side * 3)
	lowerCAmelCase__			:		Optional[int]						       =			perm[0:3]
	perm.append(perm[1]				)

	lowerCAmelCase__			:		int						       =			1 if gon_side < 5 else 2

	for i in range(1		,  len(A_				) // 3 + magic_number				):
		lowerCAmelCase__			:		List[str]						       =			perm[2 * i + 1]
		lowerCAmelCase__			:		Optional[int]						       =			result[3 * i - 1]
		lowerCAmelCase__			:		List[Any]						       =			perm[2 * i + 2]

	return result

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if len(A_				) % 3 != 0:
		raise ValueError('''a gon ring should have a length that is a multiple of 3'''				)

	if min(numbers[::3]				) != numbers[0]:
		return False

	lowerCAmelCase__			:		int						       =			sum(numbers[:3]				)

	return all(sum(numbers[i : i + 3]				) == total for i in range(3		,  len(A_				)		,  3				)				)


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




