
import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)


class   __lowerCAmelCase		:



      """simple docstring"""







      def __init__( self						:    Union[str, Any]			,    _snake_case						:    Any			):
          __lowercase						:     Dict		      =    foo




      def __call__( self						:    List[Any]			):
          return self.foo






class   __lowerCAmelCase		(		datasets.Dataset ):



      """simple docstring"""







      @fingerprint_transform(inplace=_snake_case			)
      def 						snake_case_     ( self						:    Optional[Any]			,    _snake_case						:    Tuple			,    *_snake_case						:    Optional[Any]			,    **_snake_case						:    Optional[Any]			):
          return DatasetChild(self.data			,    fingerprint=_snake_case			)




      @fingerprint_transform(inplace=_snake_case			)
      def 						snake_case_     ( self						:    int			,    _snake_case						:    Optional[int]			,    *_snake_case						:    List[str]			,    **_snake_case						:    int			):
          return DatasetChild(self.data			,    fingerprint=_snake_case			)






class   __lowerCAmelCase		:



      """simple docstring"""







      def __init__( self						:    Dict			,    _snake_case						:    Any			):
          __lowercase						:     Optional[int]		      =    callable




      def __call__( self						:    Any			,    *_snake_case						:    List[str]			,    **_snake_case						:    Union[str, Any]			):
          if self.callable is not None:
              return self.callable(*_snake_case			,    **_snake_case			)




      def __getstate__( self						:    Tuple			):
          raise pickle.PicklingError()






