




'''simple docstring'''







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase	):






   '''simple docstring'''







   if start == end:
      return start if lst[start] > item else start + 1
   if start > end:
      return start

   A__         =    (start + end) // 2
   if lst[mid] < item:
      return binary_search(UpperCAmelCase			,UpperCAmelCase			,mid + 1			,UpperCAmelCase	)
   elif lst[mid] > item:
      return binary_search(UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase			,mid - 1	)
   else:
      return mid







def 	_A			(   UpperCAmelCase	):






   '''simple docstring'''







   A__         =    len(UpperCAmelCase	)

   for index in range(1			,UpperCAmelCase	):
      A__         =    lst[index]
      A__         =    binary_search(UpperCAmelCase			,UpperCAmelCase			,0			,index - 1	)
      A__         =    lst[:pos] + [value] + lst[pos:index] + lst[index + 1 :]

   return lst







def 	_A			(   UpperCAmelCase			,UpperCAmelCase	):






   '''simple docstring'''







   if not left:
      return right

   if not right:
      return left

   if left[0] < right[0]:
      return [left[0], *merge(left[1:]			,UpperCAmelCase	)]

   return [right[0], *merge(UpperCAmelCase			,right[1:]	)]







def 	_A			(   UpperCAmelCase	):






   '''simple docstring'''







   A__         =    len(UpperCAmelCase	)
   A__     , A__         =    [], []
   A__         =    [lst[0]]
   A__         =    []
   A__         =    1
   while i < length:
      if lst[i] < lst[i - 1]:
         runs.append(UpperCAmelCase	)
         A__         =    [lst[i]]
      else:
         new_run.append(lst[i]	)
      i += 1
   runs.append(UpperCAmelCase	)

   for run in runs:
      sorted_runs.append(insertion_sort(UpperCAmelCase	)	)
   for run in sorted_runs:
      A__         =    merge(UpperCAmelCase			,UpperCAmelCase	)

   return sorted_array







def 	_A			(   ):






   '''simple docstring'''







   A__         =    [5, 9, 10, 3, -4, 5, 178, 92, 46, -18, 0, 7]
   A__         =    tim_sort(UpperCAmelCase	)
   print(UpperCAmelCase	)


if __name__ == "__main__":
    main()








'''simple docstring'''







def 	_A			(   UpperCAmelCase	):






   '''simple docstring'''







   if not isinstance(UpperCAmelCase			,UpperCAmelCase	) or not all(
       isinstance(UpperCAmelCase			,UpperCAmelCase	) and item >= 0 for item in citations	):
      raise ValueError('The citations should be a list of non negative integers.'	)

   citations.sort()
   A__         =    len(UpperCAmelCase	)

   for i in range(UpperCAmelCase	):
      if citations[len_citations - 1 - i] <= i:
         return i

   return len_citations


if __name__ == "__main__":
    import doctest

    doctest.testmod()


