
'''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 snake_case_     (					lowercase__   ,       lowercase__   ,       lowercase__   ,       lowercase__		):
  UpperCAmelCase__      :					Union[str, Any]				       =							multiprocessing.Manager()
  UpperCAmelCase__      :					Any				       =							manager.list()

  UpperCAmelCase__      :					str				       =							multiprocessing.Process(target=lowercase__   ,       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 snake_case_     (					lowercase__   ,       lowercase__   ,       lowercase__		):
  with create_tempdir():
    # These system calls are needed when cleaning up tempdir.
    import os
    import shutil

    UpperCAmelCase__      :					List[str]				       =							shutil.rmtree
    UpperCAmelCase__      :					str				       =							os.rmdir
    UpperCAmelCase__      :					Optional[int]				       =							os.chdir

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

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

    # Needed for cleaning up.
    UpperCAmelCase__      :					Optional[int]				       =							rmtree
    UpperCAmelCase__      :					List[str]				       =							rmdir
    UpperCAmelCase__      :					Union[str, Any]				       =							chdir







@contextlib.contextmanager
def snake_case_     (					lowercase__		):
  def signal_handler(lowercase__   ,       lowercase__		):
    raise TimeoutException("Timed out!"		)

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







@contextlib.contextmanager
def snake_case_     (					):
  UpperCAmelCase__      :					Optional[Any]				       =							WriteOnlyStringIO()
  with contextlib.redirect_stdout(lowercase__		):
    with contextlib.redirect_stderr(lowercase__		):
      with redirect_stdin(lowercase__		):
        yield







@contextlib.contextmanager
def snake_case_     (					):
  with tempfile.TemporaryDirectory() as dirname:
    with chdir(lowercase__		):
      yield dirname






class 							UpperCAmelCase_							(    SCREAMING_SNAKE_CASE_				):

 '''simple docstring'''
 pass






class 							UpperCAmelCase_							(    io.StringIO				):

 '''simple docstring'''







 def 							UpperCamelCase  (					self		:  List[str]			,				*snake_case__		:  Tuple			,				**snake_case__		:  Dict ):



   '''simple docstring'''




   raise OSError







 def 							UpperCamelCase  (					self		:  Any			,				*snake_case__		:  Union[str, Any]			,				**snake_case__		:  List[str] ):



   '''simple docstring'''




   raise OSError







 def 							UpperCamelCase  (					self		:  Optional[Any]			,				*snake_case__		:  int			,				**snake_case__		:  Any ):



   '''simple docstring'''




   raise OSError







 def 							UpperCamelCase  (					self		:  Tuple			,				*snake_case__		:  Union[str, Any]			,				**snake_case__		:  Tuple ):



   '''simple docstring'''




   return False






class 							UpperCAmelCase_							(    contextlib._RedirectStream				):  # type: ignore

 '''simple docstring'''
 lowercase_					:    List[Any]				=							"stdin"







@contextlib.contextmanager
def snake_case_     (					lowercase__		):
  if root == ".":
    yield
    return
  UpperCAmelCase__      :					Optional[Any]				       =							os.getcwd()
  os.chdir(lowercase__		)
  try:
    yield
  except BaseException as exc:
    raise exc
  finally:
    os.chdir(lowercase__		)







def snake_case_     (					lowercase__=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

  UpperCAmelCase__      :					Optional[Any]				       =							None
  UpperCAmelCase__      :					Tuple				       =							None

  import os

  UpperCAmelCase__      :					Tuple				       =							"1"

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

  import shutil

  UpperCAmelCase__      :					Optional[int]				       =							None
  UpperCAmelCase__      :					Union[str, Any]				       =							None
  UpperCAmelCase__      :					Union[str, Any]				       =							None

  import subprocess

  UpperCAmelCase__      :					Tuple				       =							None  # type: ignore

  UpperCAmelCase__      :					Tuple				       =							None

  import sys

  UpperCAmelCase__      :					List[Any]				       =							None
  UpperCAmelCase__      :					Optional[int]				       =							None
  UpperCAmelCase__      :					Any				       =							None
  UpperCAmelCase__      :					str				       =							None
  UpperCAmelCase__      :					Union[str, Any]				       =							None




from __future__ import annotations

import math

import numpy as np
from numpy.linalg import norm


def 	lowerCamelCase					(	UpperCamelCase     :				np.ndarray			,       UpperCamelCase     :				np.ndarray							)   ->    float:
		return math.sqrt(sum(pow(a - b			,       2							) for a, b in zip(UpperCamelCase			,       UpperCamelCase							)							)							)


def 	lowerCamelCase					(	UpperCamelCase     :				np.ndarray			,       UpperCamelCase     :				np.ndarray							)   ->    list[list[list[float] | float]]:

		if dataset.ndim != value_array.ndim:
				_lowerCamelCase				   =  (
				    'Wrong input data\'s dimensions... '
				    F"""dataset : {dataset.ndim}, value_array : {value_array.ndim}"""
				)
				raise ValueError(UpperCamelCase							)

		try:
				if dataset.shape[1] != value_array.shape[1]:
						_lowerCamelCase				   =  (
						    'Wrong input data\'s shape... '
						    F"""dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}"""
						)
						raise ValueError(UpperCamelCase							)
		except IndexError:
				if dataset.ndim != value_array.ndim:
						raise TypeError('Wrong shape'							)

		if dataset.dtype != value_array.dtype:
				_lowerCamelCase				   =  (
				    'Input data have different datatype... '
				    F"""dataset : {dataset.dtype}, value_array : {value_array.dtype}"""
				)
				raise TypeError(UpperCamelCase							)

		_lowerCamelCase				   =  []

		for value in value_array:
				_lowerCamelCase				   =  euclidean(UpperCamelCase			,       dataset[0]							)
				_lowerCamelCase				   =  dataset[0].tolist()

				for dataset_value in dataset[1:]:
						_lowerCamelCase				   =  euclidean(UpperCamelCase			,       UpperCamelCase							)

						if dist > temp_dist:
								_lowerCamelCase				   =  temp_dist
								_lowerCamelCase				   =  dataset_value.tolist()

				answer.append([vector, dist]							)

		return answer


def 	lowerCamelCase					(	UpperCamelCase     :				np.ndarray			,       UpperCamelCase     :				np.ndarray							)   ->    float:
		return np.dot(UpperCamelCase			,       UpperCamelCase							) / (norm(UpperCamelCase							) * norm(UpperCamelCase							))


if __name__ == "__main__":
				import doctest

				doctest.testmod()