





"""simple docstring"""





# 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     )   ->str:





  """simple docstring"""


  lowerCAmelCase__     :Optional[Any]											=				multiprocessing.Manager()
  lowerCAmelCase__     :Optional[int]											=				manager.list()

  lowerCAmelCase__     :str											=				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     )   ->Any:





  """simple docstring"""


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

    lowerCAmelCase__     :Any											=				shutil.rmtree
    lowerCAmelCase__     :Dict											=				os.rmdir
    lowerCAmelCase__     :int											=				os.chdir

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

    # Run program.
    try:
      lowerCAmelCase__     :Optional[Any]											=				{}
      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.
    lowerCAmelCase__     :Optional[Any]											=				rmtree
    lowerCAmelCase__     :Union[str, Any]											=				rmdir
    lowerCAmelCase__     :Optional[int]											=				chdir
@contextlib.contextmanager
def 					__A  (_SCREAMING_SNAKE_CASE     )   ->List[str]:





  """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  ()   ->int:





  """simple docstring"""


  lowerCAmelCase__     :Optional[Any]											=				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  ()   ->List[Any]:





  """simple docstring"""


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






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       pass






class    _lowerCAmelCase  (	io.StringIO			):
       """simple docstring"""




       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         raise OSError






       def 	snake_case		(       self       ,					*__UpperCAmelCase       ,					**__UpperCAmelCase ):



         '''simple docstring'''

         return False






class    _lowerCAmelCase  (	contextlib._RedirectStream			):  # type: ignore
       """simple docstring"""




       __magic_name__	:List[Any]						    =   """stdin"""






@contextlib.contextmanager
def 					__A  (_SCREAMING_SNAKE_CASE     )   ->List[Any]:





  """simple docstring"""


  if root == ".":
    yield
    return
  lowerCAmelCase__     :Dict											=				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     )   ->int:





  """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

  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :List[Any]											=				None

  import os

  lowerCAmelCase__     :Optional[Any]											=				'1'

  lowerCAmelCase__     :Optional[Any]											=				None
  lowerCAmelCase__     :List[Any]											=				None
  lowerCAmelCase__     :Optional[Any]											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :int											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :List[Any]											=				None
  lowerCAmelCase__     :Any											=				None
  lowerCAmelCase__     :Any											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :List[str]											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :int											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Optional[int]											=				None
  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Optional[int]											=				None

  import shutil

  lowerCAmelCase__     :Dict											=				None
  lowerCAmelCase__     :str											=				None
  lowerCAmelCase__     :str											=				None

  import subprocess

  lowerCAmelCase__     :List[str]											=				None  # type: ignore

  lowerCAmelCase__     :int											=				None

  import sys

  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Tuple											=				None
  lowerCAmelCase__     :Union[str, Any]											=				None
  lowerCAmelCase__     :List[str]											=				None
  lowerCAmelCase__     :List[str]											=				None

def 	lowerCamelCase					(	UpperCamelCase     :				int			,       UpperCamelCase     :				int							)   ->    str:
		if number < 0 or shift_amount < 0:
				raise ValueError('both inputs must be positive integers'							)

		_lowerCamelCase				   =  str(bin(UpperCamelCase							)							)
		binary_number += "0" * shift_amount
		return binary_number


def 	lowerCamelCase					(	UpperCamelCase     :				int			,       UpperCamelCase     :				int							)   ->    str:
		if number < 0 or shift_amount < 0:
				raise ValueError('both inputs must be positive integers'							)

		_lowerCamelCase				   =  str(bin(UpperCamelCase							)							)[2:]
		if shift_amount >= len(UpperCamelCase							):
				return "0b0"
		_lowerCamelCase				   =  binary_number[: len(UpperCamelCase							) - shift_amount]
		return "0b" + shifted_binary_number


def 	lowerCamelCase					(	UpperCamelCase     :				int			,       UpperCamelCase     :				int							)   ->    str:
		if number >= 0:  # Get binary representation of positive number
				_lowerCamelCase				   =  '0' + str(bin(UpperCamelCase							)							).strip('-'							)[2:]
		else:  # Get binary (2's complement) representation of negative number
				_lowerCamelCase				   =  len(bin(UpperCamelCase							)[3:]							)  # Find 2's complement of number
				_lowerCamelCase				   =  bin(abs(UpperCamelCase							) - (1 << binary_number_length)							)[3:]
				_lowerCamelCase				   =  (
				    '1' + '0' * (binary_number_length - len(UpperCamelCase							)) + binary_number
				)

		if shift_amount >= len(UpperCamelCase							):
				return "0b" + binary_number[0] * len(UpperCamelCase							)
		return (
		    "0b"
		    + binary_number[0] * shift_amount
		    + binary_number[: len(UpperCamelCase							) - shift_amount]
		)


if __name__ == "__main__":
				import doctest

				doctest.testmod()