





"""simple docstring"""






import asyncio
import os
import re
import sys
import tempfile
import unittest
from contextlib import contextmanager
from copy import deepcopy
from distutils.util import strtobool
from enum import Enum
from importlib.util import find_spec
from pathlib import Path
from unittest.mock import patch

import pyarrow as pa
import pytest
import requests
from packaging import version

from datasets import config


if config.PY_VERSION < version.parse('''3.8'''):
		import importlib_metadata
else:
		import importlib.metadata as importlib_metadata

def     __A      (			a_						:List[str]   ,       a_						:int=False)		->		Optional[Any]:
				try:
								__a :						List[Any]			       =  os.environ[key]
				except KeyError:
								# KEY isn't set, default to `default`.
								__a :						str			       =  default
				else:
								# KEY is set, convert it to True or False.
								try:
												__a :						Any			       =  strtobool(a_)
								except ValueError:
												# More values are supported, but let's keep the message simple.
												raise ValueError(F"""If set, {key} must be yes or no.""")
				return _value


A 			=  parse_flag_from_env('''RUN_SLOW''', default=False)
A 			=  parse_flag_from_env('''RUN_REMOTE''', default=False)
A 			=  parse_flag_from_env('''RUN_LOCAL''', default=True)
A 			=  parse_flag_from_env('''RUN_PACKAGED''', default=True)

# Compression
A 			=  pytest.mark.skipif(not config.LZ4_AVAILABLE, reason='''test requires lz4''')
A 			=  pytest.mark.skipif(not config.PY7ZR_AVAILABLE, reason='''test requires py7zr''')
A 			=  pytest.mark.skipif(not config.ZSTANDARD_AVAILABLE, reason='''test requires zstandard''')

# Audio
A 			=  pytest.mark.skipif(
    # On Windows and OS X, soundfile installs sndfile
    find_spec('''soundfile''') is None or version.parse(importlib_metadata.version('''soundfile''')) < version.parse('''0.12.0'''),
    reason='''test requires sndfile>=0.12.1: \'pip install \"soundfile>=0.12.1\"\'; ''',
)

# Beam
A 			=  pytest.mark.skipif(
    not config.BEAM_AVAILABLE or config.DILL_VERSION >= version.parse('''0.3.2'''),
    reason='''test requires apache-beam and a compatible dill version''',
)

# Dill-cloudpickle compatibility
A 			=  pytest.mark.skipif(
    config.DILL_VERSION <= version.parse('''0.3.2'''),
    reason='''test requires dill>0.3.2 for cloudpickle compatibility''',
)

# Windows
A 			=  pytest.mark.skipif(
    sys.platform == '''win32''',
    reason='''test should not be run on Windows''',
)

def     __A      (			a_						:int)		->		Optional[int]:
				try:
								import faiss  # noqa
				except ImportError:
								__a :						Dict			       =  unittest.skip('''test requires faiss''')(a_)
				return test_case

def     __A      (			a_						:Tuple)		->		Union[str, Any]:
				try:
								import regex  # noqa
				except ImportError:
								__a :						str			       =  unittest.skip('''test requires regex''')(a_)
				return test_case

def     __A      (			a_						:List[str])		->		str:
				try:
								import elasticsearch  # noqa
				except ImportError:
								__a :						Tuple			       =  unittest.skip('''test requires elasticsearch''')(a_)
				return test_case

def     __A      (			a_						:Optional[int])		->		Optional[int]:
				try:
								import sqlalchemy  # noqa
				except ImportError:
								__a :						Any			       =  unittest.skip('''test requires sqlalchemy''')(a_)
				return test_case

def     __A      (			a_						:Dict)		->		Tuple:
				if not config.TORCH_AVAILABLE:
								__a :						str			       =  unittest.skip('''test requires PyTorch''')(a_)
				return test_case

def     __A      (			a_						:Tuple)		->		Union[str, Any]:
				if not config.TF_AVAILABLE:
								__a :						Union[str, Any]			       =  unittest.skip('''test requires TensorFlow''')(a_)
				return test_case

