





"""simple docstring"""


import numpy as np

def     UpperCamelCase       (SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
						UpperCamelCase							:		List[str]							      = n_draws * class_counts / class_counts.sum()
						# floored means we don't overshoot n_samples, but probably undershoot
						UpperCamelCase							:		str							      = np.floor(SCREAMING_SNAKE_CASE    )
						# we add samples according to how much "left over" probability
						# they had, until we arrive at n_samples
						UpperCamelCase							:		Optional[Any]							      = int(n_draws - floored.sum()    )
						if need_to_add > 0:
												UpperCamelCase							:		List[str]							      = continuous - floored
												UpperCamelCase							:		str							      = np.sort(np.unique(SCREAMING_SNAKE_CASE    )    )[::-1]
												# add according to remainder, but break ties
												# randomly to avoid biases
												for value in values:
																		((UpperCamelCase    )      ,	    )							:		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
																		UpperCamelCase							:		Optional[Any]							      = min(len(SCREAMING_SNAKE_CASE    )       ,    SCREAMING_SNAKE_CASE    )
																		UpperCamelCase							:		Union[str, Any]							      = rng.choice(SCREAMING_SNAKE_CASE       ,    size=SCREAMING_SNAKE_CASE       ,    replace=SCREAMING_SNAKE_CASE    )
																		floored[inds] += 1
																		need_to_add -= add_now
																		if need_to_add == 0:
																								break
						return floored.astype(np.intaa    )

def     UpperCamelCase       (SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE=10    ):
						UpperCamelCase      ,	UpperCamelCase							:		Dict							      = np.unique(SCREAMING_SNAKE_CASE       ,    return_inverse=SCREAMING_SNAKE_CASE    )
						UpperCamelCase							:		Dict							      = classes.shape[0]
						UpperCamelCase							:		Union[str, Any]							      = np.bincount(SCREAMING_SNAKE_CASE    )
						if np.min(SCREAMING_SNAKE_CASE    ) < 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)    )
						UpperCamelCase							:		Dict							      = np.split(np.argsort(SCREAMING_SNAKE_CASE       ,    kind="""mergesort"""    )       ,    np.cumsum(SCREAMING_SNAKE_CASE    )[:-1]    )
						for _ in range(SCREAMING_SNAKE_CASE    ):
												UpperCamelCase							:		Optional[Any]							      = approximate_mode(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    )
												UpperCamelCase							:		Dict							      = class_counts - n_i
												UpperCamelCase							:		List[str]							      = approximate_mode(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    )

												UpperCamelCase							:		str							      = []
												UpperCamelCase							:		List[str]							      = []

												for i in range(SCREAMING_SNAKE_CASE    ):
																		UpperCamelCase							:		Any							      = rng.permutation(class_counts[i]    )
																		UpperCamelCase							:		Optional[int]							      = class_indices[i].take(SCREAMING_SNAKE_CASE       ,    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]]    )
												UpperCamelCase							:		int							      = rng.permutation(SCREAMING_SNAKE_CASE    )
												UpperCamelCase							:		Union[str, Any]							      = rng.permutation(SCREAMING_SNAKE_CASE    )

												yield train, test










"""simple docstring"""


from __future__ import annotations

def     UpperCamelCase       (SCREAMING_SNAKE_CASE    ):
						UpperCamelCase							:		Tuple							      = [0] * max_one

						for i in range(0       ,    SCREAMING_SNAKE_CASE    ):
												UpperCamelCase							:		Union[str, Any]							      = i

						for i in range(2       ,    SCREAMING_SNAKE_CASE    ):
												if totients[i] == i:
																		for j in range(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
																								totients[j] -= totients[j] // i

						return totients

def     UpperCamelCase       (SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
						return sorted(str(SCREAMING_SNAKE_CASE    )    ) == sorted(str(SCREAMING_SNAKE_CASE    )    )

def     UpperCamelCase       (SCREAMING_SNAKE_CASE = 1000_0000    ):
						UpperCamelCase							:		List[str]							      = 1  # i
						UpperCamelCase							:		Optional[int]							      = 0  # φ(i)
						UpperCamelCase							:		List[str]							      = get_totients(max_n + 1    )

						for i in range(2       ,    max_n + 1    ):
												UpperCamelCase							:		Tuple							      = totients[i]

												if i * min_denominator < min_numerator * t and has_same_digits(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
																		UpperCamelCase							:		str							      = i
																		UpperCamelCase							:		Tuple							      = t

						return min_numerator


if __name__ == "__main__":
		print(f'''{solution() = }''')



