





"""simple docstring"""





from __future__ import annotations

from statistics import mean
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->list[int]:





  """simple docstring"""


  lowerCAmelCase__			:Optional[int]											=							[0] * no_of_processes
  lowerCAmelCase__			:str											=							[0] * no_of_processes

  # Initialize remaining_time to waiting_time.

  for i in range(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:Any											=							burst_time[i]
  lowerCAmelCase__			:list[int]											=							[]

  lowerCAmelCase__			:Optional[Any]											=							0
  lowerCAmelCase__			:Optional[int]											=							0

  # When processes are not completed,
  # A process whose arrival time has passed \
  # and has remaining execution time is put into the ready_process.
  # The shortest process in the ready_process, target_process is executed.

  while completed != no_of_processes:
    lowerCAmelCase__			:List[Any]											=							[]
    lowerCAmelCase__			:int											=							-1

    for i in range(_SCREAMING_SNAKE_CASE			):
      if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
        ready_process.append(_SCREAMING_SNAKE_CASE			)

    if len(_SCREAMING_SNAKE_CASE			) > 0:
      lowerCAmelCase__			:int											=							ready_process[0]
      for i in ready_process:
        if remaining_time[i] < remaining_time[target_process]:
          lowerCAmelCase__			:Dict											=							i
      total_time += burst_time[target_process]
      completed += 1
      lowerCAmelCase__			:Tuple											=							0
      lowerCAmelCase__			:List[str]											=							(
          total_time - arrival_time[target_process] - burst_time[target_process]
      )
    else:
      total_time += 1

  return waiting_time
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->list[int]:





  """simple docstring"""


  lowerCAmelCase__			:Optional[Any]											=							[0] * no_of_processes
  for i in range(_SCREAMING_SNAKE_CASE			):
    lowerCAmelCase__			:str											=							burst_time[i] + waiting_time[i]
  return turn_around_time


if __name__ == "__main__":
  print("""[TEST CASE 01]""")

  __A											=		4
  __A											=		[2, 5, 3, 7]
  __A											=		[0, 0, 0, 0]
  __A											=		calculate_waitingtime(arrival_time, burst_time, no_of_processes)
  __A											=		calculate_turnaroundtime(
      burst_time, no_of_processes, waiting_time
  )

  # Printing the Result
  print("""PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time""")
  for i, process_id in enumerate(list(range(1, 5))):
    print(
        F'''{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t'''
        F'''{waiting_time[i]}\t\t\t\t{turn_around_time[i]}'''
    )
  print(F'''\nAverage waiting time = {mean(waiting_time):.5f}''')
  print(F'''Average turnaround time = {mean(turn_around_time):.5f}''')







"""simple docstring"""





from collections.abc import Iterator, MutableMapping
from dataclasses import dataclass
from typing import Generic, TypeVar

__A											=		TypeVar("""KEY""")
__A											=		TypeVar("""VAL""")






@dataclass(frozen=a  ,   slots=a       )
class 					_lowerCAmelCase   (     Generic[KEY, VAL]       ):
       """simple docstring"""




       __magic_name__     :KEY
       __magic_name__     :VAL






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




       def __init__(    self      ):



         '''simple docstring'''

         super().__init__(__UpperCAmelCase    , __UpperCAmelCase      )






       def __bool__(    self      ):



         '''simple docstring'''

         return False






__A											=		_DeletedItem()






class 					_lowerCAmelCase   (     MutableMapping[KEY, VAL]       ):
       """simple docstring"""




       def __init__(    self    , __UpperCAmelCase = 8    , __UpperCAmelCase = 0.75      ):



         '''simple docstring'''

         lowerCAmelCase__			:List[str]											=							initial_block_size
         lowerCAmelCase__			:list[_Item | None]											=							[None] * initial_block_size
         assert 0.0 < capacity_factor < 1.0
         lowerCAmelCase__			:Tuple											=							capacity_factor
         lowerCAmelCase__			:str											=							0






       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         return hash(__UpperCAmelCase      ) % len(self._buckets      )






       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         return (ind + 1) % len(self._buckets      )






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



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							self._buckets[ind]
         if not stored:
           lowerCAmelCase__			:Dict											=							_Item(__UpperCAmelCase    , __UpperCAmelCase      )
           self._len += 1
           return True
         elif stored.key == key:
           lowerCAmelCase__			:Optional[Any]											=							_Item(__UpperCAmelCase    , __UpperCAmelCase      )
           return True
         else:
           return False






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:int											=							len(self._buckets      ) * self._capacity_factor
         return len(self      ) >= int(__UpperCAmelCase      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         if len(self._buckets      ) <= self._initial_block_size:
           return False
         lowerCAmelCase__			:Optional[Any]											=							len(self._buckets      ) * self._capacity_factor / 2
         return len(self      ) < limit






       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[int]											=							self._buckets
         lowerCAmelCase__			:Tuple											=							[None] * new_size
         lowerCAmelCase__			:List[Any]											=							0
         for item in old_buckets:
           if item:
             self._add_item(item.key    , item.val      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         self._resize(len(self._buckets      ) * 2      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         self._resize(len(self._buckets      ) // 2      )






       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[Any]											=							self._get_bucket_index(__UpperCAmelCase      )
         for _ in range(len(self._buckets      )      ):
           yield ind
           lowerCAmelCase__			:Tuple											=							self._get_next_ind(__UpperCAmelCase      )






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         for ind in self._iterate_buckets(__UpperCAmelCase      ):
           if self._try_set(__UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):
             break






       def __setitem__(    self    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         if self._is_full():
           self._size_up()

         self._add_item(__UpperCAmelCase    , __UpperCAmelCase      )






       def __delitem__(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         for ind in self._iterate_buckets(__UpperCAmelCase      ):
           lowerCAmelCase__			:int											=							self._buckets[ind]
           if item is None:
             raise KeyError(__UpperCAmelCase      )
           if item is _deleted:
             continue
           if item.key == key:
             lowerCAmelCase__			:List[str]											=							_deleted
             self._len -= 1
             break
         if self._is_sparse():
           self._size_down()






       def __getitem__(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         for ind in self._iterate_buckets(__UpperCAmelCase      ):
           lowerCAmelCase__			:str											=							self._buckets[ind]
           if item is None:
             break
           if item is _deleted:
             continue
           if item.key == key:
             return item.val
         raise KeyError(__UpperCAmelCase      )






       def __len__(    self      ):



         '''simple docstring'''

         return self._len






       def __iter__(    self      ):



         '''simple docstring'''

         yield from (item.key for item in self._buckets if item)






       def __repr__(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							' ,'.join(
             F"{item.key}: {item.val}" for item in self._buckets if item      )
         return F"HashMap({val_string})"
