"""simple docstring"""




import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =multiprocessing.Manager()
							A__	     =manager.list()

							A__	     =multiprocessing.Process(target=UpperCamelCase__       ,    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   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





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

														A__	     =shutil.rmtree
														A__	     =os.rmdir
														A__	     =os.chdir

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

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

														# Needed for cleaning up.
														A__	     =rmtree
														A__	     =rmdir
														A__	     =chdir






@contextlib.contextmanager
def   UpperCAmelCase					(	UpperCamelCase__				):






							"""simple docstring"""





							def signal_handler(UpperCamelCase__       ,    UpperCamelCase__				):
														raise TimeoutException('Timed out!'				)

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






@contextlib.contextmanager
def   UpperCAmelCase					(	):






							"""simple docstring"""





							A__	     =WriteOnlyStringIO()
							with contextlib.redirect_stdout(UpperCamelCase__				):
														with contextlib.redirect_stderr(UpperCamelCase__				):
																					with redirect_stdin(UpperCamelCase__				):
																												yield






@contextlib.contextmanager
def   UpperCAmelCase					(	):






							"""simple docstring"""





							with tempfile.TemporaryDirectory() as dirname:
														with chdir(UpperCamelCase__				):
																					yield dirname
class     UpperCamelCase__(			SCREAMING_SNAKE_CASE__ ):
						pass






class     UpperCamelCase__(			io.StringIO ):





						def 				snake_case__	(       self		,*__UpperCAmelCase		,**__UpperCAmelCase     )					->				List[Any]:
													raise OSError





						def 				snake_case__	(       self		,*__UpperCAmelCase		,**__UpperCAmelCase     )					->				str:
													raise OSError





						def 				snake_case__	(       self		,*__UpperCAmelCase		,**__UpperCAmelCase     )					->				List[Any]:
													raise OSError





						def 				snake_case__	(       self		,*__UpperCAmelCase		,**__UpperCAmelCase     )					->				List[Any]:
													return False






class     UpperCamelCase__(			contextlib._RedirectStream ):  # type: ignore
						lowerCAmelCase__  :						Tuple													=		'stdin'






@contextlib.contextmanager
def   UpperCAmelCase					(	UpperCamelCase__				):






							"""simple docstring"""





							if root == ".":
														yield
														return
							A__	     =os.getcwd()
							os.chdir(UpperCamelCase__				)
							try:
														yield
							except BaseException as exc:
														raise exc
							finally:
														os.chdir(UpperCamelCase__				)






def   UpperCAmelCase					(	UpperCamelCase__=None				):






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

							A__	     =None
							A__	     =None

							import os

							A__	     ="1"

							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None

							import shutil

							A__	     =None
							A__	     =None
							A__	     =None

							import subprocess

							A__	     =None  # type: ignore

							A__	     =None

							import sys

							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None
							A__	     =None






"""simple docstring"""




from __future__ import annotations

import pandas as pd






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =							[0] * no_of_processes
							A__	     =							[0] * no_of_processes
							# Copy the burst time into remaining_time[]
							for i in range(UpperCamelCase__				):
														A__	     =							burst_time[i]

							A__	     =							0
							A__	     =							0
							A__	     =							999_999_999
							A__	     =							0
							A__	     =							False

							# Process until all processes are completed
							while complete != no_of_processes:
														for j in range(UpperCamelCase__				):
																					if arrival_time[j] <= increment_time and remaining_time[j] > 0:
																												if remaining_time[j] < minm:
																																			A__	     =							remaining_time[j]
																																			A__	     =							j
																																			A__	     =							True

														if not check:
																					increment_time += 1
																					continue
														remaining_time[short] -= 1

														A__	     =							remaining_time[short]
														if minm == 0:
																					A__	     =							999_999_999

														if remaining_time[short] == 0:
																					complete += 1
																					A__	     =							False

																					# Find finish time of current process
																					A__	     =							increment_time + 1

																					# Calculate waiting time
																					A__	     =							finish_time - arrival_time[short]
																					A__	     =							finar - burst_time[short]

																					if waiting_time[short] < 0:
																												A__	     =							0

        # Increment time
														increment_time += 1
							return waiting_time






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =							[0] * no_of_processes
							for i in range(UpperCamelCase__				):
														A__	     =							burst_time[i] + waiting_time[i]
							return turn_around_time






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =							0
							A__	     =							0
							for i in range(UpperCamelCase__				):
														A__	     =							total_waiting_time + waiting_time[i]
														A__	     =							total_turn_around_time + turn_around_time[i]
							print(F'''Average waiting time = {total_waiting_time / no_of_processes:.5f}'''				)
							print('Average turn around time ='       ,    total_turn_around_time / no_of_processes				)


if __name__ == "__main__":
				print("Enter how many process you want to analyze")
				__lowerCamelCase											=  int(input())
				__lowerCamelCase											=  [0] * no_of_processes
				__lowerCamelCase											=  [0] * no_of_processes
				__lowerCamelCase											=  list(range(1, no_of_processes + 1))

				for i in range(no_of_processes):
								print("Enter the arrival time and burst time for process:--" + str(i + 1))
								__lowerCamelCase				,   __lowerCamelCase											=  map(int, input().split())

				__lowerCamelCase											=  calculate_waitingtime(arrival_time, burst_time, no_of_processes)

				__lowerCamelCase											=  burst_time
				__lowerCamelCase											=  no_of_processes
				__lowerCamelCase											=  waiting_time
				__lowerCamelCase											=  calculate_turnaroundtime(bt, n, wt)

				calculate_average_times(waiting_time, turn_around_time, no_of_processes)

				__lowerCamelCase											=  pd.DataFrame(
				    list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)),
				    columns=[
				        "Process",
				        "BurstTime",
				        "ArrivalTime",
				        "WaitingTime",
				        "TurnAroundTime",
				    ],
				)

				# Printing the dataFrame
				pd.set_option("display.max_rows", fcfs.shape[0] + 1)
				print(fcfs)





