


'''simple docstring'''





import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Tuple       ,  SCREAMING_SNAKE_CASE_   :		Union[str, Any]       ,  SCREAMING_SNAKE_CASE_   :		Optional[int]       ,  SCREAMING_SNAKE_CASE_   :		str	):





			"""simple docstring"""




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

			UpperCamelCase         =					multiprocessing.Process(target=lowerCamelCase__       ,  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 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Union[str, Any]       ,  SCREAMING_SNAKE_CASE_   :		Tuple       ,  SCREAMING_SNAKE_CASE_   :		List[str]	):





			"""simple docstring"""




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

						UpperCamelCase         =					shutil.rmtree
						UpperCamelCase         =					os.rmdir
						UpperCamelCase         =					os.chdir

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

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

						# Needed for cleaning up.
						UpperCamelCase         =					rmtree
						UpperCamelCase         =					rmdir
						UpperCamelCase         =					chdir






@contextlib.contextmanager
def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			def signal_handler(SCREAMING_SNAKE_CASE_   :		List[Any]       ,  SCREAMING_SNAKE_CASE_   :		str	):
						raise TimeoutException("""Timed out!"""	)

			signal.setitimer(signal.ITIMER_REAL       ,  lowerCamelCase__	)
			signal.signal(signal.SIGALRM       ,  lowerCamelCase__	)
			try:
						yield
			finally:
						signal.setitimer(signal.ITIMER_REAL       ,  0	)






@contextlib.contextmanager
def 							_lowercase    (		):





			"""simple docstring"""




			UpperCamelCase         =					WriteOnlyStringIO()
			with contextlib.redirect_stdout(lowerCamelCase__	):
						with contextlib.redirect_stderr(lowerCamelCase__	):
									with redirect_stdin(lowerCamelCase__	):
												yield






@contextlib.contextmanager
def 							_lowercase    (		):





			"""simple docstring"""




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




class    UpperCAmelCase					(       __snake_case    ):
			pass




class    UpperCAmelCase					(       io.StringIO    ):




			def   lowerCamelCase_					(						self							:		Dict       ,       *__magic_name__							:		Union[str, Any]       ,       **__magic_name__							:		str						):







						"""simple docstring"""







						raise OSError




			def   lowerCamelCase_					(						self							:		Optional[Any]       ,       *__magic_name__							:		int       ,       **__magic_name__							:		Any						):







						"""simple docstring"""







						raise OSError




			def   lowerCamelCase_					(						self							:		int       ,       *__magic_name__							:		int       ,       **__magic_name__							:		Union[str, Any]						):







						"""simple docstring"""







						raise OSError





			def   lowerCamelCase_					(						self							:		int       ,       *__magic_name__							:		Union[str, Any]       ,       **__magic_name__							:		Optional[Any]						):







						"""simple docstring"""







						return False




class    UpperCAmelCase					(       contextlib._RedirectStream    ):  # type: ignore
			lowercase						= "stdin"






@contextlib.contextmanager
def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			if root == ".":
						yield
						return
			UpperCamelCase         =					os.getcwd()
			os.chdir(lowerCamelCase__	)
			try:
						yield
			except BaseException as exc:
						raise exc
			finally:
						os.chdir(lowerCamelCase__	)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int=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

			UpperCamelCase         =					None
			UpperCamelCase         =					None

			import os

			UpperCamelCase         =					"1"

			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None

			import shutil

			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None

			import subprocess

			UpperCamelCase         =					None  # type: ignore

			UpperCamelCase         =					None

			import sys

			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None
			UpperCamelCase         =					None








def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		str	):





			"""simple docstring"""




			return [
			    txt[:a] + txt[a].upper() + txt[a + 1 :]
			    for a in range(len(SCREAMING_SNAKE_CASE_	)	)
			    if txt[a].isalpha()
			]


if __name__ == "__main__":
			__import__("doctest").testmod()




