


# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile
def 			_a (      SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		lowercase__            =      multiprocessing.Manager()
		lowercase__            =      manager.list()

		lowercase__            =      multiprocessing.Process(target=SCREAMING_SNAKE_CASE						,				args=(check_program, result, timeout)     )
		p.start()
		p.join(timeout=timeout + 1     )
		if p.is_alive():
				p.kill()

		if not result:
				result.append('''timed out'''     )

		return {
		    "task_id": task_id,
		    "passed": result[0] == "passed",
		    "result": result[0],
		    "completion_id": completion_id,
		}
def 			_a (      SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		with create_tempdir():
				# These system calls are needed when cleaning up tempdir.
				import os
				import shutil

				lowercase__            =      shutil.rmtree
				lowercase__            =      os.rmdir
				lowercase__            =      os.chdir

				# Disable functionalities that can make destructive changes to the test.
				reliability_guard()

				# Run program.
				try:
						lowercase__            =      {}
						with swallow_io():
								with time_limit(SCREAMING_SNAKE_CASE     ):
										exec(SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE     )
						result.append('''passed'''     )
				except TimeoutException:
						result.append('''timed out'''     )
				except BaseException as e:
						result.append(f'failed: {e}'     )

				# Needed for cleaning up.
				lowercase__            =      rmtree
				lowercase__            =      rmdir
				lowercase__            =      chdir
@contextlib.contextmanager
def 			_a (      SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		def signal_handler(SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE     ):
				raise TimeoutException('''Timed out!'''     )

		signal.setitimer(signal.ITIMER_REAL						,				SCREAMING_SNAKE_CASE     )
		signal.signal(signal.SIGALRM						,				SCREAMING_SNAKE_CASE     )
		try:
				yield
		finally:
				signal.setitimer(signal.ITIMER_REAL						,				0     )
@contextlib.contextmanager
def 			_a (      ):


		"""simple docstring"""




		lowercase__            =      WriteOnlyStringIO()
		with contextlib.redirect_stdout(SCREAMING_SNAKE_CASE     ):
				with contextlib.redirect_stderr(SCREAMING_SNAKE_CASE     ):
						with redirect_stdin(SCREAMING_SNAKE_CASE     ):
								yield
@contextlib.contextmanager
def 			_a (      ):


		"""simple docstring"""




		with tempfile.TemporaryDirectory() as dirname:
				with chdir(SCREAMING_SNAKE_CASE     ):
						yield dirname


class        _a							(			UpperCamelCase__			):
							pass


class        _a							(			io.StringIO			):

							def       lowerCamelCase_ (							self:	Optional[Any]    ,						*UpperCamelCase_:	Dict    ,						**UpperCamelCase_:	Union[str, Any]							)			->   List[Any]:





									"""simple docstring"""







									raise OSError

							def       lowerCamelCase_ (							self:	int    ,						*UpperCamelCase_:	Optional[Any]    ,						**UpperCamelCase_:	Optional[Any]							)			->   Tuple:





									"""simple docstring"""







									raise OSError

							def       lowerCamelCase_ (							self:	Union[str, Any]    ,						*UpperCamelCase_:	str    ,						**UpperCamelCase_:	str							)			->   Tuple:





									"""simple docstring"""







									raise OSError


							def       lowerCamelCase_ (							self:	str    ,						*UpperCamelCase_:	int    ,						**UpperCamelCase_:	Dict							)			->   Tuple:





									"""simple docstring"""







									return False


class        _a							(			contextlib._RedirectStream			):  # type: ignore
							_lowercase	:			Union[str, Any]        = '''stdin'''
@contextlib.contextmanager
def 			_a (      SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		if root == ".":
				yield
				return
		lowercase__            =      os.getcwd()
		os.chdir(SCREAMING_SNAKE_CASE     )
		try:
				yield
		except BaseException as exc:
				raise exc
		finally:
				os.chdir(SCREAMING_SNAKE_CASE     )
def 			_a (      SCREAMING_SNAKE_CASE=None     ):


		"""simple docstring"""




		if maximum_memory_bytes is not None:
				import resource

				resource.setrlimit(resource.RLIMIT_AS						,				(maximum_memory_bytes, maximum_memory_bytes)     )
				resource.setrlimit(resource.RLIMIT_DATA						,				(maximum_memory_bytes, maximum_memory_bytes)     )
				if not platform.uname().system == "Darwin":
						resource.setrlimit(resource.RLIMIT_STACK						,				(maximum_memory_bytes, maximum_memory_bytes)     )

		faulthandler.disable()

		import builtins

		lowercase__            =      None
		lowercase__            =      None

		import os

		lowercase__            =      '''1'''

		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None

		import shutil

		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None

		import subprocess

		lowercase__            =      None  # type: ignore

		lowercase__            =      None

		import sys

		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None
		lowercase__            =      None






def 			_a (      SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		if exponent == 1:
				return base
		if exponent % 2 == 0:
				lowercase__            =      _modexpt(SCREAMING_SNAKE_CASE						,				exponent // 2						,				SCREAMING_SNAKE_CASE     ) % modulo_value
				return (x * x) % modulo_value
		else:
				return (base * _modexpt(SCREAMING_SNAKE_CASE						,				exponent - 1						,				SCREAMING_SNAKE_CASE     )) % modulo_value
def 			_a (      SCREAMING_SNAKE_CASE = 17_77						,				SCREAMING_SNAKE_CASE = 18_55						,				SCREAMING_SNAKE_CASE = 8     ):


		"""simple docstring"""




		lowercase__            =      base
		for _ in range(1						,				SCREAMING_SNAKE_CASE     ):
				lowercase__            =      _modexpt(SCREAMING_SNAKE_CASE						,				SCREAMING_SNAKE_CASE						,				10**digits     )

		return result


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


