



from __future__ import annotations

def 	a						(				_UpperCAmelCase							: list			,       _UpperCAmelCase							: list						):







		'''simple docstring'''





		__UpperCAmelCase   :					str													=     [None] * (len(_lowerCamelCase						) + len(_lowerCamelCase						))

		__UpperCAmelCase   :					Dict													=     0  # pointer to current index for left Half
		__UpperCAmelCase   :					str													=     0  # pointer to current index for the right Half
		__UpperCAmelCase   :					Any													=     0  # pointer to current index for the sorted array Half

		while pointera < len(_lowerCamelCase						) and pointera < len(_lowerCamelCase						):
				if left_half[pointera] < right_half[pointera]:
						__UpperCAmelCase   :					Optional[Any]													=     left_half[pointera]
						pointera += 1
						index += 1
				else:
						__UpperCAmelCase   :					Union[str, Any]													=     right_half[pointera]
						pointera += 1
						index += 1
		while pointera < len(_lowerCamelCase						):
				__UpperCAmelCase   :					Optional[int]													=     left_half[pointera]
				pointera += 1
				index += 1

		while pointera < len(_lowerCamelCase						):
				__UpperCAmelCase   :					Optional[int]													=     right_half[pointera]
				pointera += 1
				index += 1

		return sorted_array

def 	a						(				_UpperCAmelCase							: list						):







		'''simple docstring'''





		if len(_lowerCamelCase						) <= 1:
				return array
		# the actual formula to calculate the middle element = left + (right - left) // 2
		# this avoids integer overflow in case of large N
		__UpperCAmelCase   :					Union[str, Any]													=     0 + (len(_lowerCamelCase						) - 0) // 2

		# Split the array into halves till the array length becomes equal to One
		# merge the arrays of single length returned by mergeSort function and
		# pass them into the merge arrays function which merges the array
		__UpperCAmelCase   :					Dict													=     array[:middle]
		__UpperCAmelCase   :					Optional[int]													=     array[middle:]

		return merge(merge_sort(_lowerCamelCase						)			,       merge_sort(_lowerCamelCase						)						)


if __name__ == "__main__":
		import doctest

		doctest.testmod()










def 	a						(				_UpperCAmelCase							: Optional[int]			,       _UpperCAmelCase							: List[Any]						):







		'''simple docstring'''





		__UpperCAmelCase   :					int													=     len(_UpperCAmelCase						)
		# Create a stack and push index of fist element to it
		__UpperCAmelCase   :					List[Any]													=     []
		st.append(0						)

		# Span value of first element is always 1
		__UpperCAmelCase   :					Any													=     1

		# Calculate span values for rest of the elements
		for i in range(1			,       _UpperCAmelCase						):
				# Pop elements from stack while stack is not
				# empty and top of stack is smaller than price[i]
				while len(_UpperCAmelCase						) > 0 and price[st[0]] <= price[i]:
						st.pop()

				# If stack becomes empty, then price[i] is greater
				# than all elements on left of it, i.e. price[0],
				# price[1], ..price[i-1]. Else the price[i]  is
				# greater than elements after top of stack
				__UpperCAmelCase   :					int													=     i + 1 if len(_UpperCAmelCase						) <= 0 else (i - st[0])

				# Push this element to stack
				st.append(_UpperCAmelCase						)

def 	a						(				_UpperCAmelCase							: Dict			,       _UpperCAmelCase							: List[str]						):







		'''simple docstring'''





		for i in range(0			,       _UpperCAmelCase						):
				print(arr[i]			,       end=''' '''						)


# Driver program to test above function
__A             =[1_0, 4, 5, 9_0, 1_2_0, 8_0]
__A             =[0 for i in range(len(price) + 1)]

# Fill the span values in array S[]
calculation_span(price, S)
print_array(S, len(price))





