from itertools import permutations


def     UpperCamelCase(						__UpperCamelCase							:	Any = 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_    :  Tuple             =				list(range(gon_side + 2  ,gon_side * 2 + 1				)				)

		for perm in permutations(small_numbers + big_numbers				):
				lowerCAmelCase_    :  str             =				generate_gon_ring(snake_case_  ,list(snake_case_				)				)
				if is_magic_gon(snake_case_				):
						return int(''''''.join(str(snake_case_				) for n in numbers				)				)

		lowerCAmelCase_    :  Any             =				f"""Magic {gon_side}-gon ring is impossible"""
		raise ValueError(snake_case_				)


def     UpperCamelCase(						__UpperCamelCase							:	int  ,__UpperCamelCase							:	List[str]				):
		lowerCAmelCase_    :  List[Any]             =				[0] * (gon_side * 3)
		lowerCAmelCase_    :  List[Any]             =				perm[0:3]
		perm.append(perm[1]				)

		lowerCAmelCase_    :  Optional[int]             =				1 if gon_side < 5 else 2

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

		return result


def     UpperCamelCase(						__UpperCamelCase							:	Dict				):
		if len(snake_case_				) % 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_    :  Optional[int]             =				sum(numbers[:3]				)

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


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










from __future__ import annotations

from typing import Generic, TypeVar

A__						:						Dict          =      TypeVar('''T''')



class        __snake_case		(  Generic[T]		):




							def __init__( self  : List[Any]       ,       A_  : T):
									lowerCAmelCase_    :  Optional[Any]             =				data  # Assign data
									lowerCAmelCase_    :  Node[T] | None             =				None  # Initialize next as null
									lowerCAmelCase_    :  Node[T] | None             =				None  # Initialize prev as null





class        __snake_case		(  Generic[T]		):




							def __init__( self  : Union[str, Any]):
									lowerCAmelCase_    :  Node[T] | None             =				None




							def      UpperCAmelCase__    ( self  : List[str]       ,       A_  : T):
									if self.head is None:
											lowerCAmelCase_    :  List[Any]             =				Node(A_)
									else:
											lowerCAmelCase_    :  Tuple             =				Node(A_)
											lowerCAmelCase_    :  Optional[int]             =				new_node
											lowerCAmelCase_    :  Optional[int]             =				self.head
											lowerCAmelCase_    :  Optional[Any]             =				None
											lowerCAmelCase_    :  Dict             =				new_node




							def      UpperCAmelCase__    ( self  : List[str]):
									if self.head is None:
											return None
									else:
											assert self.head is not None
											lowerCAmelCase_    :  Tuple             =				self.head.data
											lowerCAmelCase_    :  Any             =				self.head.next
											if self.head is not None:
													lowerCAmelCase_    :  Optional[Any]             =				None
											return temp




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									return self.head.data if self.head is not None else None




							def __len__( self  : Dict):
									lowerCAmelCase_    :  List[str]             =				self.head
									lowerCAmelCase_    :  str             =				0
									while temp is not None:
											count += 1
											lowerCAmelCase_    :  Union[str, Any]             =				temp.next
									return count




							def      UpperCAmelCase__    ( self  : Dict):
									return self.head is None







							def      UpperCAmelCase__    ( self  : Dict):
									print('''stack elements are:''')
									lowerCAmelCase_    :  Optional[Any]             =				self.head
									while temp is not None:
											print(temp.data       ,       end='''->''')
											lowerCAmelCase_    :  List[str]             =				temp.next


# Code execution starts here
if __name__ == "__main__":
						# Start with the empty stack
						A__						:						Stack[int]          =      Stack()

						# Insert 4 at the beginning. So stack becomes 4->None
						print('''Stack operations using Doubly LinkedList''')
						stack.push(4)

						# Insert 5 at the beginning. So stack becomes 4->5->None
						stack.push(5)

						# Insert 6 at the beginning. So stack becomes 4->5->6->None
						stack.push(6)

						# Insert 7 at the beginning. So stack becomes 4->5->6->7->None
						stack.push(7)

						# Print the stack
						stack.print_stack()

						# Print the top element
						print('''\nTop element is ''', stack.top())

						# Print the stack size
						print('''Size of the stack is ''', len(stack))

						# pop the top element
						stack.pop()

						# pop the top element
						stack.pop()

						# two elements have now been popped off
						stack.print_stack()

						# Print True if the stack is empty else False
						print('''\nstack is empty:''', stack.is_empty())





