from __future__ import annotations

from typing import Generic, TypeVar

__magic_name__								=TypeVar('''T''')



class     _A   (    Generic[T]							):






  def __init__(self   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       UpperCamelCase__										=      data
       UpperCamelCase__										=      self
       UpperCamelCase__										=      0



class     _A   (    Generic[T]							):






  def __init__(self	)		->      None:





       '''simple docstring'''





       UpperCamelCase__										=      {}






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       UpperCamelCase__										=      DisjointSetTreeNode(SCREAMING_SNAKE_CASE_	)






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_	)		->      DisjointSetTreeNode[T]:





       '''simple docstring'''





       UpperCamelCase__										=      self.map[data]
       if elem_ref != elem_ref.parent:
            UpperCamelCase__										=      self.find_set(elem_ref.parent.data	)
       return elem_ref.parent






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       if nodea.rank > nodea.rank:
            UpperCamelCase__										=      nodea
       else:
            UpperCamelCase__										=      nodea
            if nodea.rank == nodea.rank:
                 nodea.rank += 1






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       self.link(self.find_set(SCREAMING_SNAKE_CASE_	)   ,				self.find_set(SCREAMING_SNAKE_CASE_	)	)



class     _A   (    Generic[T]							):






  def __init__(self	)		->      None:





       '''simple docstring'''





       UpperCamelCase__										=      {}






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       if node not in self.connections:
            UpperCamelCase__										=      {}






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)		->      None:





       '''simple docstring'''





       self.add_node(SCREAMING_SNAKE_CASE_	)
       self.add_node(SCREAMING_SNAKE_CASE_	)
       UpperCamelCase__										=      weight
       UpperCamelCase__										=      weight






  def 		_a					(self	)		->      GraphUndirectedWeighted[T]:





       '''simple docstring'''





       UpperCamelCase__										=      []
       UpperCamelCase__										=      set()
       for start in self.connections:
            for end in self.connections[start]:
                 if (start, end) not in seen:
                      seen.add((end, start)	)
                      edges.append((start, end, self.connections[start][end])	)
       edges.sort(key=lambda SCREAMING_SNAKE_CASE_	: x[2]	)

       # creating the disjoint set
       UpperCamelCase__										=      DisjointSetTree[T]()
       for node in self.connections:
            disjoint_set.make_set(SCREAMING_SNAKE_CASE_	)

       # MST generation
       UpperCamelCase__										=      0
       UpperCamelCase__										=      0
       UpperCamelCase__										=      GraphUndirectedWeighted[T]()
       while num_edges < len(self.connections	) - 1:
            UpperCamelCase__						,       UpperCamelCase__						,       UpperCamelCase__										=      edges[index]
            index += 1
            UpperCamelCase__										=      disjoint_set.find_set(SCREAMING_SNAKE_CASE_	)
            UpperCamelCase__										=      disjoint_set.find_set(SCREAMING_SNAKE_CASE_	)
            if parent_u != parent_v:
                 num_edges += 1
                 graph.add_edge(SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)
                 disjoint_set.union(SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)
       return graph




from __future__ import annotations

import pandas as pd







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

     UpperCamelCase__										=      0
     UpperCamelCase__										=      0
     UpperCamelCase__										=      999999999
     UpperCamelCase__										=      0
     UpperCamelCase__										=      False

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

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

          UpperCamelCase__										=      remaining_time[short]
          if minm == 0:
               UpperCamelCase__										=      999999999

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

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

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

               if waiting_time[short] < 0:
                    UpperCamelCase__										=      0

        # Increment time
          increment_time += 1
     return waiting_time







def  __UpperCamelCase    (						A ,							A ,							A							):
     UpperCamelCase__										=      [0] * no_of_processes
     for i in range(A							):
          UpperCamelCase__										=      burst_time[i] + waiting_time[i]
     return turn_around_time







def  __UpperCamelCase    (						A ,							A ,							A							):
     UpperCamelCase__										=      0
     UpperCamelCase__										=      0
     for i in range(A							):
          UpperCamelCase__										=      total_waiting_time + waiting_time[i]
          UpperCamelCase__										=      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''')
     __magic_name__								=int(input())
     __magic_name__								=[0] * no_of_processes
     __magic_name__								=[0] * no_of_processes
     __magic_name__								=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))
          __magic_name__		,  __magic_name__								=map(int, input().split())

     __magic_name__								=calculate_waitingtime(arrival_time, burst_time, no_of_processes)

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

     calculate_average_times(waiting_time, turn_around_time, no_of_processes)

     __magic_name__								=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)



