





from __future__ import annotations



def _a				(	lowerCamelCase:   list					,				lowerCamelCase:   int					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						list:







      '''simple docstring'''






      __A          =				[]
      __A   ,						__A          =				input_list[low:mid], input_list[mid : high + 1]
      while left and right:
            result.append((left if left[0] <= right[0] else right).pop(0 ) )
      __A          =				result + left + right
      return input_list



def _a				(	lowerCamelCase:   list )	->						list:







      '''simple docstring'''






      if len(lowerCamelCase ) <= 1:
            return input_list
      __A          =				list(lowerCamelCase )

      # iteration for two-way merging
      __A          =				2
      while p <= len(lowerCamelCase ):
            # getting low, high and middle value for merge-sort of single list
            for i in range(0					,				len(lowerCamelCase )					,				lowerCamelCase ):
                  __A          =				i
                  __A          =				i + p - 1
                  __A          =				(low + high + 1) // 2
                  __A          =				merge(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
            # final merge of last two parts
            if p * 2 >= len(lowerCamelCase ):
                  __A          =				i
                  __A          =				merge(lowerCamelCase					,				0					,				lowerCamelCase					,				len(lowerCamelCase ) - 1 )
                  break
            p *= 2

      return input_list


if __name__ == "__main__":
       snake_case__					:							Any													=     input('Enter numbers separated by a comma:\n').strip()
       if user_input == "":
              snake_case__					:							str													=     []
       else:
              snake_case__					:							str													=     [int(item.strip()) for item in user_input.split(',')]
       print(iter_merge_sort(unsorted))












from __future__ import annotations



def _a				(	lowerCamelCase:   list[float]					,				lowerCamelCase:   Tuple )	->						List[str]:







      '''simple docstring'''






      print(F"""Vertex\tShortest Distance from vertex {src}""" )
      for i, d in enumerate(lowerCamelCase ):
            print(F"""{i}\t\t{d}""" )



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   list[float]					,				lowerCamelCase:   int )	->						Union[str, Any]:







      '''simple docstring'''






      for j in range(lowerCamelCase ):
            __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])
            if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                  return True
      return False



def _a				(	lowerCamelCase:   list[dict[str, int]]					,				lowerCamelCase:   int					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						list[float]:







      '''simple docstring'''






      __A          =				[float('''inf''' )] * vertex_count
      __A          =				0.0

      for _ in range(vertex_count - 1 ):
            for j in range(lowerCamelCase ):
                  __A   ,						__A   ,						__A          =				(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])

                  if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
                        __A          =				distance[u] + w

      __A          =				check_negative_cycle(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
      if negative_cycle_exists:
            raise Exception('''Negative cycle found''' )

      return distance


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       snake_case__					:							Dict													=     int(input('Enter number of vertices: ').strip())
       snake_case__					:							Optional[int]													=     int(input('Enter number of edges: ').strip())

       snake_case__					:							list[dict[str, int]]													=     [{} for _ in range(E)]

       for i in range(E):
              print('Edge ', i + 1)
              snake_case__						,    snake_case__						,    snake_case__					:							Dict													=     (
                  int(x)
                  for x in input('Enter source, destination, weight: ').strip().split(' ')
              )
              snake_case__					:							List[Any]													=     {'src': src, 'dst': dest, 'weight': weight}

       snake_case__					:							Union[str, Any]													=     int(input('\nEnter shortest path source:').strip())
       snake_case__					:							List[Any]													=     bellman_ford(graph, V, E, source)
       print_distance(shortest_distance, 0)





