





'''simple docstring'''


import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
       import jax.numpy as jnp

class    lowerCAmelCase_		(		__magic_name__		):




 def __get__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase=None		)    ->							Union[str, Any]:
     # See docs.python.org/3/howto/descriptor.html#properties
     if obj is None:
         return self
     if self.fget is None:
         raise AttributeError("unreadable attribute"		)
     _lowerCAmelCase				=      '''__cached_''' + self.fget.__name__
     _lowerCAmelCase				=      getattr(UpperCAmelCase__			,     UpperCAmelCase__			,     UpperCAmelCase__		)
     if cached is None:
         _lowerCAmelCase				=      self.fget(UpperCAmelCase__		)
         setattr(UpperCAmelCase__			,     UpperCAmelCase__			,     UpperCAmelCase__		)
     return cached







def 	__a(SCREAMING_SNAKE_CASE_  :					Tuple    ):



    '''simple docstring'''





    _lowerCAmelCase				=      val.lower()
    if val in {"y", "yes", "t", "true", "on", "1"}:
        return 1
    if val in {"n", "no", "f", "false", "off", "0"}:
        return 0
    raise ValueError(F'''invalid truth value {val!r}'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					List[Any]    ):



    '''simple docstring'''





    if is_torch_fx_proxy(SCREAMING_SNAKE_CASE_    ):
        return True
    if is_torch_available():
        import torch

        if isinstance(SCREAMING_SNAKE_CASE_		,       torch.Tensor    ):
            return True
    if is_tf_available():
        import tensorflow as tf

        if isinstance(SCREAMING_SNAKE_CASE_		,       tf.Tensor    ):
            return True

    if is_flax_available():
        import jax.numpy as jnp
        from jax.core import Tracer

        if isinstance(SCREAMING_SNAKE_CASE_		,       (jnp.ndarray, Tracer)    ):
            return True

    return isinstance(SCREAMING_SNAKE_CASE_		,       np.ndarray    )


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    return isinstance(SCREAMING_SNAKE_CASE_		,       np.ndarray    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[int]    ):



    '''simple docstring'''





    return _is_numpy(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Tuple    ):



    '''simple docstring'''





    import torch

    return isinstance(SCREAMING_SNAKE_CASE_		,       torch.Tensor    )


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    return False if not is_torch_available() else _is_torch(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Tuple    ):



    '''simple docstring'''





    import torch

    return isinstance(SCREAMING_SNAKE_CASE_		,       torch.device    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    return False if not is_torch_available() else _is_torch_device(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					List[str]    ):



    '''simple docstring'''





    import torch

    if isinstance(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
        if hasattr(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
            _lowerCAmelCase				=      getattr(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
        else:
            return False
    return isinstance(SCREAMING_SNAKE_CASE_		,       torch.dtype    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[Any]    ):



    '''simple docstring'''





    return False if not is_torch_available() else _is_torch_dtype(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    import tensorflow as tf

    return isinstance(SCREAMING_SNAKE_CASE_		,       tf.Tensor    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    return False if not is_tf_available() else _is_tensorflow(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    import tensorflow as tf

    # the `is_symbolic_tensor` predicate is only available starting with TF 2.14
    if hasattr(SCREAMING_SNAKE_CASE_		,       "is_symbolic_tensor"    ):
        return tf.is_symbolic_tensor(SCREAMING_SNAKE_CASE_    )
    return type(SCREAMING_SNAKE_CASE_    ) == tf.Tensor


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[int]    ):



    '''simple docstring'''





    return False if not is_tf_available() else _is_tf_symbolic_tensor(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Union[str, Any]    ):



    '''simple docstring'''





    import jax.numpy as jnp  # noqa: F811

    return isinstance(SCREAMING_SNAKE_CASE_		,       jnp.ndarray    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    return False if not is_flax_available() else _is_jax(SCREAMING_SNAKE_CASE_    )


def 	__a(SCREAMING_SNAKE_CASE_  :					List[Any]    ):



    '''simple docstring'''





    if isinstance(SCREAMING_SNAKE_CASE_		,       (dict, UserDict)    ):
        return {k: to_py_obj(SCREAMING_SNAKE_CASE_    ) for k, v in obj.items()}
    elif isinstance(SCREAMING_SNAKE_CASE_		,       (list, tuple)    ):
        return [to_py_obj(SCREAMING_SNAKE_CASE_    ) for o in obj]
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        return obj.numpy().tolist()
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return obj.detach().cpu().tolist()
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return np.asarray(SCREAMING_SNAKE_CASE_    ).tolist()
    elif isinstance(SCREAMING_SNAKE_CASE_		,       (np.ndarray, np.number)    ):  # tolist also works on 0d np arrays
        return obj.tolist()
    else:
        return obj


def 	__a(SCREAMING_SNAKE_CASE_  :					Tuple    ):



    '''simple docstring'''





    if isinstance(SCREAMING_SNAKE_CASE_		,       (dict, UserDict)    ):
        return {k: to_numpy(SCREAMING_SNAKE_CASE_    ) for k, v in obj.items()}
    elif isinstance(SCREAMING_SNAKE_CASE_		,       (list, tuple)    ):
        return np.array(SCREAMING_SNAKE_CASE_    )
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        return obj.numpy()
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return obj.detach().cpu().numpy()
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return np.asarray(SCREAMING_SNAKE_CASE_    )
    else:
        return obj

class    lowerCAmelCase_		(		__magic_name__		):




 def 							_snake_case   (	self		)    ->							Any:
     _lowerCAmelCase				=      fields(self		)

     # Safety and consistency checks
     if not len(UpperCAmelCase__		):
         raise ValueError(f'''{self.__class__.__name__} has no fields.'''		)
     if not all(field.default is None for field in class_fields[1:]		):
         raise ValueError(f'''{self.__class__.__name__} should not have more than one required field.'''		)

     _lowerCAmelCase				=      getattr(self			,     class_fields[0].name		)
     _lowerCAmelCase				=      all(getattr(self			,     field.name		) is None for field in class_fields[1:]		)

     if other_fields_are_none and not is_tensor(UpperCAmelCase__		):
         if isinstance(UpperCAmelCase__			,     UpperCAmelCase__		):
             _lowerCAmelCase				=      first_field.items()
             _lowerCAmelCase				=      True
         else:
             try:
                 _lowerCAmelCase				=      iter(UpperCAmelCase__		)
                 _lowerCAmelCase				=      True
             except TypeError:
                 _lowerCAmelCase				=      False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
         if first_field_iterator:
             for idx, element in enumerate(UpperCAmelCase__		):
                 if (
                     not isinstance(UpperCAmelCase__			,     (list, tuple)		)
                     or not len(UpperCAmelCase__		) == 2
                     or not isinstance(element[0]			,     UpperCAmelCase__		)
                 ):
                     if idx == 0:
                         # If we do not have an iterator of key/values, set it as attribute
                         _lowerCAmelCase				=      first_field
                     else:
                         # If we have a mixed iterator, raise an error
                         raise ValueError(
                             f'''Cannot set key/value for {element}. It needs to be a tuple (key, value).'''		)
                     break
                 setattr(self			,     element[0]			,     element[1]		)
                 if element[1] is not None:
                     _lowerCAmelCase				=      element[1]
         elif first_field is not None:
             _lowerCAmelCase				=      first_field
     else:
         for field in class_fields:
             _lowerCAmelCase				=      getattr(self			,     field.name		)
             if v is not None:
                 _lowerCAmelCase				=      v




 def __delitem__(	self			,     *_lowerCAmelCase			,     **_lowerCAmelCase		)    ->							Optional[Any]:
     raise Exception(f'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''		)




 def 							_snake_case   (	self			,     *_lowerCAmelCase			,     **_lowerCAmelCase		)    ->							Any:
     raise Exception(f'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''		)




 def 							_snake_case   (	self			,     *_lowerCAmelCase			,     **_lowerCAmelCase		)    ->							Optional[Any]:
     raise Exception(f'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''		)




 def 							_snake_case   (	self			,     *_lowerCAmelCase			,     **_lowerCAmelCase		)    ->							Any:
     raise Exception(f'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''		)




 def __getitem__(	self			,     _lowerCAmelCase		)    ->							Union[str, Any]:
     if isinstance(UpperCAmelCase__			,     UpperCAmelCase__		):
         _lowerCAmelCase				=      dict(self.items()		)
         return inner_dict[k]
     else:
         return self.to_tuple()[k]




 def __setattr__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase		)    ->							Dict:
     if name in self.keys() and value is not None:
         # Don't call self.__setitem__ to avoid recursion errors
         super().__setitem__(UpperCAmelCase__			,     UpperCAmelCase__		)
     super().__setattr__(UpperCAmelCase__			,     UpperCAmelCase__		)




 def __setitem__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase		)    ->							List[str]:
     super().__setitem__(UpperCAmelCase__			,     UpperCAmelCase__		)
     # Don't call self.__setattr__ to avoid recursion errors
     super().__setattr__(UpperCAmelCase__			,     UpperCAmelCase__		)





 def 							_snake_case   (	self		)    ->							List[str]:
     return tuple(self[k] for k in self.keys()		)







class    lowerCAmelCase_		(		__magic_name__						,__magic_name__		):




 @classmethod
 def 							_snake_case   (	cls			,     _lowerCAmelCase		)    ->							Dict:
     raise ValueError(
         f'''{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()		)}'''		)







class    lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase						:							Optional[Any]         =					'longest'
 __lowerCamelCase						:							Tuple         =					'max_length'
 __lowerCamelCase						:							Any         =					'do_not_pad'







class    lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase						:							Optional[int]         =					'pt'
 __lowerCamelCase						:							List[Any]         =					'tf'
 __lowerCamelCase						:							List[str]         =					'np'
 __lowerCamelCase						:							Optional[Any]         =					'jax'







class    lowerCAmelCase_		:




 def __init__(	self			,     _lowerCAmelCase		)    ->							Optional[Any]:
     _lowerCAmelCase				=      context_managers
     _lowerCAmelCase				=      ExitStack()




 def __enter__(	self		)    ->							Any:
     for context_manager in self.context_managers:
         self.stack.enter_context(UpperCAmelCase__		)





 def __exit__(	self			,     *_lowerCAmelCase			,     **_lowerCAmelCase		)    ->							Optional[Any]:
     self.stack.__exit__(*UpperCAmelCase__			,     **UpperCAmelCase__		)







def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[Any]    ):



    '''simple docstring'''





    _lowerCAmelCase				=      infer_framework(SCREAMING_SNAKE_CASE_    )
    if framework == "tf":
        _lowerCAmelCase				=      inspect.signature(model_class.call    )  # TensorFlow models
    elif framework == "pt":
        _lowerCAmelCase				=      inspect.signature(model_class.forward    )  # PyTorch models
    else:
        _lowerCAmelCase				=      inspect.signature(model_class.__call__    )  # Flax models

    for p in signature.parameters:
        if p == "return_loss" and signature.parameters[p].default is True:
            return True

    return False


def 	__a(SCREAMING_SNAKE_CASE_  :					List[str]    ):



    '''simple docstring'''





    _lowerCAmelCase				=      model_class.__name__
    _lowerCAmelCase				=      infer_framework(SCREAMING_SNAKE_CASE_    )
    if framework == "tf":
        _lowerCAmelCase				=      inspect.signature(model_class.call    )  # TensorFlow models
    elif framework == "pt":
        _lowerCAmelCase				=      inspect.signature(model_class.forward    )  # PyTorch models
    else:
        _lowerCAmelCase				=      inspect.signature(model_class.__call__    )  # Flax models

    if "QuestionAnswering" in model_name:
        return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
    else:
        return [p for p in signature.parameters if "label" in p]


def 	__a(SCREAMING_SNAKE_CASE_  :					Dict		,       SCREAMING_SNAKE_CASE_  :					str = ""		,       SCREAMING_SNAKE_CASE_  :					Dict = "."    ):



    '''simple docstring'''





    def _flatten_dict(SCREAMING_SNAKE_CASE_  :					Union[str, Any]		,       SCREAMING_SNAKE_CASE_  :					Tuple=""		,       SCREAMING_SNAKE_CASE_  :					Tuple="."    ):
        for k, v in d.items():
            _lowerCAmelCase				=      str(SCREAMING_SNAKE_CASE_    ) + delimiter + str(SCREAMING_SNAKE_CASE_    ) if parent_key else k
            if v and isinstance(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
                yield from flatten_dict(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_		,       delimiter=SCREAMING_SNAKE_CASE_    ).items()
            else:
                yield key, v

    return dict(_flatten_dict(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )    )


@contextmanager
def 	__a(SCREAMING_SNAKE_CASE_  :					Union[str, Any]		,       SCREAMING_SNAKE_CASE_  :					Tuple = False    ):



    '''simple docstring'''





    if use_temp_dir:
        with tempfile.TemporaryDirectory() as tmp_dir:
            yield tmp_dir
    else:
        yield working_dir


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[int]		,       SCREAMING_SNAKE_CASE_  :					Union[str, Any]=None    ):



    '''simple docstring'''





    if is_numpy_array(SCREAMING_SNAKE_CASE_    ):
        return np.transpose(SCREAMING_SNAKE_CASE_		,       axes=SCREAMING_SNAKE_CASE_    )
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.T if axes is None else array.permute(*SCREAMING_SNAKE_CASE_    )
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        import tensorflow as tf

        return tf.transpose(SCREAMING_SNAKE_CASE_		,       perm=SCREAMING_SNAKE_CASE_    )
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return jnp.transpose(SCREAMING_SNAKE_CASE_		,       axes=SCREAMING_SNAKE_CASE_    )
    else:
        raise ValueError(F'''Type not supported for transpose: {type(SCREAMING_SNAKE_CASE_    )}.'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Tuple		,       SCREAMING_SNAKE_CASE_  :					Optional[int]    ):



    '''simple docstring'''





    if is_numpy_array(SCREAMING_SNAKE_CASE_    ):
        return np.reshape(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.reshape(*SCREAMING_SNAKE_CASE_    )
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        import tensorflow as tf

        return tf.reshape(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return jnp.reshape(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
    else:
        raise ValueError(F'''Type not supported for reshape: {type(SCREAMING_SNAKE_CASE_    )}.'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[Any]		,       SCREAMING_SNAKE_CASE_  :					Union[str, Any]=None    ):



    '''simple docstring'''





    if is_numpy_array(SCREAMING_SNAKE_CASE_    ):
        return np.squeeze(SCREAMING_SNAKE_CASE_		,       axis=SCREAMING_SNAKE_CASE_    )
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.squeeze() if axis is None else array.squeeze(dim=SCREAMING_SNAKE_CASE_    )
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        import tensorflow as tf

        return tf.squeeze(SCREAMING_SNAKE_CASE_		,       axis=SCREAMING_SNAKE_CASE_    )
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return jnp.squeeze(SCREAMING_SNAKE_CASE_		,       axis=SCREAMING_SNAKE_CASE_    )
    else:
        raise ValueError(F'''Type not supported for squeeze: {type(SCREAMING_SNAKE_CASE_    )}.'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Optional[int]		,       SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if is_numpy_array(SCREAMING_SNAKE_CASE_    ):
        return np.expand_dims(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.unsqueeze(dim=SCREAMING_SNAKE_CASE_    )
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        import tensorflow as tf

        return tf.expand_dims(SCREAMING_SNAKE_CASE_		,       axis=SCREAMING_SNAKE_CASE_    )
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return jnp.expand_dims(SCREAMING_SNAKE_CASE_		,       axis=SCREAMING_SNAKE_CASE_    )
    else:
        raise ValueError(F'''Type not supported for expand_dims: {type(SCREAMING_SNAKE_CASE_    )}.'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					Any    ):



    '''simple docstring'''





    if is_numpy_array(SCREAMING_SNAKE_CASE_    ):
        return np.size(SCREAMING_SNAKE_CASE_    )
    elif is_torch_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.numel()
    elif is_tf_tensor(SCREAMING_SNAKE_CASE_    ):
        import tensorflow as tf

        return tf.size(SCREAMING_SNAKE_CASE_    )
    elif is_jax_tensor(SCREAMING_SNAKE_CASE_    ):
        return array.size
    else:
        raise ValueError(F'''Type not supported for expand_dims: {type(SCREAMING_SNAKE_CASE_    )}.'''    )


def 	__a(SCREAMING_SNAKE_CASE_  :					List[Any]		,       SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    for key, value in auto_map.items():
        if isinstance(SCREAMING_SNAKE_CASE_		,       (tuple, list)    ):
            _lowerCAmelCase				=      [F'''{repo_id}--{v}''' if (v is not None and '''--''' not in v) else v for v in value]
        elif value is not None and "--" not in value:
            _lowerCAmelCase				=      F'''{repo_id}--{value}'''

    return auto_map





def 	__a(SCREAMING_SNAKE_CASE_  :					Any    ):



    '''simple docstring'''





    for base_class in inspect.getmro(SCREAMING_SNAKE_CASE_    ):
        _lowerCAmelCase				=      base_class.__module__
        _lowerCAmelCase				=      base_class.__name__
        if module.startswith("tensorflow"    ) or module.startswith("keras"    ) or name == "TFPreTrainedModel":
            return "tf"
        elif module.startswith("torch"    ) or name == "PreTrainedModel":
            return "pt"
        elif module.startswith("flax"    ) or module.startswith("jax"    ) or name == "FlaxPreTrainedModel":
            return "flax"
    else:
        raise TypeError(F'''Could not infer framework from class {model_class}.'''    )









'''simple docstring'''


from math import isqrt, loga


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    _lowerCAmelCase				=      [True] * max_number
    for i in range(2		,       isqrt(max_number - 1    ) + 1    ):
        if is_prime[i]:
            for j in range(i**2		,       SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
                _lowerCAmelCase				=      False

    return [i for i in range(2		,       SCREAMING_SNAKE_CASE_    ) if is_prime[i]]


def 	__a(SCREAMING_SNAKE_CASE_  :					int = 800800		,       SCREAMING_SNAKE_CASE_  :					int = 800800    ):



    '''simple docstring'''





    _lowerCAmelCase				=      degree * loga(SCREAMING_SNAKE_CASE_    )
    _lowerCAmelCase				=      int(SCREAMING_SNAKE_CASE_    )
    _lowerCAmelCase				=      calculate_prime_numbers(SCREAMING_SNAKE_CASE_    )

    _lowerCAmelCase				=      0
    _lowerCAmelCase				=      0
    _lowerCAmelCase				=      len(SCREAMING_SNAKE_CASE_    ) - 1
    while left < right:
        while (
            prime_numbers[right] * loga(prime_numbers[left]    )
            + prime_numbers[left] * loga(prime_numbers[right]    )
            > upper_bound
        ):
            right -= 1
        hybrid_integers_count += right - left
        left += 1

    return hybrid_integers_count


if __name__ == "__main__":
       print(f'''{solution() = }''')


