


from itertools import permutations




def       a__						(		snake_case__				:       Tuple = 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
  _UpperCAmelCase		:       str       =    list(range(gon_side + 1	,      0	,      -1    )    )
  _UpperCAmelCase		:       Dict       =    list(range(gon_side + 2	,      gon_side * 2 + 1    )    )

  for perm in permutations(small_numbers + big_numbers    ):
    _UpperCAmelCase		:       Any       =    generate_gon_ring(__a	,      list(__a    )    )
    if is_magic_gon(__a    ):
      return int("""""".join(str(__a    ) for n in numbers    )    )

  _UpperCAmelCase		:       Optional[Any]       =    f'''Magic {gon_side}-gon ring is impossible'''
  raise ValueError(__a    )




def       a__						(		snake_case__				:       Tuple	,      snake_case__				:       Union[str, Any]    ):
  _UpperCAmelCase		:       Union[str, Any]       =    [0] * (gon_side * 3)
  _UpperCAmelCase		:       str       =    perm[0:3]
  perm.append(perm[1]    )

  _UpperCAmelCase		:       List[str]       =    1 if gon_side < 5 else 2

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

  return result




def       a__						(		snake_case__				:       Dict    ):





  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

  _UpperCAmelCase		:       Optional[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())









from typing import Any


class 		_SCREAMING_SNAKE_CASE    :


     def __init__(     self						):
       _UpperCAmelCase		:       Union[str, Any]       =    []
       _UpperCAmelCase		:       Dict       =    0


     def __str__(     self						):
       _UpperCAmelCase		:       Union[str, Any]       =    """<""" + str(self.stack						)[1:-1] + """>"""
       return printed


     def 					__snake_case(     self       ,				A_						):
       self.stack.append(A_						)
       _UpperCAmelCase		:       Optional[Any]       =    self.length + 1


     def 					__snake_case(     self						):
       self.rotate(1						)
       _UpperCAmelCase		:       List[Any]       =    self.stack[self.length - 1]
       _UpperCAmelCase		:       Optional[Any]       =    self.stack[:-1]
       self.rotate(self.length - 1						)
       _UpperCAmelCase		:       Union[str, Any]       =    self.length - 1
       return dequeued


     def 					__snake_case(     self       ,				A_						):
       for _ in range(A_						):
         _UpperCAmelCase		:       Dict       =    self.stack[0]
         _UpperCAmelCase		:       List[Any]       =    self.stack[1:]
         self.put(A_						)
         _UpperCAmelCase		:       Dict       =    self.length - 1


     def 					__snake_case(     self						):
       _UpperCAmelCase		:       Tuple       =    self.get()
       self.put(A_						)
       self.rotate(self.length - 1						)
       return front


     def 					__snake_case(     self						):
       return self.length





