




"""simple docstring"""


from __future__ import annotations

from statistics import mean


def 					UpperCAmelCase__       (snake_case__							:					list[int]		,   snake_case__							:					list[int]		,   snake_case__							:					int    ):
  """simple docstring"""

  _snake_case							:		List[str]								=  [0] * no_of_processes
  _snake_case							:		Union[str, Any]								=  [0] * no_of_processes

  # Initialize remaining_time to waiting_time.

  for i in range(snake_case__    ):
    _snake_case							:		str								=  burst_time[i]
  _snake_case							:		list[int]								=  []

  _snake_case							:		Dict								=  0
  _snake_case							:		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:
    _snake_case							:		Any								=  []
    _snake_case							:		Tuple								=  -1

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

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

  return waiting_time


def 					UpperCAmelCase__       (snake_case__							:					list[int]		,   snake_case__							:					int		,   snake_case__							:					list[int]    ):
  """simple docstring"""

  _snake_case							:		Dict								=  [0] * no_of_processes
  for i in range(snake_case__    ):
    _snake_case							:		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}''')








class     __lowerCAmelCase :

			"""simple docstring"""







			def __init__(      self			,						lowerCamelCase__							)    ->      Any:



							'''simple docstring'''
							__lowerCamelCase		       =    n
							__lowerCamelCase		       =    [None] * self.n
							__lowerCamelCase		       =    0  # index of the first element
							__lowerCamelCase		       =    0
							__lowerCamelCase		       =    0


			def __len__(      self							)    ->      int:



							'''simple docstring'''
							return self.size


			def       lowercase_    (      self							)    ->      bool:



							'''simple docstring'''
							return self.size == 0


			def       lowercase_    (      self							)    ->      str:



							'''simple docstring'''
							return False if self.is_empty() else self.array[self.front]


			def       lowercase_    (      self			,						lowerCamelCase__							)    ->      Optional[Any]:



							'''simple docstring'''
							if self.size >= self.n:
											raise Exception('QUEUE IS FULL'							)

							__lowerCamelCase		       =    data
							__lowerCamelCase		       =    (self.rear + 1) % self.n
							self.size += 1
							return self






			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							if self.size == 0:
											raise Exception('UNDERFLOW'							)

							__lowerCamelCase		       =    self.array[self.front]
							__lowerCamelCase		       =    None
							__lowerCamelCase		       =    (self.front + 1) % self.n
							self.size -= 1
							return temp


