





class        snake_case_    (		__lowercase						):
  pass






class        snake_case_    (		__lowercase						):
  pass






class        snake_case_    :






  def __init__(							self			:					Optional[Any]      )->int:






   '''simple docstring'''

   __lowerCAmelCase					:	str      =       [
       [],
       [],
       [],
   ]






  def 				UpperCAmelCase__						(							self			:					Dict       ,  _snake_case			:					int       ,  _snake_case			:					int      )->None:






   '''simple docstring'''

   try:
    if len(self.queues[priority]      ) >= 100:
     raise OverflowError("""Maximum queue size is 100"""      )
    self.queues[priority].append(_snake_case      )
   except IndexError:
    raise ValueError("""Valid priorities are 0, 1, and 2"""      )






  def 				UpperCAmelCase__						(							self			:					Tuple      )->int:






   '''simple docstring'''

   for queue in self.queues:
    if queue:
     return queue.pop(0      )
   raise UnderFlowError("""All queues are empty"""      )






  def __str__(							self			:					List[str]      )->str:






   '''simple docstring'''

   return "\n".join(F'''Priority {i}: {q}''' for i, q in enumerate(self.queues      )      )






class        snake_case_    :






  def __init__(							self			:					str      )->Tuple:






   '''simple docstring'''

   __lowerCAmelCase					:	Any      =       []






  def 				UpperCAmelCase__						(							self			:					Tuple       ,  _snake_case			:					int      )->None:






   '''simple docstring'''

   if len(self.queue      ) == 100:
    raise OverFlowError("""Maximum queue size is 100"""      )
   self.queue.append(_snake_case      )






  def 				UpperCAmelCase__						(							self			:					str      )->int:






   '''simple docstring'''

   if not self.queue:
    raise UnderFlowError("""The queue is empty"""      )
   else:
    __lowerCAmelCase					:	Tuple      =       min(self.queue      )
    self.queue.remove(_snake_case      )
    return data






  def __str__(							self			:					List[str]      )->str:






   '''simple docstring'''

   return str(self.queue      )






def 	_SCREAMING_SNAKE_CASE		(      )      ->   Optional[Any]:
 __lowerCAmelCase					:	Dict      =       FixedPriorityQueue()
 fpq.enqueue(0   ,   10   )
 fpq.enqueue(1   ,   70   )
 fpq.enqueue(0   ,   100   )
 fpq.enqueue(2   ,   1   )
 fpq.enqueue(2   ,   5   )
 fpq.enqueue(1   ,   7   )
 fpq.enqueue(2   ,   4   )
 fpq.enqueue(1   ,   64   )
 fpq.enqueue(0   ,   128   )
 print(SCREAMING_SNAKE_CASE   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(SCREAMING_SNAKE_CASE   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )
 print(fpq.dequeue()   )






def 	_SCREAMING_SNAKE_CASE		(      )      ->   Optional[Any]:
 __lowerCAmelCase					:	List[str]      =       ElementPriorityQueue()
 epq.enqueue(10   )
 epq.enqueue(70   )
 epq.enqueue(100   )
 epq.enqueue(1   )
 epq.enqueue(5   )
 epq.enqueue(7   )
 epq.enqueue(4   )
 epq.enqueue(64   )
 epq.enqueue(128   )
 print(SCREAMING_SNAKE_CASE   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(SCREAMING_SNAKE_CASE   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )
 print(epq.dequeue()   )


if __name__ == "__main__":
      fixed_priority_queue()
      element_priority_queue()






_UpperCAmelCase             =							{0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

_UpperCAmelCase             =							{0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:dict[int, list[int]]   ,   SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list[bool]   )      ->   list[int]:
 __lowerCAmelCase					:	str      =       True
 __lowerCAmelCase					:	str      =       []

 for neighbour in graph[vert]:
  if not visited[neighbour]:
   order += topology_sort(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 order.append(SCREAMING_SNAKE_CASE   )

 return order






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:dict[int, list[int]]   ,   SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:list[bool]   )      ->   list[int]:
 __lowerCAmelCase					:	Optional[Any]      =       True
 __lowerCAmelCase					:	Union[str, Any]      =       [vert]

 for neighbour in reversed_graph[vert]:
  if not visited[neighbour]:
   component += find_components(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 return component







def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:dict[int, list[int]]   )      ->   list[list[int]]:
 __lowerCAmelCase					:	Optional[Any]      =       len(SCREAMING_SNAKE_CASE   ) * [False]
 __lowerCAmelCase					:	dict[int, list[int]]      =       {vert: [] for vert in range(len(SCREAMING_SNAKE_CASE   )   )}

 for vert, neighbours in graph.items():
  for neighbour in neighbours:
   reversed_graph[neighbour].append(SCREAMING_SNAKE_CASE   )

 __lowerCAmelCase					:	Tuple      =       []
 for i, was_visited in enumerate(SCREAMING_SNAKE_CASE   ):
  if not was_visited:
   order += topology_sort(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 __lowerCAmelCase					:	Optional[Any]      =       []
 __lowerCAmelCase					:	Any      =       len(SCREAMING_SNAKE_CASE   ) * [False]

 for i in range(len(SCREAMING_SNAKE_CASE   )   ):
  __lowerCAmelCase					:	Optional[int]      =       order[len(SCREAMING_SNAKE_CASE   ) - i - 1]
  if not visited[vert]:
   __lowerCAmelCase					:	Any      =       find_components(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
   components_list.append(SCREAMING_SNAKE_CASE   )

 return components_list