
'''simple docstring'''





#
# Sort large text files in a minimum amount of memory
#
import argparse
import os


class 	UpperCamelCase__					:
 UpperCAmelCase__      :      Any  			=   'block_{0}.dat'






 def __init__(     self					:List[str]		,			_A					:Union[str, Any]     )			->     Optional[Any]:







       '''simple docstring'''



       __A    		=     filename
       __A    		=     []






 def 		lowercase_  (     self					:Tuple		,			_A					:List[Any]		,			_A					:str     )			->     Union[str, Any]:







       '''simple docstring'''



       __A    		=     self.BLOCK_FILENAME_FORMAT.format(_A     )
       with open(_A		,			'w'     ) as file:
             file.write(_A     )
       self.block_filenames.append(_A     )






 def 		lowercase_  (     self					:Dict     )			->     str:







       '''simple docstring'''



       return self.block_filenames






 def 		lowercase_  (     self					:int		,			_A					:Any		,			_A					:List[Any]=None     )			->     Dict:







       '''simple docstring'''



       __A    		=     0
       with open(self.filename     ) as file:
             while True:
                   __A    		=     file.readlines(_A     )

                   if lines == []:
                         break

                   if sort_key is None:
                         lines.sort()
                   else:
                         lines.sort(key=_A     )

                   self.write_block(''.join(_A     )		,			_A     )
                   i += 1






 def 		lowercase_  (     self					:List[str]     )			->     List[Any]:







       '''simple docstring'''



       map(os.remove		,			self.block_filenames     )


class 	UpperCamelCase__					:






 def 		lowercase_  (     self					:List[str]		,			_A					:Tuple     )			->     List[Any]:







       '''simple docstring'''



       __A    		=     -1
       __A    		=     None

       for i in range(len(_A     )     ):
             if min_str is None or choices[i] < min_str:
                   __A    		=     i

       return min_index


class 	UpperCamelCase__					:






 def __init__(     self					:Union[str, Any]		,			_A					:List[str]     )			->     str:







       '''simple docstring'''



       __A    		=     files
       __A    		=     set()
       __A    		=     len(_A     )
       __A    		=     {i: None for i in range(self.num_buffers     )}






 def 		lowercase_  (     self					:int     )			->     Any:







       '''simple docstring'''



       return {
           i: self.buffers[i] for i in range(self.num_buffers     ) if i not in self.empty
       }






 def 		lowercase_  (     self					:List[str]     )			->     Any:







       '''simple docstring'''



       for i in range(self.num_buffers     ):
             if self.buffers[i] is None and i not in self.empty:
                   __A    		=     self.files[i].readline()

                   if self.buffers[i] == "":
                         self.empty.add(_A     )
                         self.files[i].close()

       if len(self.empty     ) == self.num_buffers:
             return False

       return True






 def 		lowercase_  (     self					:Any		,			_A					:Optional[int]     )			->     List[Any]:







       '''simple docstring'''



       __A    		=     self.buffers[index]
       __A    		=     None

       return value


class 	UpperCamelCase__					:






 def __init__(     self					:str		,			_A					:Dict     )			->     Optional[Any]:







       '''simple docstring'''



       __A    		=     merge_strategy






 def 		lowercase_  (     self					:Any		,			_A					:Optional[int]		,			_A					:int		,			_A					:str     )			->     Dict:







       '''simple docstring'''



       __A    		=     FilesArray(self.get_file_handles(_A		,			_A     )     )
       with open(_A		,			'w'		,			_A     ) as outfile:
             while buffers.refresh():
                   __A    		=     self.merge_strategy.select(buffers.get_dict()     )
                   outfile.write(buffers.unshift(_A     )     )






 def 		lowercase_  (     self					:List[Any]		,			_A					:Dict		,			_A					:Dict     )			->     List[Any]:







       '''simple docstring'''



       __A    		=     {}

       for i in range(len(_A     )     ):
             __A    		=     open(filenames[i]		,			'r'		,			_A     )  # noqa: UP015

       return files


