





'''simple docstring'''




def 	_lowerCAmelCase      (  __snake_case  :			List[str]      )					->					Any:
     __A						:			Any								=	0
     __A						:			Optional[int]								=	len(__snake_case      )

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

     return num_inversions






def 	_lowerCAmelCase      (  __snake_case  :			Any      )					->					str:
     if len(__snake_case      ) <= 1:
          return arr, 0
     __A						:			List[Any]								=	len(__snake_case      ) // 2
     __A						:			Optional[Any]								=	arr[0:mid]
     __A						:			List[Any]								=	arr[mid:]

     __A						:			List[Any]								=	count_inversions_recursive(__snake_case      )
     __A						:			int								=	count_inversions_recursive(__snake_case      )
     __A						:			List[str]								=	_count_cross_inversions(__snake_case			,							__snake_case      )

     __A						:			Optional[int]								=	inversion_p + inversions_q + cross_inversions
     return c, num_inversions






def 	_lowerCAmelCase      (  __snake_case  :			Tuple			,							__snake_case  :			str      )					->					Optional[Any]:
     __A						:			List[str]								=	[]
     __A						:			int								=	0
     while i < len(__snake_case      ) and j < len(__snake_case      ):
          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(__snake_case      ) - i
               r.append(q[j]      )
               j += 1
          else:
               r.append(p[i]      )
               i += 1

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

     return r, num_inversion






def 	_lowerCAmelCase      (  )					->					Optional[Any]:
     __A						:			Optional[int]								=	[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)

     __A						:			List[str]								=	count_inversions_bf(__snake_case      )
     __A						:			int								=	count_inversions_recursive(__snake_case      )

     assert num_inversions_bf == num_inversions_recursive == 8

     print('number of inversions = '			,							__snake_case      )

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

     arr_a.sort()
     __A						:			List[str]								=	count_inversions_bf(__snake_case      )
     __A						:			str								=	count_inversions_recursive(__snake_case      )

     assert num_inversions_bf == num_inversions_recursive == 0
     print('number of inversions = '			,							__snake_case      )

     # an empty list should also have zero inversions
     __A						:			Dict								=	[]
     __A						:			Optional[int]								=	count_inversions_bf(__snake_case      )
     __A						:			Dict								=	count_inversions_recursive(__snake_case      )

     assert num_inversions_bf == num_inversions_recursive == 0
     print('number of inversions = '			,							__snake_case      )


if __name__ == "__main__":
  main()








'''simple docstring'''




import math






def 	_lowerCAmelCase      (  __snake_case  :			int      )					->					int:

     if not isinstance(__snake_case			,							__snake_case      ):
          __A						:			List[Any]								=	f'Input value of [number={number}] must be an integer'
          raise TypeError(__snake_case      )

     if number < 1:
          __A						:			Union[str, Any]								=	f'Input value of [number={number}] must be > 0'
          raise ValueError(__snake_case      )
     elif number == 1:
          return 3
     elif number == 2:
          return 5
     else:
          __A						:			Optional[Any]								=	int(math.log(number // 3			,							2      )      ) + 2

          __A						:			Union[str, Any]								=	[3, 5]
          __A						:			List[Any]								=	2
          __A						:			Optional[Any]								=	3
          for block in range(1			,							__snake_case      ):
               for _ in range(__snake_case      ):
                    proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1]      )
                    proth_index += 1
               increment *= 2

     return proth_list[number - 1]


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  for number in range(11):
    lowercase__   :				str      =   0
    try:
      lowercase__   :				List[str]      =   proth(number)
    except ValueError:
      print(f"""ValueError: there is no {number}th Proth number""")
      continue

    print(f"""The {number}th Proth number: {value}""")