






'''simple docstring'''







def  SCREAMING_SNAKE_CASE_       (UpperCamelCase      )      ->       Union[str, Any]:
							lowerCamelCase__					:	str         =       0
							lowerCamelCase__					:	Tuple         =       len(UpperCamelCase      )

							for i in range(n - 1      ):
														for j in range(i + 1				,			UpperCamelCase      ):
																					if arr[i] > arr[j]:
																												num_inversions += 1

							return num_inversions





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase      )      ->       Tuple:
							if len(UpperCamelCase      ) <= 1:
														return arr, 0
							lowerCamelCase__					:	Dict         =       len(UpperCamelCase      ) // 2
							lowerCamelCase__					:	Any         =       arr[0:mid]
							lowerCamelCase__					:	Any         =       arr[mid:]

							lowerCamelCase__  ,		lowerCamelCase__					:	List[Any]         =       count_inversions_recursive(UpperCamelCase      )
							lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       count_inversions_recursive(UpperCamelCase      )
							lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       _count_cross_inversions(UpperCamelCase				,			UpperCamelCase      )

							lowerCamelCase__					:	Dict         =       inversion_p + inversions_q + cross_inversions
							return c, num_inversions





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase      )      ->       Optional[int]:
							lowerCamelCase__					:	str         =       []
							lowerCamelCase__					:	Tuple         =       0
							while i < len(UpperCamelCase      ) and j < len(UpperCamelCase      ):
														if p[i] > q[j]:
																					# if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
																					# These are all inversions. The claim emerges from the
																					# property that P is sorted.
																					num_inversion += len(UpperCamelCase      ) - i
																					r.append(q[j]      )
																					j += 1
														else:
																					r.append(p[i]      )
																					i += 1

							if i < len(UpperCamelCase      ):
														r.extend(p[i:]      )
							else:
														r.extend(q[j:]      )

							return r, num_inversion





def  SCREAMING_SNAKE_CASE_       ()      ->       List[str]:
							lowerCamelCase__					:	List[Any]         =       [10, 2, 1, 5, 5, 2, 11]

							# this arr has 8 inversions:
							# (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

							lowerCamelCase__					:	int         =       count_inversions_bf(UpperCamelCase      )
							lowerCamelCase__  ,		lowerCamelCase__					:	Optional[Any]         =       count_inversions_recursive(UpperCamelCase      )

							assert num_inversions_bf == num_inversions_recursive == 8

							print("""number of inversions = """				,			UpperCamelCase      )

							# testing an array with zero inversion (a sorted arr_1)

							arr_a.sort()
							lowerCamelCase__					:	Union[str, Any]         =       count_inversions_bf(UpperCamelCase      )
							lowerCamelCase__  ,		lowerCamelCase__					:	Tuple         =       count_inversions_recursive(UpperCamelCase      )

							assert num_inversions_bf == num_inversions_recursive == 0
							print("""number of inversions = """				,			UpperCamelCase      )

							# an empty list should also have zero inversions
							lowerCamelCase__					:	Any         =       []
							lowerCamelCase__					:	Optional[Any]         =       count_inversions_bf(UpperCamelCase      )
							lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       count_inversions_recursive(UpperCamelCase      )

							assert num_inversions_bf == num_inversions_recursive == 0
							print("""number of inversions = """				,			UpperCamelCase      )


if __name__ == "__main__":
			main()









'''simple docstring'''







from collections.abc import Sequence





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase      )      ->       float:
							return sum(c * (x**i) for i, c in enumerate(UpperCamelCase      )      )





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase      )      ->       float:
							lowerCamelCase__					:	str         =       0.0
							for coeff in reversed(UpperCamelCase      ):
														lowerCamelCase__					:	Optional[int]         =       result * x + coeff
							return result


if __name__ == "__main__":
			_A	:			Any         =(0.0, 0.0, 5.0, 9.3, 7.0)
			_A	:			Optional[Any]         =10.0
			print(evaluate_poly(poly, x))
			print(horner(poly, x))

