

# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
					import tensorflow as tf

class __UpperCamelCase    (							TensorFormatter[Mapping, "tf.Tensor", Mapping]		):






					'''simple docstring'''



					def __init__(							self							,			lowerCamelCase__=None							,			**lowerCamelCase__	):
						super().__init__(features=lowerCamelCase__	)
						UpperCAmelCase__:  Dict		       =   tf_tensor_kwargs
						import tensorflow as tf  # noqa: import tf at initialization





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						import tensorflow as tf

						if isinstance(lowerCamelCase__							,			lowerCamelCase__	) and column:
							if all(
							    isinstance(lowerCamelCase__							,			tf.Tensor	) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column	):
								return tf.stack(lowerCamelCase__	)
							elif all(
							    isinstance(lowerCamelCase__							,			(tf.Tensor, tf.RaggedTensor)	) and x.ndim == 1 and x.dtype == column[0].dtype
							    for x in column	):
								# only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
								return tf.ragged.stack(lowerCamelCase__	)

						return column





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						import tensorflow as tf

						if value is None:
							return value

						UpperCAmelCase__:  str		       =   {}

						if isinstance(lowerCamelCase__							,			(np.number, np.ndarray)	) and np.issubdtype(value.dtype							,			np.integer	):
							UpperCAmelCase__:  Any		       =   {"dtype": tf.intaa}
						elif isinstance(lowerCamelCase__							,			(np.number, np.ndarray)	) and np.issubdtype(value.dtype							,			np.floating	):
							UpperCAmelCase__:  int		       =   {"dtype": tf.floataa}
						elif config.PIL_AVAILABLE and "PIL" in sys.modules:
							import PIL.Image

							if isinstance(lowerCamelCase__							,			PIL.Image.Image	):
								UpperCAmelCase__:  List[str]		       =   np.asarray(lowerCamelCase__	)

						return tf.convert_to_tensor(lowerCamelCase__							,			**{**default_dtype, **self.tf_tensor_kwargs}	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						import tensorflow as tf

						# support for torch, tf, jax etc.
						if config.TORCH_AVAILABLE and "torch" in sys.modules:
							import torch

							if isinstance(lowerCamelCase__							,			torch.Tensor	):
								return self._tensorize(data_struct.detach().cpu().numpy()[()]	)
						if hasattr(lowerCamelCase__							,			"__array__"	) and not isinstance(lowerCamelCase__							,			tf.Tensor	):
							UpperCAmelCase__:  Union[str, Any]		       =   data_struct.__array__()
						# support for nested types like struct of list of struct
						if isinstance(lowerCamelCase__							,			np.ndarray	):
							if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
								return self._consolidate([self.recursive_tensorize(lowerCamelCase__	) for substruct in data_struct]	)
						elif isinstance(lowerCamelCase__							,			(list, tuple)	):
							return self._consolidate([self.recursive_tensorize(lowerCamelCase__	) for substruct in data_struct]	)
						return self._tensorize(lowerCamelCase__	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						return map_nested(self._recursive_tensorize							,			lowerCamelCase__							,			map_list=lowerCamelCase__	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						UpperCAmelCase__:  List[Any]		       =   self.numpy_arrow_extractor().extract_row(lowerCamelCase__	)
						UpperCAmelCase__:  int		       =   self.python_features_decoder.decode_row(lowerCamelCase__	)
						return self.recursive_tensorize(lowerCamelCase__	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						UpperCAmelCase__:  List[str]		       =   self.numpy_arrow_extractor().extract_column(lowerCamelCase__	)
						UpperCAmelCase__:  List[Any]		       =   self.python_features_decoder.decode_column(lowerCamelCase__							,			pa_table.column_names[0]	)
						UpperCAmelCase__:  Tuple		       =   self.recursive_tensorize(lowerCamelCase__	)
						UpperCAmelCase__:  Optional[Any]		       =   self._consolidate(lowerCamelCase__	)
						return column





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
						UpperCAmelCase__:  List[str]		       =   self.numpy_arrow_extractor().extract_batch(lowerCamelCase__	)
						UpperCAmelCase__:  List[Any]		       =   self.python_features_decoder.decode_batch(lowerCamelCase__	)
						UpperCAmelCase__:  Optional[Any]		       =   self.recursive_tensorize(lowerCamelCase__	)
						for column_name in batch:
							UpperCAmelCase__:  Union[str, Any]		       =   self._consolidate(batch[column_name]	)
						return batch


from __future__ import annotations

from collections import Counter



def  _A  (			SCREAMING_SNAKE_CASE			):
	UpperCAmelCase__:  Optional[Any]		       =   [True] * n
	UpperCAmelCase__:  Any		       =   False
	UpperCAmelCase__:  Tuple		       =   False
	UpperCAmelCase__:  Optional[Any]		       =   True

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

	UpperCAmelCase__:  int		       =   [2]

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

	return primes



def  _A  (			SCREAMING_SNAKE_CASE			):
	UpperCAmelCase__:  List[Any]		       =   str(SCREAMING_SNAKE_CASE			)
	UpperCAmelCase__:  Tuple		       =   []
	UpperCAmelCase__:  Optional[int]		       =   ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

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

	return replacements



def  _A  (			SCREAMING_SNAKE_CASE = 8			):
	UpperCAmelCase__:  Union[str, Any]		       =   set()

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

	for prime in primes:
		if prime in numbers_checked:
			continue

		UpperCAmelCase__:  Optional[int]		       =   digit_replacements(SCREAMING_SNAKE_CASE			)

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

			if len(SCREAMING_SNAKE_CASE			) != family_length:
				continue

			return min(SCREAMING_SNAKE_CASE			)

	return -1


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