class   __lowerCAmelCase		(		lowerCAmelCase_ ):



      """simple docstring"""







      @require_transformers
      @pytest.mark.integration
      def 						snake_case_     ( self						:    Any			):
          from transformers import AutoTokenizer

          def encode(_snake_case						:    Dict			):
              return tokenizer(_snake_case			)

          # TODO: add hash consistency tests across sessions
          __lowercase						:     List[Any]		      =    AutoTokenizer.from_pretrained('''bert-base-uncased'''			)
          __lowercase						:     Any		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Any		      =    mda(datasets.utils.py_utils.dumps(lambda _snake_case			: tokenizer(_snake_case			)			)			).hexdigest()
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Optional[Any]		      =    AutoTokenizer.from_pretrained('''bert-base-cased'''			)
          __lowercase						:     Optional[Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(lambda _snake_case			: tokenizer(_snake_case			)			)			).hexdigest()
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[Any]		      =    AutoTokenizer.from_pretrained('''bert-base-uncased'''			)
          __lowercase						:     Union[str, Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Any		      =    mda(datasets.utils.py_utils.dumps(lambda _snake_case			: tokenizer(_snake_case			)			)			).hexdigest()
          __lowercase						:     Union[str, Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      @require_transformers
      @pytest.mark.integration
      def 						snake_case_     ( self						:    Optional[int]			):
          from transformers import AutoTokenizer

          __lowercase						:     Tuple		      =    AutoTokenizer.from_pretrained('''gpt2'''			)
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          tokenizer('''Hello world !'''			)  # call once to change the tokenizer's cache
          __lowercase						:     str		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)




      @require_regex
      def 						snake_case_     ( self						:    str			):
          import regex

          __lowercase						:     str		      =    regex.Regex('''foo'''			)
          __lowercase						:     List[Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[Any]		      =    regex.Regex('''bar'''			)
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[Any]		      =    regex.Regex('''foo'''			)
          __lowercase						:     Tuple		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)






class   __lowerCAmelCase		(		lowerCAmelCase_ ):



      """simple docstring"""







      def 						snake_case_     ( self						:    Optional[Any]			):
          def func():
              return foo

          __lowercase						:     Union[str, Any]		      =    [0]
          __lowercase						:     Tuple		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     int		      =    [1]
          __lowercase						:     Tuple		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[Any]		      =    [0]
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    int			):
          def func():
              pass

          __lowercase						:     List[Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()

          def func():
              pass

          __lowercase						:     int		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Dict			):
          __lowercase						:     str		      =    mda(datasets.utils.py_utils.dumps(Foo([0]			)			)			).hexdigest()
          __lowercase						:     str		      =    mda(datasets.utils.py_utils.dumps(Foo([1]			)			)			).hexdigest()
          __lowercase						:     int		      =    mda(datasets.utils.py_utils.dumps(Foo([0]			)			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Any			):
          __lowercase						:     Union[str, Any]		      =    mda(datasets.utils.py_utils.dumps(Foo([0]			).__call__			)			).hexdigest()
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(Foo([1]			).__call__			)			).hexdigest()
          __lowercase						:     str		      =    mda(datasets.utils.py_utils.dumps(Foo([0]			).__call__			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Dict			):
          __lowercase						:     Union[str, Any]		      =    (
              '''co_argcount''',
              '''co_kwonlyargcount''',
              '''co_nlocals''',
              '''co_stacksize''',
              '''co_flags''',
              '''co_code''',
              '''co_consts''',
              '''co_names''',
              '''co_varnames''',
              '''co_filename''',
              '''co_name''',
              '''co_firstlineno''',
              '''co_lnotab''',
              '''co_freevars''',
              '''co_cellvars''',
          )

          def _create_code_pyaa(*_snake_case						:    int			):
              if hasattr(args[-3]			,    '''encode'''			):
                  __lowercase						:     Any		      =    list(_snake_case			)
                  __lowercase						:     str		      =    args[-3].encode()  # co_lnotab
                  __lowercase						:     List[str]		      =    args[-10].encode()  # co_code
              if hasattr(_snake_case			,    '''co_posonlyargcount'''			):
                  if len(_snake_case			) == 16:
                      return CodeType(*_snake_case			)
                  elif len(_snake_case			) == 15:
                      return CodeType(args[0]			,    0			,    *args[1:]			)
                  return CodeType(args[0]			,    0			,    0			,    *args[1:]			)
              elif hasattr(_snake_case			,    '''co_kwonlyargcount'''			):
                  if len(_snake_case			) == 16:
                      return CodeType(args[0]			,    *args[2:]			)
                  elif len(_snake_case			) == 15:
                      return CodeType(*_snake_case			)
                  return CodeType(args[0]			,    0			,    *args[1:]			)
              if len(_snake_case			) == 16:
                  return CodeType(args[0]			,    *args[3:]			)
              elif len(_snake_case			) == 15:
                  return CodeType(args[0]			,    *args[2:]			)
              return CodeType(*_snake_case			)

          def create_ipython_func(_snake_case						:    List[str]			,    _snake_case						:    str			):
              def func():
                  return returned_obj

              __lowercase						:     Tuple		      =    func.__code__
              # Use _create_code from dill in order to make it work for different python versions
              if datasets.config.PY_VERSION < version.parse('''3.8'''			):
                  __lowercase						:     Any		      =    _create_code_pyaa(
                      *[getattr(_snake_case			,    _snake_case			) if k != '''co_filename''' else co_filename for k in code_args_pyaa]			)
              else:
                  __lowercase						:     Dict		      =    code.replace(co_filename=_snake_case			)
              return FunctionType(_snake_case			,    func.__globals__			,    func.__name__			,    func.__defaults__			,    func.__closure__			)

          __lowercase      , __lowercase						:     int		      =    '''<ipython-input-2-e0383a102aae>''', [0]
          __lowercase						:     Any		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          __lowercase      , __lowercase						:     str		      =    '''<ipython-input-2-e0383a102aae>''', [1]
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          __lowercase      , __lowercase						:     Union[str, Any]		      =    '''<ipython-input-5-713f6613acf3>''', [0]
          __lowercase						:     int		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)

          __lowercase      , __lowercase						:     Union[str, Any]		      =    os.path.join(gettempdir()			,    '''ipykernel_12345'''			,    '''321456789.py'''			), [0]
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          __lowercase      , __lowercase						:     Tuple		      =    os.path.join(gettempdir()			,    '''ipykernel_12345'''			,    '''321456789.py'''			), [1]
          __lowercase						:     Optional[int]		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          __lowercase      , __lowercase						:     int		      =    os.path.join(gettempdir()			,    '''ipykernel_12345'''			,    '''654123987.py'''			), [0]
          __lowercase						:     Union[str, Any]		      =    mda(datasets.utils.py_utils.dumps(create_ipython_func(_snake_case			,    _snake_case			)			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Dict			):
          __lowercase      , __lowercase						:     Tuple		      =    [0], [1]

          def func():
              return foo, bar

          __lowercase						:     Any		      =    '''__main__'''

          def globalvars_mocka_side_effect(_snake_case						:    str			,    *_snake_case						:    Tuple			,    **_snake_case						:    str			):
              return {"foo": foo, "bar": bar}

          def globalvars_mocka_side_effect(_snake_case						:    Union[str, Any]			,    *_snake_case						:    int			,    **_snake_case						:    Optional[Any]			):
              return {"bar": bar, "foo": foo}

          with patch('''dill.detect.globalvars'''			,    side_effect=_snake_case			) as globalvars_mocka:
              __lowercase						:     Optional[int]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
              self.assertGreater(globalvars_mocka.call_count			,    0			)
          with patch('''dill.detect.globalvars'''			,    side_effect=_snake_case			) as globalvars_mocka:
              __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
              self.assertGreater(globalvars_mocka.call_count			,    0			)
          self.assertEqual(_snake_case			,    _snake_case			)






class   __lowerCAmelCase		(		lowerCAmelCase_ ):



      """simple docstring"""







      def 						snake_case_     ( self						:    Dict			):
          __lowercase						:     int		      =    Hasher.hash('''hello'''			)
          __lowercase						:     Dict		      =    Hasher.hash('''hello'''			)
          __lowercase						:     List[str]		      =    Hasher.hash('''there'''			)
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Union[str, Any]			):
          __lowercase						:     Optional[Any]		      =    Hasher.hash(Foo('''hello'''			)			)
          __lowercase						:     Optional[Any]		      =    Hasher.hash(Foo('''hello'''			)			)
          __lowercase						:     List[Any]		      =    Hasher.hash(Foo('''there'''			)			)
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Tuple			):
          __lowercase						:     Union[str, Any]		      =    Hasher()
          for x in ["hello", Foo('''hello'''			)]:
              hasher.update(_snake_case			)
          __lowercase						:     List[str]		      =    hasher.hexdigest()
          __lowercase						:     Dict		      =    Hasher()
          for x in ["hello", Foo('''hello'''			)]:
              hasher.update(_snake_case			)
          __lowercase						:     List[Any]		      =    hasher.hexdigest()
          __lowercase						:     Optional[int]		      =    Hasher()
          for x in ["there", Foo('''there'''			)]:
              hasher.update(_snake_case			)
          __lowercase						:     List[Any]		      =    hasher.hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      def 						snake_case_     ( self						:    Union[str, Any]			):
          with self.assertRaises(pickle.PicklingError			):
              Hasher.hash(UnpicklableCallable(Foo('''hello'''			)			)			)




      def 						snake_case_     ( self						:    Optional[int]			):
          __lowercase						:     Tuple		      =    '''abc'''
          __lowercase						:     Union[str, Any]		      =    [string, string]  # two strings have the same ids
          __lowercase						:     Tuple		      =    [string, string]
          __lowercase						:     Optional[int]		      =    json.loads(F'["{string}", "{string}"]'			)  # two strings have different ids
          self.assertIs(obja[0]			,    _snake_case			)
          self.assertIs(obja[0]			,    obja[1]			)
          self.assertIs(obja[0]			,    _snake_case			)
          self.assertIs(obja[0]			,    obja[1]			)
          self.assertIsNot(obja[0]			,    _snake_case			)
          self.assertIsNot(obja[0]			,    obja[1]			)
          __lowercase						:     Any		      =    Hasher.hash(_snake_case			)
          __lowercase						:     int		      =    Hasher.hash(_snake_case			)
          __lowercase						:     Any		      =    Hasher.hash(_snake_case			)
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertEqual(_snake_case			,    _snake_case			)




      @require_tiktoken
      def 						snake_case_     ( self						:    Optional[int]			):
          import tiktoken

          __lowercase						:     str		      =    tiktoken.get_encoding('''gpt2'''			)
          __lowercase						:     int		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Any		      =    tiktoken.get_encoding('''r50k_base'''			)
          __lowercase						:     Optional[int]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Optional[Any]		      =    tiktoken.get_encoding('''gpt2'''			)
          __lowercase						:     Union[str, Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      @require_torch
      def 						snake_case_     ( self						:    Dict			):
          import torch

          __lowercase						:     Union[str, Any]		      =    torch.tensor([1.0]			)
          __lowercase						:     List[Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[Any]		      =    torch.tensor([2.0]			)
          __lowercase						:     Optional[Any]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Tuple		      =    torch.tensor([1.0]			)
          __lowercase						:     Dict		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)




      @require_spacy
      @require_spacy_model('''en_core_web_sm'''			)
      @require_spacy_model('''fr_core_news_sm'''			)
      @pytest.mark.integration
      def 						snake_case_     ( self						:    List[str]			):
          import spacy

          __lowercase						:     Dict		      =    spacy.load('''en_core_web_sm'''			)
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     Tuple		      =    spacy.load('''fr_core_news_sm'''			)
          __lowercase						:     List[str]		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          __lowercase						:     List[str]		      =    spacy.load('''en_core_web_sm'''			)
          __lowercase						:     str		      =    mda(datasets.utils.py_utils.dumps(_snake_case			)			).hexdigest()
          self.assertEqual(_snake_case			,    _snake_case			)
          self.assertNotEqual(_snake_case			,    _snake_case			)






@pytest.mark.integration
def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  Dict:
    __lowercase						:     List[Any]		      =    tmp_path / '''dir1'''
    __lowercase						:     Tuple		      =    tmp_path / '''dir2'''
    dira.mkdir()
    dira.mkdir()
    __lowercase						:     Any		      =    '''script.py'''
    __lowercase						:     Optional[Any]		      =    dedent(
        '''
    from datasets.fingerprint import Hasher
    def foo():
        pass
    print(Hasher.hash(foo))
    '''		)
    __lowercase						:     Optional[Any]		      =    dira / script_filename
    __lowercase						:     Dict		      =    dira / script_filename
    with script_patha.open('''w'''		) as f:
        f.write(__lowerCAmelCase		)
    with script_patha.open('''w'''		) as f:
        f.write(__lowerCAmelCase		)
    __lowercase						:     int		      =    subprocess.check_output(['''python''', str(__lowerCAmelCase		)]		)
    __lowercase						:     str		      =    subprocess.check_output(['''python''', str(__lowerCAmelCase		)]		)
    assert fingerprinta == fingerprinta


def       UpperCAmelCase_					(  )	->  str:
    __lowercase						:     int		      =    {'''a''': [0, 1, 2]}
    __lowercase						:     Union[str, Any]		      =    DatasetChild(InMemoryTable.from_pydict(__lowerCAmelCase		)		)
    __lowercase						:     List[Any]		      =    dataset.funca()._fingerprint
    assert expected_fingerprint == dataset.funca()._fingerprint
    assert expected_fingerprint != dataset.funca()._fingerprint

    with Pool(2		) as p:
        assert expected_fingerprint == p.apply_async(dataset.funca		).get()._fingerprint
        assert expected_fingerprint != p.apply_async(dataset.funca		).get()._fingerprint


def       UpperCAmelCase_					(  )	->  List[str]:
    __lowercase						:     List[Any]		      =    {'''a''': [0, 1, 2]}


    class   __lowerCAmelCase		(		datasets.Dataset ):



          """simple docstring"""







          @fingerprint_transform(inplace=_snake_case			)
          def 						snake_case_     ( self						:    Tuple			,    _snake_case						:    str			):
              return DummyDatasetChild(self.data			,    fingerprint=_snake_case			)






    __lowercase						:     str		      =    DummyDatasetChild(InMemoryTable.from_pydict(__lowerCAmelCase		)		).func()


    class   __lowerCAmelCase		(		datasets.Dataset ):



          """simple docstring"""







          @fingerprint_transform(inplace=_snake_case			,    version='''1.0.0'''			)
          def 						snake_case_     ( self						:    int			,    _snake_case						:    Dict			):
              return DummyDatasetChild(self.data			,    fingerprint=_snake_case			)






    __lowercase						:     Union[str, Any]		      =    DummyDatasetChild(InMemoryTable.from_pydict(__lowerCAmelCase		)		).func()


    class   __lowerCAmelCase		(		datasets.Dataset ):



          """simple docstring"""







          @fingerprint_transform(inplace=_snake_case			,    version='''2.0.0'''			)
          def 						snake_case_     ( self						:    str			,    _snake_case						:    Dict			):
              return DummyDatasetChild(self.data			,    fingerprint=_snake_case			)






    __lowercase						:     List[str]		      =    DummyDatasetChild(InMemoryTable.from_pydict(__lowerCAmelCase		)		).func()

    assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}		) == 3





