



"""simple docstring"""






from itertools import permutations






def 	snake_case__  (						__lowerCamelCase							:       int = 5      ):
			"""simple docstring"""
			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__						:						Tuple						      =list(range(gon_side + 1				,						0				,						-1      )      )
			lowerCamelCase__						:						List[str]						      =list(range(gon_side + 2				,						gon_side * 2 + 1      )      )

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

			lowerCamelCase__						:						List[Any]						      =f'''Magic {gon_side}-gon ring is impossible'''
			raise ValueError(__lowerCamelCase      )






def 	snake_case__  (						__lowerCamelCase							:       int				,						__lowerCamelCase							:       list[int]      ):
			"""simple docstring"""
			lowerCamelCase__						:						Any						      =[0] * (gon_side * 3)
			lowerCamelCase__						:						Optional[Any]						      =perm[0:3]
			perm.append(perm[1]      )

			lowerCamelCase__						:						Optional[Any]						      =1 if gon_side < 5 else 2

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

			return result






def 	snake_case__  (						__lowerCamelCase							:       list[int]      ):
			"""simple docstring"""
			if len(__lowerCamelCase      ) % 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__						:						Dict						      =sum(numbers[:3]      )

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


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










'''simple docstring'''






from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import Any, Generic, TypeVar

lowercase						:   Union[str, Any]      						=							TypeVar('''T''', bound=bool)

class 	SCREAMING_SNAKE_CASE_		(							Generic[T]					):



 def __init__(	self ,		A			):






        '''simple docstring'''




        lowercase	:		T    =   value
        lowercase	:		SkewNode[T] | None    =   None
        lowercase	:		SkewNode[T] | None    =   None



 @property
 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        return self._value





 @staticmethod
 def  SCREAMING_SNAKE_CASE(	A ,		A			):






        '''simple docstring'''




        if not roota:
               return roota

        if not roota:
               return roota

        if roota.value > roota.value:
               lowercase,  lowercase	:		Union[str, Any]    =   roota, roota

        lowercase	:		Optional[int]    =   roota
        lowercase	:		Tuple    =   roota.right
        lowercase	:		Union[str, Any]    =   roota.left
        lowercase	:		Any    =   SkewNode.merge(A ,		A			)

        return result






class 	SCREAMING_SNAKE_CASE_		(							Generic[T]					):



 def __init__(	self ,		A = ()			):






        '''simple docstring'''




        lowercase	:		SkewNode[T] | None    =   None
        if data:
               for item in data:
                      self.insert(A			)



 def __bool__(	self			):






        '''simple docstring'''




        return self._root is not None



 def __iter__(	self			):






        '''simple docstring'''




        lowercase	:		list[Any]    =   []
        while self:
               result.append(self.pop()			)

        # Pushing items back to the heap not to clear it.
        for item in result:
               self.insert(A			)

        return iter(A			)



 def  SCREAMING_SNAKE_CASE(	self ,		A			):






        '''simple docstring'''




        lowercase	:		List[str]    =   SkewNode.merge(self._root ,		SkewNode(A			)			)



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        lowercase	:		List[Any]    =   self.top()
        lowercase	:		int    =   (
            SkewNode.merge(self._root.left ,		self._root.right			) if self._root else None
        )

        return result



 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        if not self._root:
               raise IndexError('''Can\'t get top element for the empty heap.'''			)
        return self._root.value





 def  SCREAMING_SNAKE_CASE(	self			):






        '''simple docstring'''




        lowercase	:		Optional[Any]    =   None


if __name__ == "__main__":
      import doctest

      doctest.testmod()




