code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  from itertools import permutations
  
  
  
  
  def        __a (     UpperCAmelCase = 5    )      ->int:
  
  
  
  	"""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
  	A							  =      list(range(gon_side + 1       ,			0       ,			-1    )    )
  	A							  =      list(range(gon_side + 2       ,			gon_side * 2 + 1    )    )
  
  	for perm in permutations(small_numbers + big_numbers    ):
  		A							  =      generate_gon_ring(UpperCAmelCase       ,			list(UpperCAmelCase    )    )
  		if is_magic_gon(UpperCAmelCase    ):
  			return int("""""".join(str(UpperCAmelCase    ) for n in numbers    )    )
  
  	A							  =      f"""Magic {gon_side}-gon ring is impossible"""
  	raise ValueError(UpperCAmelCase    )
  
  
  
  
  def        __a (     UpperCAmelCase       ,			UpperCAmelCase    )      ->list[int]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      [0] * (gon_side * 3)
  	A							  =      perm[0:3]
  	perm.append(perm[1]    )
  
  	A							  =      1 if gon_side < 5 else 2
  
  	for i in range(1       ,			len(UpperCAmelCase    ) // 3 + magic_number    ):
  		A							  =      perm[2 * i + 1]
  		A							  =      result[3 * i - 1]
  		A							  =      perm[2 * i + 2]
  
  	return result
  
  
  
  
  def        __a (     UpperCAmelCase    )      ->bool:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	if len(UpperCAmelCase    ) % 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
  
  	A							  =      sum(numbers[:3]    )
  
  	return all(sum(numbers[i : i + 3]    ) == total for i in range(3       ,			len(UpperCAmelCase    )       ,			3    )    )
  
  
  if __name__ == "__main__":
  				print(solution())
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  class 							__UpperCAmelCase  :
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(self						:      List[str]      ):
  			# numbermap keys are the number and its values are lists of indexes sorted
  			# in ascending order
  			A							  =      {}
  			# indexmap keys are an index and it's values are the number at that index
  			A							  =      {}
  
  
  
  
  
  
  
  		def        A     (self						:      Union[str, Any]      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
  			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
  				A							  =      list(_lowerCAmelCase      )
  			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
  				raise TypeError(
  				    """binary_search_delete() only accepts either a list, range or str"""      )
  
  			A							  =      0
  			A							  =      len(_lowerCAmelCase      ) - 1
  
  			while low <= high:
  				A							  =      (low + high) // 2
  				if array[mid] == item:
  					array.pop(_lowerCAmelCase      )
  					return array
  				elif array[mid] < item:
  					A							  =      mid + 1
  				else:
  					A							  =      mid - 1
  			raise ValueError(
  			    """Either the item is not in the array or the array was unsorted"""      )
  
  
  
  
  
  
  
  		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
  			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
  				A							  =      list(_lowerCAmelCase      )
  			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
  				raise TypeError(
  				    """binary_search_insert() only accepts either a list, range or str"""      )
  
  			A							  =      0
  			A							  =      len(_lowerCAmelCase      ) - 1
  
  			while low <= high:
  				A							  =      (low + high) // 2
  				if array[mid] == index:
  					# If the item already exists in the array,
  					# insert it after the existing item
  					array.insert(mid + 1      ,      _lowerCAmelCase      )
  					return array
  				elif array[mid] < index:
  					A							  =      mid + 1
  				else:
  					A							  =      mid - 1
  
          # If the item doesn't exist in the array, insert it at the appropriate position
  			array.insert(_lowerCAmelCase      ,      _lowerCAmelCase      )
  			return array
  
  
  
  
  
  
  
  		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      int      ,      _lowerCAmelCase						:      int      ):
  			# Remove previous index
  			if index in self.indexmap:
  				A							  =      self.indexmap[index]
  				if len(self.numbermap[n]      ) == 1:
  					del self.numbermap[n]
  				else:
  					A							  =      self.binary_search_delete(self.numbermap[n]      ,      _lowerCAmelCase      )
  
          # Set new index
  			A							  =      number
  
  			# Number not seen before or empty so insert number value
  			if number not in self.numbermap:
  				A							  =      [index]
  
  			# Here we need to perform a binary search insertion in order to insert
  			# The item in the correct place
  			else:
  				A							  =      self.binary_search_insert(
  				    self.numbermap[number]      ,      _lowerCAmelCase      )
  
  
  
  
  
  
  
  		def        A     (self						:      int      ,      _lowerCAmelCase						:      int      ):
  			return self.numbermap.get(_lowerCAmelCase      ,      [-1]      )[0]
  
  
  if __name__ == "__main__":
  				import doctest
  
  				doctest.testmod()
  
  