def     __A      (			a_						:Union[str, Any])		->		Optional[Any]:
				if not config.JAX_AVAILABLE:
								__a :						Optional[int]			       =  unittest.skip('''test requires JAX''')(a_)
				return test_case

def     __A      (			a_						:Optional[int])		->		Dict:
				if not config.PIL_AVAILABLE:
								__a :						Any			       =  unittest.skip('''test requires Pillow''')(a_)
				return test_case

def     __A      (			a_						:Any)		->		List[Any]:
				try:
								import transformers  # noqa F401
				except ImportError:
								return unittest.skip('''test requires transformers''')(a_)
				else:
								return test_case

def     __A      (			a_						:List[Any])		->		int:
				try:
								import tiktoken  # noqa F401
				except ImportError:
								return unittest.skip('''test requires tiktoken''')(a_)
				else:
								return test_case

def     __A      (			a_						:str)		->		Tuple:
				try:
								import spacy  # noqa F401
				except ImportError:
								return unittest.skip('''test requires spacy''')(a_)
				else:
								return test_case

def     __A      (			a_						:Union[str, Any])		->		Optional[int]:

				def _require_spacy_model(a_						:int):
								try:
												import spacy  # noqa F401

												spacy.load(a_)
								except ImportError:
												return unittest.skip('''test requires spacy''')(a_)
								except OSError:
												return unittest.skip('''test requires spacy model \'{}\''''.format(a_))(a_)
								else:
												return test_case

				return _require_spacy_model

def     __A      (			a_						:Tuple)		->		Optional[int]:
				try:
								import pyspark  # noqa F401
				except ImportError:
								return unittest.skip('''test requires pyspark''')(a_)
				else:
								return test_case

def     __A      (			a_						:str)		->		int:
				try:
								import joblibspark  # noqa F401
				except ImportError:
								return unittest.skip('''test requires joblibspark''')(a_)
				else:
								return test_case

def     __A      (			a_						:Tuple)		->		Any:
				if not _run_slow_tests or _run_slow_tests == 0:
								__a :						int			       =  unittest.skip('''test is slow''')(a_)
				return test_case

def     __A      (			a_						:Any)		->		List[Any]:
				if not _run_local_tests or _run_local_tests == 0:
								__a :						Optional[int]			       =  unittest.skip('''test is local''')(a_)
				return test_case

def     __A      (			a_						:Optional[int])		->		Any:
				if not _run_packaged_tests or _run_packaged_tests == 0:
								__a :						str			       =  unittest.skip('''test is packaged''')(a_)
				return test_case

def     __A      (			a_						:Tuple)		->		List[str]:
				if not _run_remote_tests or _run_remote_tests == 0:
								__a :						Optional[Any]			       =  unittest.skip('''test requires remote''')(a_)
				return test_case

def     __A      (			*a_						:List[str])		->		int:
				def decorate(cls						:Tuple):
								for name, fn in cls.__dict__.items():
												if callable(a_) and name.startswith('''test'''):
																for decorator in decorators:
																				__a :						int			       =  decorator(a_)
																setattr(cls   ,       a_   ,       a_)
								return cls

				return decorate




class 				__lowercase			(			_UpperCamelCase							):







					'''simple docstring'''




					pass






