




"""simple docstring"""




class 							lowerCamelCase						:







   def __init__(							self       ):
       # numbermap keys are the number and its values are lists of indexes sorted
       # in ascending order
       UpperCamelCase :      Optional[int]      				=							{}
       # indexmap keys are an index and it's values are the number at that index
       UpperCamelCase :      List[Any]      				=							{}







   def 					a_							(							self			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_       ):
       if isinstance(__A			,					(range, str)       ):
           UpperCamelCase :      Union[str, Any]      				=							list(__A       )
       elif not isinstance(__A			,					__A       ):
           raise TypeError(
               """binary_search_delete() only accepts either a list, range or str"""       )

       UpperCamelCase :      Any      				=							0
       UpperCamelCase :      Optional[int]      				=							len(__A       ) - 1

       while low <= high:
           UpperCamelCase :      List[str]      				=							(low + high) // 2
           if array[mid] == item:
               array.pop(__A       )
               return array
           elif array[mid] < item:
               UpperCamelCase :      List[Any]      				=							mid + 1
           else:
               UpperCamelCase :      Optional[int]      				=							mid - 1
       raise ValueError(
           """Either the item is not in the array or the array was unsorted"""       )







   def 					a_							(							self			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_       ):
       if isinstance(__A			,					(range, str)       ):
           UpperCamelCase :      Tuple      				=							list(__A       )
       elif not isinstance(__A			,					__A       ):
           raise TypeError(
               """binary_search_insert() only accepts either a list, range or str"""       )

       UpperCamelCase :      str      				=							0
       UpperCamelCase :      Optional[Any]      				=							len(__A       ) - 1

       while low <= high:
           UpperCamelCase :      List[str]      				=							(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:
               UpperCamelCase :      int      				=							mid + 1
           else:
               UpperCamelCase :      List[Any]      				=							mid - 1

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







   def 					a_							(							self			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_       ):
       # Remove previous index
       if index in self.indexmap:
           UpperCamelCase :      int      				=							self.indexmap[index]
           if len(self.numbermap[n]       ) == 1:
               del self.numbermap[n]
           else:
               UpperCamelCase :      Union[str, Any]      				=							self.binary_search_delete(self.numbermap[n]			,					__A       )

        # Set new index
       UpperCamelCase :      Tuple      				=							number

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

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







   def 					a_							(							self			,					SCREAMING_SNAKE_CASE_       ):
       return self.numbermap.get(__A			,					[-1]       )[0]


if __name__ == "__main__":
  import doctest

  doctest.testmod()












from __future__ import annotations

from collections.abc import Generator




def    __A    (   _lowercase       ):

					'''simple docstring'''







					if not isinstance(_lowercase    ,	_lowercase       ) or n < 1:
										raise Exception('''Sequence only defined for positive integers'''       )

					yield n
					while n != 1:
										if n % 2 == 0:
															n //= 2
										else:
															_A									=       3 * n + 1
										yield n




def    __A    (   ):

					'''simple docstring'''







					_A									=       43
					_A									=       tuple(collatz_sequence(_lowercase       )       )
					print(_lowercase       )
					print(f"""Collatz sequence from {n} took {len(_lowercase       )} steps."""       )


if __name__ == "__main__":
				main()



