





class       UpperCamelCase__			:




					"""simple docstring"""


					def __init__(		self							:	Tuple		):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE				:							dict[int, list[int]]						=	{}
							# indexmap keys are an index and it's values are the number at that index
							SCREAMING_SNAKE_CASE				:							dict[int, int]						=	{}


					def lowerCamelCase_	(		self							:	Tuple     ,		lowerCamelCase_							:	str     ,		lowerCamelCase_							:	Tuple		):

							'''simple docstring'''



							if isinstance(lowercase__     ,		(range, str)		):
									SCREAMING_SNAKE_CASE				:							Optional[Any]						=	list(lowercase__		)
							elif not isinstance(lowercase__     ,		lowercase__		):
									raise TypeError(
									    """binary_search_delete() only accepts either a list, range or str"""		)

							SCREAMING_SNAKE_CASE				:							Any						=	0
							SCREAMING_SNAKE_CASE				:							Optional[Any]						=	len(lowercase__		) - 1

							while low <= high:
									SCREAMING_SNAKE_CASE				:							List[str]						=	(low + high) // 2
									if array[mid] == item:
											array.pop(lowercase__		)
											return array
									elif array[mid] < item:
											SCREAMING_SNAKE_CASE				:							List[str]						=	mid + 1
									else:
											SCREAMING_SNAKE_CASE				:							List[str]						=	mid - 1
							raise ValueError(
							    """Either the item is not in the array or the array was unsorted"""		)


					def lowerCamelCase_	(		self							:	List[str]     ,		lowerCamelCase_							:	Optional[Any]     ,		lowerCamelCase_							:	List[str]		):

							'''simple docstring'''



							if isinstance(lowercase__     ,		(range, str)		):
									SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	list(lowercase__		)
							elif not isinstance(lowercase__     ,		lowercase__		):
									raise TypeError(
									    """binary_search_insert() only accepts either a list, range or str"""		)

							SCREAMING_SNAKE_CASE				:							Dict						=	0
							SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	len(lowercase__		) - 1

							while low <= high:
									SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	(low + high) // 2
									if array[mid] == index:
											# If the item already exists in the array,
											# insert it after the existing item
											array.insert(mid + 1     ,		lowercase__		)
											return array
									elif array[mid] < index:
											SCREAMING_SNAKE_CASE				:							List[str]						=	mid + 1
									else:
											SCREAMING_SNAKE_CASE				:							Any						=	mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
							array.insert(lowercase__     ,		lowercase__		)
							return array


					def lowerCamelCase_	(		self							:	Optional[int]     ,		lowerCamelCase_							:	Tuple     ,		lowerCamelCase_							:	List[Any]		):

							'''simple docstring'''



							if index in self.indexmap:
									SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	self.indexmap[index]
									if len(self.numbermap[n]		) == 1:
											del self.numbermap[n]
									else:
											SCREAMING_SNAKE_CASE				:							Any						=	self.binary_search_delete(self.numbermap[n]     ,		lowercase__		)

        # Set new index
							SCREAMING_SNAKE_CASE				:							Dict						=	number

							# Number not seen before or empty so insert number value
							if number not in self.numbermap:
									SCREAMING_SNAKE_CASE				:							Optional[Any]						=	[index]

							# Here we need to perform a binary search insertion in order to insert
							# The item in the correct place
							else:
									SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	self.binary_search_insert(
									    self.numbermap[number]     ,		lowercase__		)



					def lowerCamelCase_	(		self							:	str     ,		lowerCamelCase_							:	int		):

							'''simple docstring'''



							return self.numbermap.get(lowercase__     ,		[-1]		)[0]


if __name__ == "__main__":
							import doctest

							doctest.testmod()










'''simple docstring'''




from __future__ import annotations

from collections import Counter



def 						__A						(       lowerCamelCase_					):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE				:							int						=	[True] * n
		SCREAMING_SNAKE_CASE				:							Optional[Any]						=	False
		SCREAMING_SNAKE_CASE				:							Optional[Any]						=	False
		SCREAMING_SNAKE_CASE				:							Optional[int]						=	True

		for i in range(3	,	int(n**0.5 + 1					)	,	2					):
				SCREAMING_SNAKE_CASE				:							List[Any]						=	i * 2
				while index < n:
						SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	False
						SCREAMING_SNAKE_CASE				:							Optional[Any]						=	index + i

		SCREAMING_SNAKE_CASE				:							Dict						=	[2]

		for i in range(3	,	lowerCamelCase_	,	2					):
				if is_prime[i]:
						primes.append(lowerCamelCase_					)

		return primes



def 						__A						(       lowerCamelCase_					):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE				:							List[str]						=	str(lowerCamelCase_					)
		SCREAMING_SNAKE_CASE				:							List[str]						=	[]
		SCREAMING_SNAKE_CASE				:							Optional[int]						=	["""0""", """1""", """2""", """3""", """4""", """5""", """6""", """7""", """8""", """9"""]

		for duplicate in Counter(lowerCamelCase_					) - Counter(set(lowerCamelCase_					)					):
				SCREAMING_SNAKE_CASE				:							Tuple						=	[int(number_str.replace(lowerCamelCase_	,	lowerCamelCase_					)					) for digit in digits]
				replacements.append(lowerCamelCase_					)

		return replacements



def 						__A						(       lowerCamelCase_ = 8					):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE				:							Tuple						=	set()

		# Filter primes with less than 3 replaceable digits
		SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	{
		    x for x in set(prime_sieve(1_00_00_00					)					) if len(str(lowerCamelCase_					)					) - len(set(str(lowerCamelCase_					)					)					) >= 3
		}

		for prime in primes:
				if prime in numbers_checked:
						continue

				SCREAMING_SNAKE_CASE				:							int						=	digit_replacements(lowerCamelCase_					)

				for family in replacements:
						numbers_checked.update(lowerCamelCase_					)
						SCREAMING_SNAKE_CASE				:							Dict						=	primes.intersection(lowerCamelCase_					)

						if len(lowerCamelCase_					) != family_length:
								continue

						return min(lowerCamelCase_					)

		return -1


if __name__ == "__main__":
							print(solution())



