

import numpy as np







def _a					(			SCREAMING_SNAKE_CASE						:     List[str]       ,   SCREAMING_SNAKE_CASE						:     int       ,   SCREAMING_SNAKE_CASE						:     str						)       ->       Optional[int]:

 """simple docstring"""






 __lowerCAmelCase:  int        = n_draws * class_counts / class_counts.sum()
 # floored means we don't overshoot n_samples, but probably undershoot
 __lowerCAmelCase:  Optional[Any]        = np.floor(UpperCAmelCase__						)
 # we add samples according to how much "left over" probability
 # they had, until we arrive at n_samples
 __lowerCAmelCase:  List[str]        = int(n_draws - floored.sum()						)
 if need_to_add > 0:
  __lowerCAmelCase:  int        = continuous - floored
  __lowerCAmelCase:  Tuple        = np.sort(np.unique(UpperCAmelCase__						)						)[::-1]
  # add according to remainder, but break ties
  # randomly to avoid biases
  for value in values:
   ((__lowerCAmelCase   )      ,				   ):  List[Any]        = np.where(remainder == value						)
   # if we need_to_add less than what's in inds
   # we draw randomly from them.
   # if we need to add more, we add them all and
   # go to the next value
   __lowerCAmelCase:  List[str]        = min(len(UpperCAmelCase__						)       ,   UpperCAmelCase__						)
   __lowerCAmelCase:  int        = rng.choice(UpperCAmelCase__       ,   size=UpperCAmelCase__       ,   replace=UpperCAmelCase__						)
   floored[inds] += 1
   need_to_add -= add_now
   if need_to_add == 0:
    break
 return floored.astype(np.intaa						)







def _a					(			SCREAMING_SNAKE_CASE						:     Optional[int]       ,   SCREAMING_SNAKE_CASE						:     Optional[int]       ,   SCREAMING_SNAKE_CASE						:     Dict       ,   SCREAMING_SNAKE_CASE						:     Any       ,   SCREAMING_SNAKE_CASE						:     Union[str, Any]=10						)       ->       Tuple:

 """simple docstring"""






 __lowerCAmelCase      ,				__lowerCAmelCase:  Optional[int]        = np.unique(UpperCAmelCase__       ,   return_inverse=UpperCAmelCase__						)
 __lowerCAmelCase:  Union[str, Any]        = classes.shape[0]
 __lowerCAmelCase:  Any        = np.bincount(UpperCAmelCase__						)
 if np.min(UpperCAmelCase__						) < 2:
  raise ValueError('Minimum class count error'						)
 if n_train < n_classes:
  raise ValueError(
      'The train_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_train, n_classes)						)
 if n_test < n_classes:
  raise ValueError(
      'The test_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_test, n_classes)						)
 __lowerCAmelCase:  Dict        = np.split(np.argsort(UpperCAmelCase__       ,   kind='mergesort'						)       ,   np.cumsum(UpperCAmelCase__						)[:-1]						)
 for _ in range(UpperCAmelCase__						):
  __lowerCAmelCase:  Union[str, Any]        = approximate_mode(UpperCAmelCase__       ,   UpperCAmelCase__       ,   UpperCAmelCase__						)
  __lowerCAmelCase:  int        = class_counts - n_i
  __lowerCAmelCase:  Any        = approximate_mode(UpperCAmelCase__       ,   UpperCAmelCase__       ,   UpperCAmelCase__						)

  __lowerCAmelCase:  Union[str, Any]        = []
  __lowerCAmelCase:  Optional[int]        = []

  for i in range(UpperCAmelCase__						):
   __lowerCAmelCase:  Tuple        = rng.permutation(class_counts[i]						)
   __lowerCAmelCase:  List[Any]        = class_indices[i].take(UpperCAmelCase__       ,   mode='clip'						)
   train.extend(perm_indices_class_i[: n_i[i]]						)
   test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]]						)
  __lowerCAmelCase:  Tuple        = rng.permutation(UpperCAmelCase__						)
  __lowerCAmelCase:  str        = rng.permutation(UpperCAmelCase__						)

  yield train, test






"""simple docstring"""







from __future__ import annotations


def 	a__   (		UpperCAmelCase__							:      list      )->						int | float:
						UpperCAmelCase__       						=		sorted(UpperCAmelCase__      )
						UpperCAmelCase__       						=		len(UpperCAmelCase__      )
						UpperCAmelCase__       						=		length >> 1
						return (
						    (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
						    if length % 2 == 0
						    else sorted_list[mid_index]
						)


def 	a__   (		)->						Dict:
						import doctest

						doctest.testmod()


if __name__ == "__main__":
						main()

