






from __future__ import annotations

def 					UpperCamelCase		( _A,					_A				):






						"""simple docstring"""







						__magic_name__    :     List[str]     		=      0
						__magic_name__    :     str     		=      len(_A				) - 1
						while left <= right:
												__magic_name__    :     int     		=      (left + right) // 2
												if left == right:
																		if sorted_list[middle] < item:
																								__magic_name__    :     Dict     		=      middle + 1
																		break
												elif sorted_list[middle] < item:
																		__magic_name__    :     Tuple     		=      middle + 1
												else:
																		__magic_name__    :     Dict     		=      middle - 1
						sorted_list.insert(_A,					_A				)
						return sorted_list

def 					UpperCamelCase		( _A,					_A				):






						"""simple docstring"""







						__magic_name__    :     List[str]     		=      []
						while left and right:
												if left[0][0] < right[0][0]:
																		result.append(left.pop(0				)				)
												else:
																		result.append(right.pop(0				)				)
						return result + left + right

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						__magic_name__    :     Any     		=      len(_A				)
						if length <= 1:
												return list_ad
						__magic_name__    :     Union[str, Any]     		=      length // 2
						return merge(sortlist_ad(list_ad[:middle]				),					sortlist_ad(list_ad[middle:]				)				)

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						if len(_A				) <= 1:
												return collection
						__magic_name__    :     List[Any]     		=      []
						__magic_name__    :     Optional[Any]     		=      False
						for i in range(0,					len(_A				),					2				):
												if i == len(_A				) - 1:
																		__magic_name__    :     str     		=      True
												else:
																		if collection[i] < collection[i + 1]:
																								two_paired_list.append([collection[i], collection[i + 1]]				)
																		else:
																								two_paired_list.append([collection[i + 1], collection[i]]				)
						__magic_name__    :     Any     		=      sortlist_ad(_A				)
						__magic_name__    :     int     		=      [i[0] for i in sorted_list_ad]
						result.append(sorted_list_ad[-1][1]				)
						if has_last_odd_item:
												__magic_name__    :     str     		=      collection[-1]
												__magic_name__    :     Optional[int]     		=      binary_search_insertion(_A,					_A				)
						__magic_name__    :     int     		=      False
						for i in range(len(_A				) - 1				):
												if result[i] == collection[-1] and has_last_odd_item:
																		__magic_name__    :     Optional[Any]     		=      True
												__magic_name__    :     List[str]     		=      sorted_list_ad[i][1]
												# If last_odd_item is inserted before the item's index,
												# you should forward index one more.
												if is_last_odd_item_inserted_before_this_index:
																		__magic_name__    :     str     		=      result[: i + 2] + binary_search_insertion(result[i + 2 :],					_A				)
												else:
																		__magic_name__    :     Any     		=      result[: i + 1] + binary_search_insertion(result[i + 1 :],					_A				)

						return result


if __name__ == "__main__":
		__magic_name__:  Optional[Any]  	=			input("Enter numbers separated by a comma:\n").strip()
		__magic_name__:  List[str]  	=			[int(item) for item in user_input.split(",")]
		print(merge_insertion_sort(unsorted))








class  snake_case__      :
	def __init__(       self				)							->   None:
							# numbermap keys are the number and its values are lists of indexes sorted
							# in ascending order
							__magic_name__    :     dict[int, list[int]]     		=      {}
							# indexmap keys are an index and it's values are the number at that index
							__magic_name__    :     dict[int, int]     		=      {}
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   list[int]:
							if isinstance(lowerCAmelCase__    ,     (range, str)				):
													__magic_name__    :     int     		=      list(lowerCAmelCase__				)
							elif not isinstance(lowerCAmelCase__    ,     lowerCAmelCase__				):
													raise TypeError(
													    """binary_search_delete() only accepts either a list, range or str"""				)

							__magic_name__    :     str     		=      0
							__magic_name__    :     int     		=      len(lowerCAmelCase__				) - 1

							while low <= high:
													__magic_name__    :     List[str]     		=      (low + high) // 2
													if array[mid] == item:
																			array.pop(lowerCAmelCase__				)
																			return array
													elif array[mid] < item:
																			__magic_name__    :     Tuple     		=      mid + 1
													else:
																			__magic_name__    :     Dict     		=      mid - 1
							raise ValueError(
							    """Either the item is not in the array or the array was unsorted"""				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   list[int]:
							if isinstance(lowerCAmelCase__    ,     (range, str)				):
													__magic_name__    :     Tuple     		=      list(lowerCAmelCase__				)
							elif not isinstance(lowerCAmelCase__    ,     lowerCAmelCase__				):
													raise TypeError(
													    """binary_search_insert() only accepts either a list, range or str"""				)

							__magic_name__    :     List[str]     		=      0
							__magic_name__    :     Tuple     		=      len(lowerCAmelCase__				) - 1

							while low <= high:
													__magic_name__    :     Dict     		=      (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:
																			__magic_name__    :     int     		=      mid + 1
													else:
																			__magic_name__    :     Tuple     		=      mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
							array.insert(lowerCAmelCase__    ,     lowerCAmelCase__				)
							return array
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   None:
							# Remove previous index
							if index in self.indexmap:
													__magic_name__    :     int     		=      self.indexmap[index]
													if len(self.numbermap[n]				) == 1:
																			del self.numbermap[n]
													else:
																			__magic_name__    :     Union[str, Any]     		=      self.binary_search_delete(self.numbermap[n]    ,     lowerCAmelCase__				)

        # Set new index
							__magic_name__    :     List[Any]     		=      number

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

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







	def     __magic_name__       (       self    ,     lowerCAmelCase__				)							->   int:
							return self.numbermap.get(lowerCAmelCase__    ,     [-1]				)[0]


if __name__ == "__main__":
		import doctest

		doctest.testmod()
