


"""simple docstring"""
from __future__ import annotations

from collections import Counter






def 						lowercase				(	_snake_case		: int	)	->list[int]:
	"""simple docstring"""





	__snake_case      :		List[str]         =							[True] * n
	__snake_case      :		str         =							False
	__snake_case      :		int         =							False
	__snake_case      :		List[str]         =							True

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

	__snake_case      :		Dict         =							[2]

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

	return primes






def 						lowercase				(	_snake_case		: int	)	->list[list[int]]:
	"""simple docstring"""





	__snake_case      :		Optional[Any]         =							str(_snake_case	)
	__snake_case      :		str         =							[]
	__snake_case      :		List[Any]         =							['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

	for duplicate in Counter(_snake_case	) - Counter(set(_snake_case	)	):
		__snake_case      :		Union[str, Any]         =							[int(number_str.replace(_snake_case	,  _snake_case	)	) for digit in digits]
		replacements.append(_snake_case	)

	return replacements






def 						lowercase				(	_snake_case		: int = 8	)	->int:
	"""simple docstring"""





	__snake_case      :		Any         =							set()

	# Filter primes with less than 3 replaceable digits
	__snake_case      :		Dict         =							{
	    x for x in set(prime_sieve(1_000_000	)	) if len(str(_snake_case	)	) - len(set(str(_snake_case	)	)	) >= 3
	}

	for prime in primes:
		if prime in numbers_checked:
			continue

		__snake_case      :		Union[str, Any]         =							digit_replacements(_snake_case	)

		for family in replacements:
			numbers_checked.update(_snake_case	)
			__snake_case      :		Optional[Any]         =							primes.intersection(_snake_case	)

			if len(_snake_case	) != family_length:
				continue

			return min(_snake_case	)

	return -1


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









from __future__ import annotations

from abc import abstractmethod
from collections.abc import Iterable
from typing import Generic, Protocol, TypeVar


class 	a__						(    lowerCAmelCase_     ):

       @abstractmethod
       def __lt__( self   :  T   ,				lowerCamelCase_   :  T     ):
            pass

       @abstractmethod
       def __gt__( self   :  T   ,				lowerCamelCase_   :  T     ):
            pass

       @abstractmethod
       def __eq__( self   :  T   ,				lowerCamelCase_   :  object     ):
            pass

__lowerCamelCase   	=  TypeVar('''T''', bound=Comparable)


class 	a__						(    Generic[T]     ):

       def __init__( self   :  Tuple     ):
            a_     :  list[T]				      =     []
            a_     :  int				      =     0

       def __repr__( self   :  Optional[Any]     ):
            return str(self.h     )

       def     UpperCAmelCase( self   :  Dict   ,				lowerCamelCase_   :  int     ):
            if child_idx > 0:
                 return (child_idx - 1) // 2
            return None

       def     UpperCAmelCase( self   :  Any   ,				lowerCamelCase_   :  int     ):
            a_     :  Tuple				      =     2 * parent_idx + 1
            if left_child_index < self.heap_size:
                 return left_child_index
            return None

       def     UpperCAmelCase( self   :  List[Any]   ,				lowerCamelCase_   :  int     ):
            a_     :  List[Any]				      =     2 * parent_idx + 2
            if right_child_index < self.heap_size:
                 return right_child_index
            return None

       def     UpperCAmelCase( self   :  Optional[int]   ,				lowerCamelCase_   :  int     ):
            if index < self.heap_size:
                 a_     :  int				      =     index
                 a_     :  Union[str, Any]				      =     self.left_child_idx(lowerCamelCase_     )
                 a_     :  Optional[int]				      =     self.right_child_idx(lowerCamelCase_     )
                 # check which child is larger than its parent
                 if left_child is not None and self.h[left_child] > self.h[violation]:
                      a_     :  str				      =     left_child
                 if right_child is not None and self.h[right_child] > self.h[violation]:
                      a_     :  List[Any]				      =     right_child
                 # if violation indeed exists
                 if violation != index:
                      # swap to fix the violation
                      a_      ,      a_     :  int				      =     self.h[index], self.h[violation]
                      # fix the subsequent violation recursively if any
                      self.max_heapify(lowerCamelCase_     )

       def     UpperCAmelCase( self   :  List[str]   ,				lowerCamelCase_   :  Iterable[T]     ):
            a_     :  Dict				      =     list(lowerCamelCase_     )
            a_     :  int				      =     len(self.h     )
            if self.heap_size > 1:
                 # max_heapify from right to left but exclude leaves (last level)
                 for i in range(self.heap_size // 2 - 1   ,				-1   ,				-1     ):
                      self.max_heapify(lowerCamelCase_     )

       def     UpperCAmelCase( self   :  Tuple     ):
            if self.heap_size >= 2:
                 a_     :  int				      =     self.h[0]
                 a_     :  Dict				      =     self.h.pop(-1     )
                 self.heap_size -= 1
                 self.max_heapify(0     )
                 return me
            elif self.heap_size == 1:
                 self.heap_size -= 1
                 return self.h.pop(-1     )
            else:
                 raise Exception("""Empty heap"""     )

       def     UpperCAmelCase( self   :  List[str]   ,				lowerCamelCase_   :  T     ):
            self.h.append(lowerCamelCase_     )
            a_     :  Optional[int]				      =     (self.heap_size - 1) // 2
            self.heap_size += 1
            while idx >= 0:
                 self.max_heapify(lowerCamelCase_     )
                 a_     :  Union[str, Any]				      =     (idx - 1) // 2

       def     UpperCAmelCase( self   :  int     ):
            a_     :  Union[str, Any]				      =     self.heap_size
            for j in range(size - 1   ,				0   ,				-1     ):
                 a_      ,      a_     :  str				      =     self.h[j], self.h[0]
                 self.heap_size -= 1
                 self.max_heapify(0     )
            a_     :  Union[str, Any]				      =     size


if __name__ == "__main__":
       import doctest

       # run doc test
       doctest.testmod()

       # demo
       for unsorted in [
           [0],
           [2],
           [3, 5],
           [5, 3],
           [5, 5],
           [0, 0, 0, 0],
           [1, 1, 1, 1],
           [2, 2, 3, 5],
           [0, 2, 2, 3, 5],
           [2, 5, 3, 0, 2, 3, 0, 3],
           [6, 1, 2, 7, 9, 3, 4, 5, 10, 8],
           [103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5],
           [-45, -2, -5],
       ]:
              print(f'''unsorted array: {unsorted}''')

              __lowerCamelCase   	=  Heap()
              heap.build_max_heap(unsorted)
              print(f'''after build heap: {heap}''')

              print(f'''max value: {heap.extract_max()}''')
              print(f'''after max value removed: {heap}''')

              heap.insert(100)
              print(f'''after new value 100 inserted: {heap}''')

              heap.heap_sort()
              print(f'''heap-sorted array: {heap}\n''')



