
from __future__ import annotations

import time

import numpy as np

lowercase  : Optional[Any]						   =							[8, 5, 9, 7]
lowercase  : Union[str, Any]						   =							[
    [2, 0, 1, 1],
    [0, 1, 2, 1],
    [4, 0, 0, 3],
    [0, 2, 1, 0],
    [1, 0, 3, 0],
]
lowercase  : Optional[Any]						   =							[
    [3, 2, 1, 4],
    [0, 2, 5, 2],
    [5, 1, 0, 5],
    [1, 5, 3, 0],
    [3, 0, 3, 3],
]

class __snake_case		:
    def __init__(  self		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					Any	     =				claim_vector
           lowercase							:					Union[str, Any]	     =				allocated_resources_table
           lowercase							:					Dict	     =				maximum_claim_table
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return [
               sum(p_item[i] for p_item in self.__allocated_resources_table				)
               for i in range(len(self.__allocated_resources_table[0]				)				)
           ]
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return np.array(self.__claim_vector				) - np.array(
               self.__processes_resource_summation()				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return [
               list(np.array(self.__maximum_claim_table[i]				) - np.array(snake_case				)				)
               for i, allocated_resource in enumerate(self.__allocated_resources_table				)
           ]
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           return {self.__need().index(snake_case				): i for i in self.__need()}
    def 				_SCREAMING_SNAKE_CASE	(  self		,**snake_case				):



           '''simple docstring'''







           lowercase							:					Any	     =				self.__need()
           lowercase							:					List[str]	     =				self.__allocated_resources_table
           lowercase							:					int	     =				self.__available_resources()
           lowercase							:					int	     =				self.__need_index_manager()
           for kw, val in kwargs.items():
                  if kw and val is True:
                         self.__pretty_data()
           print("""_""" * 50 + """\n"""				)
           while need_list:
                  lowercase							:					List[str]	     =				False
                  for each_need in need_list:
                         lowercase							:					Optional[Any]	     =				True
                         for index, need in enumerate(snake_case				):
                                if need > available_resources[index]:
                                       lowercase							:					Optional[Any]	     =				False
                                       break
                         if execution:
                                lowercase							:					Optional[Any]	     =				True
                                # get the original index of the process from ind_ctrl db
                                for original_need_index, need_clone in need_index_manager.items():
                                       if each_need == need_clone:
                                              lowercase							:					Union[str, Any]	     =				original_need_index
                                print(f"Process {process_number + 1} is executing."				)
                                # remove the process run from stack
                                need_list.remove(snake_case				)
                                # update available/freed resources stack
                                lowercase							:					Dict	     =				np.array(snake_case				) + np.array(
                                    alloc_resources_table[process_number]				)
                                print(
                                    """Updated available resource stack for processes: """
                                    + """ """.join([str(snake_case				) for x in available_resources]				)				)
                                break
                  if safe:
                         print("""The process is in a safe state.\n"""				)
                  else:
                         print("""System in unsafe state. Aborting...\n"""				)
                         break
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           print(""" """ * 9 + """Allocated Resource Table"""				)
           for item in self.__allocated_resources_table:
                  print(
                      f"P{self.__allocated_resources_table.index(snake_case				) + 1}"
                      + """ """.join(f"{it:>8}" for it in item				)
                      + """\n"""				)
           print(""" """ * 9 + """System Resource Table"""				)
           for item in self.__maximum_claim_table:
                  print(
                      f"P{self.__maximum_claim_table.index(snake_case				) + 1}"
                      + """ """.join(f"{it:>8}" for it in item				)
                      + """\n"""				)
           print(
               """Current Usage by Active Processes: """
               + """ """.join(str(snake_case				) for x in self.__claim_vector				)				)
           print(
               """Initial Available Resources:       """
               + """ """.join(str(snake_case				) for x in self.__available_resources()				)				)
           time.sleep(1				)


if __name__ == "__main__":
  import doctest

  doctest.testmod()


from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat







def 						_snake_case(  )			->   tuple[list[int], int]:
       lowercase							:					List[Any]	     =				[randint(-1_000 ,     1_000    ) for i in range(10    )]
       lowercase							:					Tuple	     =				randint(-5_000 ,     5_000    )
       return (arr, r)


lowercase  : List[Any]						   =							make_dataset()







def 						_snake_case(  SCREAMING_SNAKE_CASE__ ,     SCREAMING_SNAKE_CASE__    )			->   tuple[int, ...]:
       for triplet in permutations(SCREAMING_SNAKE_CASE__ ,     3    ):
              if sum(SCREAMING_SNAKE_CASE__    ) == target:
                     return tuple(sorted(SCREAMING_SNAKE_CASE__    )    )
       return (0, 0, 0)







def 						_snake_case(  SCREAMING_SNAKE_CASE__ ,     SCREAMING_SNAKE_CASE__    )			->   tuple[int, int, int]:
       arr.sort()
       lowercase							:					Optional[int]	     =				len(SCREAMING_SNAKE_CASE__    )
       for i in range(n - 1    ):
              lowercase     ,      lowercase							:					Optional[Any]	     =				i + 1, n - 1
              while left < right:
                     if arr[i] + arr[left] + arr[right] == target:
                            return (arr[i], arr[left], arr[right])
                     elif arr[i] + arr[left] + arr[right] < target:
                            left += 1
                     elif arr[i] + arr[left] + arr[right] > target:
                            right -= 1
       return (0, 0, 0)







def 						_snake_case(  )			->   tuple[float, float]:
       lowercase							:					Dict	     =				"""
from __main__ import dataset, triplet_sum1, triplet_sum2
"""
       lowercase							:					Tuple	     =				"""
triplet_sum1(*dataset)
"""
       lowercase							:					int	     =				"""
triplet_sum2(*dataset)
"""
       lowercase							:					str	     =				repeat(setup=SCREAMING_SNAKE_CASE__ ,     stmt=SCREAMING_SNAKE_CASE__ ,     repeat=5 ,     number=10_000    )
       lowercase							:					Dict	     =				repeat(setup=SCREAMING_SNAKE_CASE__ ,     stmt=SCREAMING_SNAKE_CASE__ ,     repeat=5 ,     number=10_000    )
       return (min(SCREAMING_SNAKE_CASE__    ), min(SCREAMING_SNAKE_CASE__    ))


if __name__ == "__main__":
  from doctest import testmod

  testmod()
  lowercase  : Union[str, Any]						   =							solution_times()
  print(F'''The time for naive implementation is {times[0]}.''')
  print(F'''The time for optimized implementation is {times[1]}.''')