class 	UpperCamelCase__					:






 def __init__(     self					:str		,			_A					:Any     )			->     Tuple:







       '''simple docstring'''



       __A    		=     block_size






 def 		lowercase_  (     self					:Dict		,			_A					:List[Any]		,			_A					:Tuple=None     )			->     str:







       '''simple docstring'''



       __A    		=     self.get_number_blocks(_A		,			self.block_size     )
       __A    		=     FileSplitter(_A     )
       splitter.split(self.block_size		,			_A     )

       __A    		=     FileMerger(NWayMerge()     )
       __A    		=     self.block_size / (num_blocks + 1)
       merger.merge(splitter.get_block_filenames()		,			filename + '.out'		,			_A     )

       splitter.cleanup()






 def 		lowercase_  (     self					:List[str]		,			_A					:Optional[Any]		,			_A					:List[str]     )			->     Optional[Any]:







       '''simple docstring'''



       return (os.stat(_A     ).st_size / block_size) + 1





def     snake_case							(						UpperCAmelCase		)->     Optional[Any]:







      """simple docstring"""
      if string[-1].lower() == "k":
            return int(string[:-1]		) * 1_0_2_4
      elif string[-1].lower() == "m":
            return int(string[:-1]		) * 1_0_2_4 * 1_0_2_4
      elif string[-1].lower() == "g":
            return int(string[:-1]		) * 1_0_2_4 * 1_0_2_4 * 1_0_2_4
      else:
            return int(UpperCAmelCase		)





def     snake_case							(						)->     Tuple:







      """simple docstring"""
      __A    		=     argparse.ArgumentParser()
      parser.add_argument(
          '-m' ,					'--mem' ,					help='amount of memory to use for sorting' ,					default='100M'		)
      parser.add_argument(
          'filename' ,					metavar='<filename>' ,					nargs=1 ,					help='name of file to sort'		)
      __A    		=     parser.parse_args()

      __A    		=     ExternalSort(parse_memory(args.mem		)		)
      sorter.sort(args.filename[0]		)


if __name__ == "__main__":
 main()








'''simple docstring'''





def     snake_case							(						UpperCAmelCase ,					UpperCAmelCase		)->     Union[str, Any]:







      """simple docstring"""
      print('\nVertex Distance'		)
      for i in range(UpperCAmelCase		):
            if dist[i] != float('inf'		):
                  print(UpperCAmelCase ,					'\t' ,					int(dist[i]		) ,					end='\t'		)
            else:
                  print(UpperCAmelCase ,					'\t' ,					'INF' ,					end='\t'		)
            print()





def     snake_case							(						UpperCAmelCase ,					UpperCAmelCase ,					UpperCAmelCase		)->     List[Any]:







      """simple docstring"""
      __A    		=     float('inf'		)
      __A    		=     -1
      for i in range(UpperCAmelCase		):
            if (not vset[i]) and mdist[i] < min_val:
                  __A    		=     i
                  __A    		=     mdist[i]
      return min_ind





def     snake_case							(						UpperCAmelCase ,					UpperCAmelCase ,					UpperCAmelCase		)->     Dict:







      """simple docstring"""
      __A    		=     [float('inf'		) for _ in range(UpperCAmelCase		)]
      __A    		=     [False for _ in range(UpperCAmelCase		)]
      __A    		=     0.0

      for _ in range(v - 1		):
            __A    		=     min_dist(UpperCAmelCase ,					UpperCAmelCase ,					UpperCAmelCase		)
            __A    		=     True

            for i in range(UpperCAmelCase		):
                  if (
                      (not vset[i])
                      and graph[u][i] != float('inf'		)
                      and mdist[u] + graph[u][i] < mdist[i]
                  ):
                        __A    		=     mdist[u] + graph[u][i]

      print_dist(UpperCAmelCase ,					UpperCAmelCase		)


if __name__ == "__main__":
 a__						:				Tuple           =    int(input("Enter number of vertices: ").strip())
 a__						:				List[str]           =    int(input("Enter number of edges: ").strip())

 a__						:				int           =    [[float("inf") for i in range(V)] for j in range(V)]

 for i in range(V):
  a__						:				Optional[int]           =    0.0

 for i in range(E):
  print("\nEdge ", i + 1)
  a__						:				Union[str, Any]           =    int(input("Enter source:").strip())
  a__						:				Tuple           =    int(input("Enter destination:").strip())
  a__						:				int           =    float(input("Enter weight:").strip())
  a__						:				Dict           =    weight

 a__						:				int           =    int(input("\nEnter shortest path source:").strip())
 dijkstra(graph, V, gsrc)






