

"""simple docstring"""






class 	_lowerCAmelCase    :

							def __init__( self       :    Tuple    )   ->    None:

									"""simple docstring"""
									# numbermap keys are the number and its values are lists of indexes sorted
									# in ascending order
									lowercase										=							{}
									# indexmap keys are an index and it's values are the number at that index
									lowercase										=							{}

							def 					_lowerCAmelCase  ( self       :    List[str] ,		a       :    list | str | range ,		a       :    int    )   ->    list[int]:

									"""simple docstring"""
									if isinstance(a ,		(range, str)    ):
											lowercase										=							list(a    )
									elif not isinstance(a ,		a    ):
											raise TypeError(
											    '''binary_search_delete() only accepts either a list, range or str'''    )

									lowercase										=							0
									lowercase										=							len(a    ) - 1

									while low <= high:
											lowercase										=							(low + high) // 2
											if array[mid] == item:
													array.pop(a    )
													return array
											elif array[mid] < item:
													lowercase										=							mid + 1
											else:
													lowercase										=							mid - 1
									raise ValueError(
									    '''Either the item is not in the array or the array was unsorted'''    )

							def 					_lowerCAmelCase  ( self       :    int ,		a       :    list | str | range ,		a       :    int    )   ->    list[int]:

									"""simple docstring"""
									if isinstance(a ,		(range, str)    ):
											lowercase										=							list(a    )
									elif not isinstance(a ,		a    ):
											raise TypeError(
											    '''binary_search_insert() only accepts either a list, range or str'''    )

									lowercase										=							0
									lowercase										=							len(a    ) - 1

									while low <= high:
											lowercase										=							(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 ,		a    )
													return array
											elif array[mid] < index:
													lowercase										=							mid + 1
											else:
													lowercase										=							mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
									array.insert(a ,		a    )
									return array

							def 					_lowerCAmelCase  ( self       :    List[Any] ,		a       :    int ,		a       :    int    )   ->    None:

									"""simple docstring"""
									# Remove previous index
									if index in self.indexmap:
											lowercase										=							self.indexmap[index]
											if len(self.numbermap[n]    ) == 1:
													del self.numbermap[n]
											else:
													lowercase										=							self.binary_search_delete(self.numbermap[n] ,		a    )

        # Set new index
									lowercase										=							number

									# Number not seen before or empty so insert number value
									if number not in self.numbermap:
											lowercase										=							[index]

									# Here we need to perform a binary search insertion in order to insert
									# The item in the correct place
									else:
											lowercase										=							self.binary_search_insert(
											    self.numbermap[number] ,		a    )

							def 					_lowerCAmelCase  ( self       :    Tuple ,		a       :    int    )   ->    int:

									"""simple docstring"""
									return self.numbermap.get(a ,		[-1]    )[0]


if __name__ == "__main__":
							import doctest

							doctest.testmod()


"""simple docstring"""






from typing import Callable
def 		A_	(   __UpperCamelCase     :				Callable				):

		def wrapper(__UpperCamelCase     :				Optional[Any]				):
				lowercase										=							function_with_docstring.__doc__
				return target_function

		return wrapper