def       UpperCAmelCase_					(  )	->  int:
    # AttributeError: module 'dill._dill' has no attribute 'stack'
    __lowercase						:     Dict		      =    Hasher()
    hasher.update(lambda __lowerCAmelCase		: x		)




from __future__ import annotations

from collections import Counter


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[int]:
    __lowercase						:     Any		      =    [True] * n
    __lowercase						:     str		      =    False
    __lowercase						:     int		      =    False
    __lowercase						:     List[Any]		      =    True

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

    __lowercase						:     Tuple		      =    [2]

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

    return primes


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[list[int]]:
    __lowercase						:     Optional[int]		      =    str(__lowerCAmelCase		)
    __lowercase						:     List[str]		      =    []
    __lowercase						:     int		      =    ['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

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

    return replacements


def       UpperCAmelCase_					(  __lowerCAmelCase = 8		)	->  int:
    __lowercase						:     Tuple		      =    set()

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

    for prime in primes:
        if prime in numbers_checked:
            continue

        __lowercase						:     str		      =    digit_replacements(__lowerCAmelCase		)

        for family in replacements:
            numbers_checked.update(__lowerCAmelCase		)
            __lowercase						:     List[Any]		      =    primes.intersection(__lowerCAmelCase		)

            if len(__lowerCAmelCase		) != family_length:
                continue

            return min(__lowerCAmelCase		)

    return -1


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


