




from __future__ import annotations

from random import random





class 					__lowerCamelCase			:




    """simple docstring"""

    def __init__(			self	:	Dict  ,      SCREAMING_SNAKE_CASE__	:	int | None = None  ) ->			Optional[int]:
         lowerCAmelCase__            =					value
         lowerCAmelCase__            =					random()
         lowerCAmelCase__            =					None
         lowerCAmelCase__            =					None


    def __repr__(			self	:	List[Any]  ) ->			str:
         from pprint import pformat

         if self.left is None and self.right is None:
              return f'\'{self.value}: {self.prior:.5}\''
         else:
              return pformat(
                  {f'{self.value}: {self.prior:.5}': (self.left, self.right)}  ,      indent=1  )


    def __str__(			self	:	Dict  ) ->			str:
         lowerCAmelCase__            =					str(self.value  ) + " "
         lowerCAmelCase__            =					str(self.left or ""  )
         lowerCAmelCase__            =					str(self.right or ""  )
         return value + left + right






def 				_A  (		lowerCAmelCase_	:   Node | None  ,							lowerCAmelCase_	:   int     ):
     """simple docstring"""

     if root is None:  # None tree is split into 2 Nones
          return None, None
     elif root.value is None:
          return None, None
     else:
          if value < root.value:
               lowerCAmelCase__      ,						lowerCAmelCase__            =					split(root.left  ,							lowerCAmelCase_     )
               return left, root
          else:
               lowerCAmelCase__      ,						lowerCAmelCase__            =					split(root.right  ,							lowerCAmelCase_     )
               return root, right



def 				_A  (		lowerCAmelCase_	:   Node | None  ,							lowerCAmelCase_	:   Node | None     ):
     """simple docstring"""

     if (not left) or (not right):  # If one node is None, return the other
          return left or right
     elif left.prior < right.prior:
          lowerCAmelCase__            =					merge(left.right  ,							lowerCAmelCase_     )
          return left
     else:
          lowerCAmelCase__            =					merge(lowerCAmelCase_  ,							right.left     )
          return right



def 				_A  (		lowerCAmelCase_	:   Node | None  ,							lowerCAmelCase_	:   int     ):
     """simple docstring"""

     lowerCAmelCase__            =					Node(lowerCAmelCase_     )
     lowerCAmelCase__      ,						lowerCAmelCase__            =					split(lowerCAmelCase_  ,							lowerCAmelCase_     )
     return merge(merge(lowerCAmelCase_  ,							lowerCAmelCase_     )  ,							lowerCAmelCase_     )



def 				_A  (		lowerCAmelCase_	:   Node | None  ,							lowerCAmelCase_	:   int     ):
     """simple docstring"""

     lowerCAmelCase__      ,						lowerCAmelCase__            =					split(lowerCAmelCase_  ,							value - 1     )
     lowerCAmelCase__      ,						lowerCAmelCase__            =					split(lowerCAmelCase_  ,							lowerCAmelCase_     )
     return merge(lowerCAmelCase_  ,							lowerCAmelCase_     )



def 				_A  (		lowerCAmelCase_	:   Node | None     ):
     """simple docstring"""

     if not root:  # None
          return
     else:
          inorder(root.left     )
          print(root.value  ,							end=","     )
          inorder(root.right     )



def 				_A  (		lowerCAmelCase_	:   Node | None  ,							lowerCAmelCase_	:   str     ):
     """simple docstring"""

     for arg in args.split():
          if arg[0] == "+":
               lowerCAmelCase__            =					insert(lowerCAmelCase_  ,							int(arg[1:]     )     )

          elif arg[0] == "-":
               lowerCAmelCase__            =					erase(lowerCAmelCase_  ,							int(arg[1:]     )     )

          else:
               print("Unknown command"     )

     return root



def 				_A  (		):
     """simple docstring"""

     lowerCAmelCase__            =					None
     print(
         "enter numbers to create a tree, + value to add value into treap, "
         "- value to erase all nodes with value. 'q' to quit. "     )

     lowerCAmelCase__            =					input()
     while args != "q":
          lowerCAmelCase__            =					interact_treap(lowerCAmelCase_  ,							lowerCAmelCase_     )
          print(lowerCAmelCase_     )
          lowerCAmelCase__            =					input()

     print("good by!"     )


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     main()


'''simple docstring'''

from __future__ import annotations

import pandas as pd


def        UpperCAmelCase_ (  lowerCamelCase_      ,			lowerCamelCase_      ,			lowerCamelCase_			):







 """simple docstring"""


 lowerCAmelCase__     :   Tuple     		=	[0] * no_of_processes
 lowerCAmelCase__     :   Any     		=	[0] * no_of_processes
 # Copy the burst time into remaining_time[]
 for i in range(lowerCamelCase_			):
  lowerCAmelCase__     :   Dict     		=	burst_time[i]

 lowerCAmelCase__     :   str     		=	0
 lowerCAmelCase__     :   Optional[Any]     		=	0
 lowerCAmelCase__     :   Optional[Any]     		=	9_9_9_9_9_9_9_9_9
 lowerCAmelCase__     :   int     		=	0
 lowerCAmelCase__     :   str     		=	False

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

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

  lowerCAmelCase__     :   Optional[Any]     		=	remaining_time[short]
  if minm == 0:
   lowerCAmelCase__     :   Optional[int]     		=	9_9_9_9_9_9_9_9_9

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

   # Find finish time of current process
   lowerCAmelCase__     :   Tuple     		=	increment_time + 1

   # Calculate waiting time
   lowerCAmelCase__     :   Dict     		=	finish_time - arrival_time[short]
   lowerCAmelCase__     :   Optional[Any]     		=	finar - burst_time[short]

   if waiting_time[short] < 0:
    lowerCAmelCase__     :   Tuple     		=	0

        # Increment time
  increment_time += 1
 return waiting_time


def        UpperCAmelCase_ (  lowerCamelCase_      ,			lowerCamelCase_      ,			lowerCamelCase_			):







 """simple docstring"""


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


def        UpperCAmelCase_ (  lowerCamelCase_      ,			lowerCamelCase_      ,			lowerCamelCase_			):







 """simple docstring"""


 lowerCAmelCase__     :   Union[str, Any]     		=	0
 lowerCAmelCase__     :   Optional[int]     		=	0
 for i in range(lowerCamelCase_			):
  lowerCAmelCase__     :   Tuple     		=	total_waiting_time + waiting_time[i]
  lowerCAmelCase__     :   str     		=	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""")
     snake_case									=    int(input())
     snake_case									=    [0] * no_of_processes
     snake_case									=    [0] * no_of_processes
     snake_case									=    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))
          snake_case					,					snake_case									=    map(int, input().split())

     snake_case									=    calculate_waitingtime(arrival_time, burst_time, no_of_processes)

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

     calculate_average_times(waiting_time, turn_around_time, no_of_processes)

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