class 				__lowercase			(			_UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  0
					__lowerCAmelCase  =  1
					__lowerCAmelCase  =  2






@contextmanager
def     __A      (			a_						:List[str]=OfflineSimulationMode.CONNECTION_FAILS   ,       a_						:str=1e-16)		->		str:
				__a :						List[str]			       =  requests.Session().request

				def timeout_request(a_						:Optional[int]   ,       a_						:Optional[Any]   ,       a_						:int   ,       **a_						:List[Any]):
								# Change the url to an invalid url so that the connection hangs
								__a :						List[Any]			       =  '''https://10.255.255.1'''
								if kwargs.get('''timeout''') is None:
												raise RequestWouldHangIndefinitelyError(
												    F"""Tried a call to {url} in offline mode with no timeout set. Please set a timeout.""")
								__a :						str			       =  timeout
								try:
												return online_request(a_   ,       a_   ,       **a_)
								except Exception as e:
												# The following changes in the error are just here to make the offline timeout error prettier
												__a :						Dict			       =  url
												__a :						Optional[int]			       =  e.args[0]
												__a :						List[Any]			       =  (max_retry_error.args[0].replace('''10.255.255.1'''   ,       F"""OfflineMock[{url}]"""),)
												__a :						Optional[Any]			       =  (max_retry_error,)
												raise

				def raise_connection_error(a_						:List[str]   ,       a_						:int   ,       **a_						:int):
								raise requests.ConnectionError('''Offline mode is enabled.'''   ,       request=a_)

				if mode is OfflineSimulationMode.CONNECTION_FAILS:
								with patch('''requests.Session.send'''   ,       a_):
												yield
				elif mode is OfflineSimulationMode.CONNECTION_TIMES_OUT:
								# inspired from https://stackoverflow.com/a/904609
								with patch('''requests.Session.request'''   ,       a_):
												yield
				elif mode is OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1:
								with patch('''datasets.config.HF_DATASETS_OFFLINE'''   ,       a_):
												yield
				else:
								raise ValueError('''Please use a value from the OfflineSimulationMode enum.''')

@contextmanager
def     __A      (			*a_						:List[Any]   ,       **a_						:str)		->		int:
				__a :						int			       =  str(Path().resolve())
				with tempfile.TemporaryDirectory(*a_   ,       **a_) as tmp_dir:
								try:
												os.chdir(a_)
												yield
								finally:
												os.chdir(a_)

@contextmanager
def     __A      (			)		->		List[Any]:
				import gc

				gc.collect()
				__a :						List[Any]			       =  pa.total_allocated_bytes()
				yield
				assert pa.total_allocated_bytes() - previous_allocated_memory > 0, "Arrow memory didn't increase."

@contextmanager
def     __A      (			)		->		Union[str, Any]:
				import gc

				gc.collect()
				__a :						Dict			       =  pa.total_allocated_bytes()
				yield
				assert pa.total_allocated_bytes() - previous_allocated_memory <= 0, "Arrow memory wasn't expected to increase."

def     __A      (			a_						:str   ,       a_						:Tuple)		->		Optional[int]:
				return deepcopy(a_).integers(0   ,       1_00   ,       10).tolist() == deepcopy(a_).integers(0   ,       1_00   ,       10).tolist()

def     __A      (			a_						:int)		->		List[Any]:
				import decorator
				from requests.exceptions import HTTPError

				def _wrapper(a_						:str   ,       *a_						:Any   ,       **a_						:List[Any]):
								try:
												return func(*a_   ,       **a_)
								except HTTPError as err:
												if str(a_).startswith('''500''') or str(a_).startswith('''502'''):
																pytest.xfail(str(a_))
												raise err

				return decorator.decorator(_wrapper   ,       a_)




class 				__lowercase			:







					'''simple docstring'''




					def __init__(						self	,			_UpperCAmelCase	,			_UpperCAmelCase	,			_UpperCAmelCase     ):
									__a :						Union[str, Any]			       =  returncode
									__a :						Dict			       =  stdout
									__a :						List[Any]			       =  stderr






async def     __A      (			a_						:Tuple   ,       a_						:Tuple)		->		Tuple:
				while True:
								__a :						Union[str, Any]			       =  await stream.readline()
								if line:
												callback(a_)
								else:
												break

async def     __A      (			a_						:str   ,       a_						:Optional[int]=None   ,       a_						:int=None   ,       a_						:Any=None   ,       a_						:str=False   ,       a_						:Dict=False)		->		_RunOutput:
				if echo:
								print('''\nRunning: '''   ,       ''' '''.join(a_))

				__a :						Union[str, Any]			       =  await asyncio.create_subprocess_exec(
				    cmd[0]   ,       *cmd[1:]   ,       stdin=a_   ,       stdout=asyncio.subprocess.PIPE   ,       stderr=asyncio.subprocess.PIPE   ,       env=a_   ,       )

				# note: there is a warning for a possible deadlock when using `wait` with huge amounts of data in the pipe
				# https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.wait
				#
				# If it starts hanging, will need to switch to the following code. The problem is that no data
				# will be seen until it's done and if it hangs for example there will be no debug info.
				# out, err = await p.communicate()
				# return _RunOutput(p.returncode, out, err)

				__a :						Dict			       =  []
				__a :						str			       =  []

				def tee(a_						:List[Any]   ,       a_						:Dict   ,       a_						:Tuple   ,       a_						:List[Any]=""):
								__a :						str			       =  line.decode('''utf-8''').rstrip()
								sink.append(a_)
								if not quiet:
												print(a_   ,       a_   ,       file=a_)

    # XXX: the timeout doesn't seem to make any difference here
				await asyncio.wait(
				    [
				        _read_stream(p.stdout   ,       lambda a_: tee(a_   ,       a_   ,       sys.stdout   ,       label='''stdout:''')),
				        _read_stream(p.stderr   ,       lambda a_: tee(a_   ,       a_   ,       sys.stderr   ,       label='''stderr:''')),
				    ]   ,       timeout=a_   ,       )
				return _RunOutput(await p.wait()   ,       a_   ,       a_)

def     __A      (			a_						:Optional[Any]   ,       a_						:Dict=None   ,       a_						:Dict=None   ,       a_						:Optional[Any]=1_80   ,       a_						:List[Any]=False   ,       a_						:Optional[Any]=True)		->		_RunOutput:
				__a :						Optional[int]			       =  asyncio.get_event_loop()
				__a :						int			       =  loop.run_until_complete(
				    _stream_subprocess(a_   ,       env=a_   ,       stdin=a_   ,       timeout=a_   ,       quiet=a_   ,       echo=a_))

				__a :						Optional[Any]			       =  ''' '''.join(a_)
				if result.returncode > 0:
								__a :						Dict			       =  '''\n'''.join(result.stderr)
								raise RuntimeError(
								    F"""'{cmd_str}' failed with returncode {result.returncode}\n\n"""
								    F"""The combined stderr from workers follows:\n{stderr}""")

				# check that the subprocess actually did run and produced some output, should the test rely on
				# the remote side to do the testing
				if not result.stdout and not result.stderr:
								raise RuntimeError(F"""'{cmd_str}' produced no output.""")

				return result

def     __A      (			)		->		List[Any]:
				__a :						Dict			       =  os.environ.get('''PYTEST_XDIST_WORKER'''   ,       '''gw0''')
				__a :						List[str]			       =  re.sub(R'''^gw'''   ,       ''''''   ,       a_   ,       0   ,       re.M)
				return int(a_)






def     __A      (			)		->		Tuple:
				__a :						Tuple			       =  2_95_00
				__a :						Union[str, Any]			       =  pytest_xdist_worker_id()
				return port + uniq_delta






"""simple docstring"""






from math import isqrt, loga

def     __A      (			a_						:int)		->		list[int]:
				__a :						int			       =  [True] * max_number
				for i in range(2   ,       isqrt(max_number - 1) + 1):
								if is_prime[i]:
												for j in range(i**2   ,       a_   ,       a_):
																__a :						int			       =  False

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

def     __A      (			a_						:int = 80_08_00   ,       a_						:int = 80_08_00)		->		int:
				__a :						str			       =  degree * loga(a_)
				__a :						Tuple			       =  int(a_)
				__a :						int			       =  calculate_prime_numbers(a_)

				__a :						List[Any]			       =  0
				__a :						Optional[Any]			       =  0
				__a :						Dict			       =  len(a_) - 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() = }')