


"""simple docstring"""







import math




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_ = 0						,		lowerCAmelCase_ = 0     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       end or len(lowerCAmelCase_     )
					for i in range(lowerCAmelCase_						,		lowerCAmelCase_     ):
										__SCREAMING_SNAKE_CASE		     =       i
										__SCREAMING_SNAKE_CASE		     =       array[i]
										while temp_index != start and temp_index_value < array[temp_index - 1]:
															__SCREAMING_SNAKE_CASE		     =       array[temp_index - 1]
															temp_index -= 1
										__SCREAMING_SNAKE_CASE		     =       temp_index_value
					return array




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):  # Max Heap




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       index
					__SCREAMING_SNAKE_CASE		     =       2 * index + 1  # Left Node
					__SCREAMING_SNAKE_CASE		     =       2 * index + 2  # Right Node

					if left_index < heap_size and array[largest] < array[left_index]:
										__SCREAMING_SNAKE_CASE		     =       left_index

					if right_index < heap_size and array[largest] < array[right_index]:
										__SCREAMING_SNAKE_CASE		     =       right_index

					if largest != index:
										__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       array[largest], array[index]
										heapify(lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     )




def      UpperCAmelCase__ (lowerCAmelCase_     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       len(lowerCAmelCase_     )

					for i in range(n // 2						,		-1						,		-1     ):
										heapify(lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     )

					for i in range(n - 1						,		0						,		-1     ):
										__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       array[0], array[i]
										heapify(lowerCAmelCase_						,		0						,		lowerCAmelCase_     )

					return array




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					if (array[first_index] > array[middle_index]) != (
					    array[first_index] > array[last_index]
					):
										return array[first_index]
					elif (array[middle_index] > array[first_index]) != (
					    array[middle_index] > array[last_index]
					):
										return array[middle_index]
					else:
										return array[last_index]




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       low
					__SCREAMING_SNAKE_CASE		     =       high
					while True:
										while array[i] < pivot:
															i += 1
										j -= 1
										while pivot < array[j]:
															j -= 1
										if i >= j:
															return i
										__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       array[j], array[i]
										i += 1




def      UpperCAmelCase__ (lowerCAmelCase_     ):




					'''simple docstring'''


					if len(lowerCAmelCase_     ) == 0:
										return array
					__SCREAMING_SNAKE_CASE		     =       2 * math.ceil(math.loga(len(lowerCAmelCase_     )     )     )
					__SCREAMING_SNAKE_CASE		     =       16
					return intro_sort(lowerCAmelCase_						,		0						,		len(lowerCAmelCase_     )						,		lowerCAmelCase_						,		lowerCAmelCase_     )




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					while end - start > size_threshold:
										if max_depth == 0:
															return heap_sort(lowerCAmelCase_     )
										max_depth -= 1
										__SCREAMING_SNAKE_CASE		     =       median_of_a(lowerCAmelCase_						,		lowerCAmelCase_						,		start + ((end - start) // 2) + 1						,		end - 1     )
										__SCREAMING_SNAKE_CASE		     =       partition(lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     )
										intro_sort(lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     )
										__SCREAMING_SNAKE_CASE		     =       p
					return insertion_sort(lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     )


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				a__       :							Dict        =  input('''Enter numbers separated by a comma : ''').strip()
				a__       :							int        =  [float(item) for item in user_input.split(''',''')]
				print(sort(unsorted))




"""simple docstring"""







from __future__ import annotations

import math




class 				UpperCamelCase_			:

	"""simple docstring"""





	def __init__(				self    :       Union[str, Any]    ,    UpperCAmelCase__    :       int     ) ->			None:
						__SCREAMING_SNAKE_CASE		     =       size
						# approximate the overall size of segment tree with given value
						__SCREAMING_SNAKE_CASE		     =       [0 for i in range(0    ,    4 * size     )]
						# create array to store lazy update
						__SCREAMING_SNAKE_CASE		     =       [0 for i in range(0    ,    4 * size     )]
						__SCREAMING_SNAKE_CASE		     =       [0 for i in range(0    ,    4 * size     )]  # flag for lazy update




	def 						UpperCAmelCase_   (				self    :       str    ,    UpperCAmelCase__    :       int     ) ->			int:
						return idx * 2




	def 						UpperCAmelCase_   (				self    :       Any    ,    UpperCAmelCase__    :       int     ) ->			int:
						return idx * 2 + 1




	def 						UpperCAmelCase_   (				self    :       List[Any]    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       list[int]     ) ->			None:
						if left_element == right_element:
											__SCREAMING_SNAKE_CASE		     =       a[left_element - 1]
						else:
											__SCREAMING_SNAKE_CASE		     =       (left_element + right_element) // 2
											self.build(self.left(UpperCAmelCase__     )    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
											self.build(self.right(UpperCAmelCase__     )    ,    mid + 1    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
											__SCREAMING_SNAKE_CASE		     =       max(
											    self.segment_tree[self.left(UpperCAmelCase__     )]    ,    self.segment_tree[self.right(UpperCAmelCase__     )]     )




	def 						UpperCAmelCase_   (				self    :       Tuple    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int     ) ->			bool:
						if self.flag[idx] is True:
											__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
											__SCREAMING_SNAKE_CASE		     =       False
											if left_element != right_element:
																__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
																__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
																__SCREAMING_SNAKE_CASE		     =       True
																__SCREAMING_SNAKE_CASE		     =       True

						if right_element < a or left_element > b:
											return True
						if left_element >= a and right_element <= b:
											__SCREAMING_SNAKE_CASE		     =       val
											if left_element != right_element:
																__SCREAMING_SNAKE_CASE		     =       val
																__SCREAMING_SNAKE_CASE		     =       val
																__SCREAMING_SNAKE_CASE		     =       True
																__SCREAMING_SNAKE_CASE		     =       True
											return True
						__SCREAMING_SNAKE_CASE		     =       (left_element + right_element) // 2
						self.update(self.left(UpperCAmelCase__     )    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
						self.update(self.right(UpperCAmelCase__     )    ,    mid + 1    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
						__SCREAMING_SNAKE_CASE		     =       max(
						    self.segment_tree[self.left(UpperCAmelCase__     )]    ,    self.segment_tree[self.right(UpperCAmelCase__     )]     )
						return True




	def 						UpperCAmelCase_   (				self    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int    ,    UpperCAmelCase__    :       int     ) ->			int | float:
						if self.flag[idx] is True:
											__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
											__SCREAMING_SNAKE_CASE		     =       False
											if left_element != right_element:
																__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
																__SCREAMING_SNAKE_CASE		     =       self.lazy[idx]
																__SCREAMING_SNAKE_CASE		     =       True
																__SCREAMING_SNAKE_CASE		     =       True
						if right_element < a or left_element > b:
											return -math.inf
						if left_element >= a and right_element <= b:
											return self.segment_tree[idx]
						__SCREAMING_SNAKE_CASE		     =       (left_element + right_element) // 2
						__SCREAMING_SNAKE_CASE		     =       self.query(self.left(UpperCAmelCase__     )    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
						__SCREAMING_SNAKE_CASE		     =       self.query(self.right(UpperCAmelCase__     )    ,    mid + 1    ,    UpperCAmelCase__    ,    UpperCAmelCase__    ,    UpperCAmelCase__     )
						return max(UpperCAmelCase__    ,    UpperCAmelCase__     )




	def __str__(				self    :       int     ) ->			str:
						return str([self.query(1    ,    1    ,    self.size    ,    UpperCAmelCase__    ,    UpperCAmelCase__     ) for i in range(1    ,    self.size + 1     )]     )


if __name__ == "__main__":
		a__       :							Tuple        =  [1, 2, -4, 7, 3, -5, 6, 1_1, -2_0, 9, 1_4, 1_5, 5, 2, -8]
		a__       :							Dict        =  1_5
		a__       :							int        =  SegmentTree(size)
		segt.build(1, 1, size, A)
		print(segt.query(1, 1, size, 4, 6))
		print(segt.query(1, 1, size, 7, 1_1))
		print(segt.query(1, 1, size, 7, 1_2))
		segt.update(1, 1, size, 1, 3, 1_1_1)
		print(segt.query(1, 1, size, 1, 1_5))
		segt.update(1, 1, size, 7, 8, 2_3_5)
		print(segt)
