






from __future__ import annotations

from collections import Counter


def        __snake_case       (						lowerCAmelCase_  )							->	list[int]:
    SCREAMING_SNAKE_CASE__       							= [True] * n
    SCREAMING_SNAKE_CASE__       							= False
    SCREAMING_SNAKE_CASE__       							= False
    SCREAMING_SNAKE_CASE__       							= True

    for i in range(3   ,       int(n**0.5 + 1  )   ,       2  ):
        SCREAMING_SNAKE_CASE__       							= i * 2
        while index < n:
            SCREAMING_SNAKE_CASE__       							= False
            SCREAMING_SNAKE_CASE__       							= index + i

    SCREAMING_SNAKE_CASE__       							= [2]

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

    return primes


def        __snake_case       (						lowerCAmelCase_  )							->	list[list[int]]:
    SCREAMING_SNAKE_CASE__       							= str(snake_case_  )
    SCREAMING_SNAKE_CASE__       							= []
    SCREAMING_SNAKE_CASE__       							= ['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

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

    return replacements


def        __snake_case       (						lowerCAmelCase_ = 8  )							->	int:
    SCREAMING_SNAKE_CASE__       							= set()

    # Filter primes with less than 3 replaceable digits
    SCREAMING_SNAKE_CASE__       							= {
        x for x in set(prime_sieve(1_0_0_0_0_0_0  )  ) if len(str(snake_case_  )  ) - len(set(str(snake_case_  )  )  ) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        SCREAMING_SNAKE_CASE__       							= digit_replacements(snake_case_  )

        for family in replacements:
            numbers_checked.update(snake_case_  )
            SCREAMING_SNAKE_CASE__       							= primes.intersection(snake_case_  )

            if len(snake_case_  ) != family_length:
                continue

            return min(snake_case_  )

    return -1


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







import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
  import transformer_engine.pytorch as te


def        __snake_case       (						lowerCAmelCase_   ,       lowerCAmelCase_=True   ,       lowerCAmelCase_=True   ,       lowerCAmelCase_=True  )							->	Tuple:
    if not is_fpa_available():
        raise ImportError('''Using `convert_model` requires transformer_engine to be installed.'''  )
    for name, module in model.named_children():
        if isinstance(lowerCAmelCase_   ,       nn.Linear  ) and to_transformer_engine and _convert_linear:
            # Return early if the linear layer weights are not multiples of 16
            if any(p % 1_6 != 0 for p in module.weight.shape  ):
                return
            SCREAMING_SNAKE_CASE__       							= module.bias is not None
            SCREAMING_SNAKE_CASE__       							= te.Linear(
                module.in_features   ,       module.out_features   ,       bias=lowerCAmelCase_   ,       params_dtype=module.weight.dtype  )
            SCREAMING_SNAKE_CASE__       							= module.weight.data.clone()
            if has_bias:
                SCREAMING_SNAKE_CASE__       							= module.bias.data.clone()

            setattr(lowerCAmelCase_   ,       lowerCAmelCase_   ,       lowerCAmelCase_  )
        elif isinstance(lowerCAmelCase_   ,       nn.LayerNorm  ) and to_transformer_engine and _convert_ln:
            SCREAMING_SNAKE_CASE__       							= te.LayerNorm(module.normalized_shape[0]   ,       eps=module.eps   ,       params_dtype=module.weight.dtype  )
            SCREAMING_SNAKE_CASE__       							= module.weight.data.clone()
            SCREAMING_SNAKE_CASE__       							= module.bias.data.clone()

            setattr(lowerCAmelCase_   ,       lowerCAmelCase_   ,       lowerCAmelCase_  )
        elif isinstance(lowerCAmelCase_   ,       te.Linear  ) and not to_transformer_engine and _convert_linear:
            SCREAMING_SNAKE_CASE__       							= module.bias is not None
            SCREAMING_SNAKE_CASE__       							= nn.Linear(
                module.in_features   ,       module.out_features   ,       bias=lowerCAmelCase_   ,       params_dtype=module.weight.dtype  )
            SCREAMING_SNAKE_CASE__       							= module.weight.data.clone()
            if has_bias:
                SCREAMING_SNAKE_CASE__       							= module.bias.data.clone()

            setattr(lowerCAmelCase_   ,       lowerCAmelCase_   ,       lowerCAmelCase_  )
        elif isinstance(lowerCAmelCase_   ,       te.LayerNorm  ) and not to_transformer_engine and _convert_ln:
            SCREAMING_SNAKE_CASE__       							= nn.LayerNorm(module.normalized_shape[0]   ,       eps=module.eps   ,       params_dtype=module.weight.dtype  )
            SCREAMING_SNAKE_CASE__       							= module.weight.data.clone()
            SCREAMING_SNAKE_CASE__       							= module.bias.data.clone()

            setattr(lowerCAmelCase_   ,       lowerCAmelCase_   ,       lowerCAmelCase_  )
        else:
            convert_model(
                lowerCAmelCase_   ,       to_transformer_engine=lowerCAmelCase_   ,       _convert_linear=_convert_linear   ,       _convert_ln=_convert_ln   ,       )



def        __snake_case       (						lowerCAmelCase_  )							->	Union[str, Any]:
    if not is_fpa_available():
        raise ImportError('''Using `has_transformer_engine_layers` requires transformer_engine to be installed.'''  )
    for m in model.modules():
        if isinstance(lowerCAmelCase_   ,       (te.LayerNorm, te.Linear)  ):
            return True
    return False
