"""simple docstring"""




class 		__A							:






     def __init__(	self						):
       _lowerCAmelCase		: int						    =  0
       _lowerCAmelCase		: int						    =  0
       _lowerCAmelCase		: Tuple						    =  {}






     def 					__A						(	self       ,  a__						):
       if vertex not in self.adjacency:
         _lowerCAmelCase		: Any						    =  {}
         self.num_vertices += 1






     def 					__A						(	self       ,  a__       ,  a__       ,  a__						):
       self.add_vertex(a__						)
       self.add_vertex(a__						)

       if head == tail:
         return

       _lowerCAmelCase		: Union[str, Any]						    =  weight
       _lowerCAmelCase		: int						    =  weight






     def 					__A						(	self						):
       _lowerCAmelCase		: Dict						    =  self.get_edges()
       for edge in edges:
         _lowerCAmelCase    ,			_lowerCAmelCase    ,			_lowerCAmelCase		: str						    =  edge
         edges.remove((tail, head, weight)						)
       for i in range(len(a__						)						):
         _lowerCAmelCase		: List[Any]						    =  list(edges[i]						)

       edges.sort(key=lambda a__						: e[2]						)
       for i in range(len(a__						) - 1						):
         if edges[i][2] >= edges[i + 1][2]:
           _lowerCAmelCase		: Tuple						    =  edges[i][2] + 1
       for edge in edges:
         _lowerCAmelCase    ,			_lowerCAmelCase    ,			_lowerCAmelCase		: Tuple						    =  edge
         _lowerCAmelCase		: Dict						    =  weight
         _lowerCAmelCase		: Optional[int]						    =  weight






     def __str__(	self						):
       _lowerCAmelCase		: Any						    =  """"""
       for tail in self.adjacency:
         for head in self.adjacency[tail]:
           _lowerCAmelCase		: Optional[int]						    =  self.adjacency[head][tail]
           string += F"{head} -> {tail} == {weight}\n"
       return string.rstrip("""\n"""						)






     def 					__A						(	self						):
       _lowerCAmelCase		: List[str]						    =  []
       for tail in self.adjacency:
         for head in self.adjacency[tail]:
           output.append((tail, head, self.adjacency[head][tail])						)
       return output






     def 					__A						(	self						):
       return self.adjacency.keys()






     @staticmethod
     def 					__A						(	a__=None       ,  a__=None						):
       _lowerCAmelCase		: Optional[int]						    =  Graph()
       if vertices is None:
         _lowerCAmelCase		: int						    =  []
       if edges is None:
         _lowerCAmelCase		: Optional[Any]						    =  []
       for vertex in vertices:
         g.add_vertex(a__						)
       for edge in edges:
         g.add_edge(*a__						)
       return g
     class 		__A							:






          def __init__(	self						):
            _lowerCAmelCase		: str						    =  {}
            _lowerCAmelCase		: int						    =  {}






          def __len__(	self						):
            return len(self.parent						)






          def 					__A						(	self       ,  a__						):
            if item in self.parent:
              return self.find(a__						)

            _lowerCAmelCase		: List[str]						    =  item
            _lowerCAmelCase		: Dict						    =  0
            return item






          def 					__A						(	self       ,  a__						):
            if item not in self.parent:
              return self.make_set(a__						)
            if item != self.parent[item]:
              _lowerCAmelCase		: List[str]						    =  self.find(self.parent[item]						)
            return self.parent[item]






          def 					__A						(	self       ,  a__       ,  a__						):
            _lowerCAmelCase		: Optional[int]						    =  self.find(a__						)
            _lowerCAmelCase		: Any						    =  self.find(a__						)

            if roota == roota:
              return roota

            if self.rank[roota] > self.rank[roota]:
              _lowerCAmelCase		: str						    =  roota
              return roota

            if self.rank[roota] < self.rank[roota]:
              _lowerCAmelCase		: str						    =  roota
              return roota

            if self.rank[roota] == self.rank[roota]:
              self.rank[roota] += 1
              _lowerCAmelCase		: str						    =  roota
              return roota
            return None







     @staticmethod
     def 					__A						(	a__						):
       _lowerCAmelCase		: str						    =  graph.num_vertices

       _lowerCAmelCase		: Tuple						    =  Graph.UnionFind()
       _lowerCAmelCase		: Union[str, Any]						    =  []
       while num_components > 1:
         _lowerCAmelCase		: List[Any]						    =  {}
         for vertex in graph.get_vertices():
           _lowerCAmelCase		: List[Any]						    =  -1

         _lowerCAmelCase		: Tuple						    =  graph.get_edges()
         for edge in edges:
           _lowerCAmelCase    ,			_lowerCAmelCase    ,			_lowerCAmelCase		: Union[str, Any]						    =  edge
           edges.remove((tail, head, weight)						)
         for edge in edges:
           _lowerCAmelCase    ,			_lowerCAmelCase    ,			_lowerCAmelCase		: Any						    =  edge
           _lowerCAmelCase		: List[str]						    =  union_find.find(a__						)
           _lowerCAmelCase		: List[str]						    =  union_find.find(a__						)
           if seta != seta:
             if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
               _lowerCAmelCase		: int						    =  [head, tail, weight]

             if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
               _lowerCAmelCase		: Dict						    =  [head, tail, weight]
         for vertex in cheap_edge:
           if cheap_edge[vertex] != -1:
             _lowerCAmelCase    ,			_lowerCAmelCase    ,			_lowerCAmelCase		: List[str]						    =  cheap_edge[vertex]
             if union_find.find(a__						) != union_find.find(a__						):
               union_find.union(a__       ,  a__						)
               mst_edges.append(cheap_edge[vertex]						)
               _lowerCAmelCase		: Optional[int]						    =  num_components - 1
       _lowerCAmelCase		: Optional[int]						    =  Graph.build(edges=a__						)
       return mst





"""simple docstring"""




class 		__A							(				SCREAMING_SNAKE_CASE_	):
     pass







class 		__A							(				SCREAMING_SNAKE_CASE_	):
     pass







class 		__A							:






     def __init__(	self						):
       _lowerCAmelCase		: Union[str, Any]						    =  [
           [],
           [],
           [],
       ]






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






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






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







class 		__A							:






     def __init__(	self						):
       _lowerCAmelCase		: int						    =  []






     def 					__A						(	self       ,  a__						):
       if len(self.queue						) == 100:
         raise OverFlowError("""Maximum queue size is 100"""						)
       self.queue.append(a__						)






     def 					__A						(	self						):
       if not self.queue:
         raise UnderFlowError("""The queue is empty"""						)
       else:
         _lowerCAmelCase		: int						    =  min(self.queue						)
         self.queue.remove(a__						)
         return data






     def __str__(	self						):
       return str(self.queue						)







def 							SCREAMING_SNAKE_CASE  (    ) ->   str:
  _lowerCAmelCase		: Union[str, Any]						    =  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(_lowerCamelCase			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(_lowerCamelCase			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)
  print(fpq.dequeue()			)





def 							SCREAMING_SNAKE_CASE  (    ) ->   Union[str, Any]:
  _lowerCAmelCase		: Tuple						    =  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(_lowerCamelCase			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(_lowerCamelCase			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)
  print(epq.dequeue()			)


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




