



class 		UpperCAmelCase    :





   def __init__(						self      ):
         _lowerCAmelCase			      =	{}
         # indexmap keys are an index and it's values are the number at that index
         _lowerCAmelCase			      =	{}





   def 						__lowerCAmelCase				(						self							,  _lowerCAmelCase							,  _lowerCAmelCase      ):






         if isinstance(__UpperCamelCase							,  (range, str)      ):
               _lowerCAmelCase			      =	list(__UpperCamelCase      )
         elif not isinstance(__UpperCamelCase							,  __UpperCamelCase      ):
               raise TypeError(
                   '''binary_search_delete() only accepts either a list, range or str'''      )

         _lowerCAmelCase			      =	0
         _lowerCAmelCase			      =	len(__UpperCamelCase      ) - 1

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





   def 						__lowerCAmelCase				(						self							,  _lowerCAmelCase							,  _lowerCAmelCase      ):






         if isinstance(__UpperCamelCase							,  (range, str)      ):
               _lowerCAmelCase			      =	list(__UpperCamelCase      )
         elif not isinstance(__UpperCamelCase							,  __UpperCamelCase      ):
               raise TypeError(
                   '''binary_search_insert() only accepts either a list, range or str'''      )

         _lowerCAmelCase			      =	0
         _lowerCAmelCase			      =	len(__UpperCamelCase      ) - 1

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

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





   def 						__lowerCAmelCase				(						self							,  _lowerCAmelCase							,  _lowerCAmelCase      ):






         if index in self.indexmap:
               _lowerCAmelCase			      =	self.indexmap[index]
               if len(self.numbermap[n]      ) == 1:
                     del self.numbermap[n]
               else:
                     _lowerCAmelCase			      =	self.binary_search_delete(self.numbermap[n]							,  __UpperCamelCase      )

        # Set new index
         _lowerCAmelCase			      =	number

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

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





   def 						__lowerCAmelCase				(						self							,  _lowerCAmelCase      ):
         return self.numbermap.get(__UpperCamelCase							,  [-1]      )[0]


if __name__ == "__main__":
    import doctest

    doctest.testmod()

'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__SCREAMING_SNAKE_CASE		:  Tuple        =      {
    'configuration_segformer': ['SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'SegformerConfig', 'SegformerOnnxConfig']
}

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__SCREAMING_SNAKE_CASE		:  Dict        =      ['SegformerFeatureExtractor']
					__SCREAMING_SNAKE_CASE		:  str        =      ['SegformerImageProcessor']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__SCREAMING_SNAKE_CASE		:  List[str]        =      [
					    'SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'SegformerDecodeHead',
					    'SegformerForImageClassification',
					    'SegformerForSemanticSegmentation',
					    'SegformerLayer',
					    'SegformerModel',
					    'SegformerPreTrainedModel',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__SCREAMING_SNAKE_CASE		:  List[str]        =      [
					    'TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFSegformerDecodeHead',
					    'TFSegformerForImageClassification',
					    'TFSegformerForSemanticSegmentation',
					    'TFSegformerModel',
					    'TFSegformerPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_segformer import SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, SegformerConfig, SegformerOnnxConfig

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_segformer import SegformerFeatureExtractor
										from .image_processing_segformer import SegformerImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_segformer import (
										    SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    SegformerDecodeHead,
										    SegformerForImageClassification,
										    SegformerForSemanticSegmentation,
										    SegformerLayer,
										    SegformerModel,
										    SegformerPreTrainedModel,
										)
					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_segformer import (
										    TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFSegformerDecodeHead,
										    TFSegformerForImageClassification,
										    TFSegformerForSemanticSegmentation,
										    TFSegformerModel,
										    TFSegformerPreTrainedModel,
										)

else:
					import sys

					__SCREAMING_SNAKE_CASE		:  Optional[Any]        =      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)