


# 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 							__lowercase     (				__lowerCAmelCase							:       Dict      ,					__lowerCAmelCase							:       str      ,					__lowerCAmelCase							:       Optional[Any]      ,					__lowerCAmelCase							:       Dict     ):
							a__    =  multiprocessing.Manager()
							a__    =  manager.list()

							a__    =  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     (				__lowerCAmelCase							:       Any      ,					__lowerCAmelCase							:       Dict      ,					__lowerCAmelCase							:       List[Any]     ):
							with create_tempdir():
														# These system calls are needed when cleaning up tempdir.
														import os
														import shutil

														a__    =  shutil.rmtree
														a__    =  os.rmdir
														a__    =  os.chdir

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

														# Run program.
														try:
																					a__    =  {}
																					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.
														a__    =  rmtree
														a__    =  rmdir
														a__    =  chdir






@contextlib.contextmanager
def 							__lowercase     (				__lowerCAmelCase							:       Any     ):
							def signal_handler(__lowerCAmelCase							:       Tuple      ,					__lowerCAmelCase							:       Dict     ):
														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     (				):
							a__    =  WriteOnlyStringIO()
							with contextlib.redirect_stdout(__lowerCAmelCase     ):
														with contextlib.redirect_stderr(__lowerCAmelCase     ):
																					with redirect_stdin(__lowerCAmelCase     ):
																												yield






@contextlib.contextmanager
def 							__lowercase     (				):
							with tempfile.TemporaryDirectory() as dirname:
														with chdir(__lowerCAmelCase     ):
																					yield dirname







class  snake_case_     (lowerCamelCase_   ):
					pass







class  snake_case_     (io.StringIO   ):
					def 				lowerCamelCase__(   self     :Any    ,*__snake_case     :Tuple    ,**__snake_case     :List[str]   )      ->					Union[str, Any]:
												raise OSError
					def 				lowerCamelCase__(   self     :Optional[int]    ,*__snake_case     :Any    ,**__snake_case     :List[Any]   )      ->					Any:
												raise OSError
					def 				lowerCamelCase__(   self     :Tuple    ,*__snake_case     :Optional[Any]    ,**__snake_case     :List[Any]   )      ->					Union[str, Any]:
												raise OSError



					def 				lowerCamelCase__(   self     :Any    ,*__snake_case     :Union[str, Any]    ,**__snake_case     :Union[str, Any]   )      ->					str:
												return False







class  snake_case_     (contextlib._RedirectStream   ):  # type: ignore
					UpperCAmelCase__      :					str					   =    '''stdin'''






@contextlib.contextmanager
def 							__lowercase     (				__lowerCAmelCase							:       Union[str, Any]     ):
							if root == ".":
														yield
														return
							a__    =  os.getcwd()
							os.chdir(__lowerCAmelCase     )
							try:
														yield
							except BaseException as exc:
														raise exc
							finally:
														os.chdir(__lowerCAmelCase     )






def 							__lowercase     (				__lowerCAmelCase							:       str=None     ):

							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

							a__    =  None
							a__    =  None

							import os

							a__    =  '1'

							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None

							import shutil

							a__    =  None
							a__    =  None
							a__    =  None

							import subprocess

							a__    =  None  # type: ignore

							a__    =  None

							import sys

							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None
							a__    =  None








from decimal import Decimal, getcontext
from math import ceil, factorial






def 							__lowercase     (				__lowerCAmelCase							:       int     ):

							if not isinstance(__lowerCAmelCase      ,					__lowerCAmelCase     ):
														raise TypeError('Undefined for non-integers'     )
							elif precision < 1:
														raise ValueError('Undefined for non-natural numbers'     )

							a__    =  precision
							a__    =  ceil(precision / 1_4     )
							a__    =  4_2_6_8_8_0 * Decimal(1_0_0_0_5     ).sqrt()
							a__    =  1
							a__    =  1_3_5_9_1_4_0_9
							a__    =  Decimal(__lowerCAmelCase     )
							for k in range(1      ,					__lowerCAmelCase     ):
														a__    =  factorial(6 * k     ) // (factorial(3 * k     ) * factorial(__lowerCAmelCase     ) ** 3)
														linear_term += 5_4_5_1_4_0_1_3_4
														exponential_term *= -2_6_2_5_3_7_4_1_2_6_4_0_7_6_8_0_0_0
														partial_sum += Decimal(multinomial_term * linear_term     ) / exponential_term
							return str(constant_term / partial_sum     )[:-1]


if __name__ == "__main__":
						snake_case							: Tuple      =   50
						print(f"""The first {n} digits of pi is: {pi(n)}""")




