

'''simple docstring'''
#
# Sort large text files in a minimum amount of memory
#
import argparse
import os
class  _snake_case						:
			__A   :     Union[str, Any]          ="block_{0}.dat"






			def __init__(   self       ,_snake_case			):
				UpperCAmelCase_			:	Optional[int]      =   filename
				UpperCAmelCase_			:	Union[str, Any]      =   []






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case			):
				UpperCAmelCase_			:	Tuple      =   self.BLOCK_FILENAME_FORMAT.format(_snake_case			)
				with open(_snake_case       ,"w"			) as file:
					file.write(_snake_case			)
				self.block_filenames.append(_snake_case			)






			def 						UpperCamelCase__				(   self			):
				return self.block_filenames






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case=None			):
				UpperCAmelCase_			:	Optional[Any]      =   0
				with open(self.filename			) as file:
					while True:
						UpperCAmelCase_			:	Optional[int]      =   file.readlines(_snake_case			)

						if lines == []:
							break

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

						self.write_block("".join(_snake_case			)       ,_snake_case			)
						i += 1






			def 						UpperCamelCase__				(   self			):
				map(os.remove       ,self.block_filenames			)




class  _snake_case						:






			def 						UpperCamelCase__				(   self       ,_snake_case			):
				UpperCAmelCase_			:	Any      =   -1
				UpperCAmelCase_			:	List[str]      =   None

				for i in range(len(_snake_case			)			):
					if min_str is None or choices[i] < min_str:
						UpperCAmelCase_			:	str      =   i

				return min_index




class  _snake_case						:






			def __init__(   self       ,_snake_case			):
				UpperCAmelCase_			:	Union[str, Any]      =   files
				UpperCAmelCase_			:	Union[str, Any]      =   set()
				UpperCAmelCase_			:	int      =   len(_snake_case			)
				UpperCAmelCase_			:	List[Any]      =   {i: None for i in range(self.num_buffers			)}






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






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

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

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

				return True






			def 						UpperCamelCase__				(   self       ,_snake_case			):
				UpperCAmelCase_			:	Optional[int]      =   self.buffers[index]
				UpperCAmelCase_			:	List[str]      =   None

				return value




class  _snake_case						:






			def __init__(   self       ,_snake_case			):
				UpperCAmelCase_			:	Dict      =   merge_strategy






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case       ,_snake_case			):
				UpperCAmelCase_			:	List[str]      =   FilesArray(self.get_file_handles(_snake_case       ,_snake_case			)			)
				with open(_snake_case       ,"w"       ,_snake_case			) as outfile:
					while buffers.refresh():
						UpperCAmelCase_			:	Optional[int]      =   self.merge_strategy.select(buffers.get_dict()			)
						outfile.write(buffers.unshift(_snake_case			)			)






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case			):
				UpperCAmelCase_			:	Optional[Any]      =   {}

				for i in range(len(_snake_case			)			):
					UpperCAmelCase_			:	Optional[Any]      =   open(filenames[i]       ,"r"       ,_snake_case			)  # noqa: UP015

				return files




class  _snake_case						:






			def __init__(   self       ,_snake_case			):
				UpperCAmelCase_			:	Optional[int]      =   block_size






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case=None			):
				UpperCAmelCase_			:	int      =   self.get_number_blocks(_snake_case       ,self.block_size			)
				UpperCAmelCase_			:	Dict      =   FileSplitter(_snake_case			)
				splitter.split(self.block_size       ,_snake_case			)

				UpperCAmelCase_			:	Dict      =   FileMerger(NWayMerge()			)
				UpperCAmelCase_			:	Optional[int]      =   self.block_size / (num_blocks + 1)
				merger.merge(splitter.get_block_filenames()       ,filename + ".out"       ,_snake_case			)

				splitter.cleanup()






			def 						UpperCamelCase__				(   self       ,_snake_case       ,_snake_case			):
				return (os.stat(_snake_case			).st_size / block_size) + 1




def       a__    (  _SCREAMING_SNAKE_CASE					:    str							)			-> str:


	"""simple docstring"""





	if string[-1].lower() == "k":
		return int(string[:-1]							) * 10_24
	elif string[-1].lower() == "m":
		return int(string[:-1]							) * 10_24 * 10_24
	elif string[-1].lower() == "g":
		return int(string[:-1]							) * 10_24 * 10_24 * 10_24
	else:
		return int(_SCREAMING_SNAKE_CASE							)


def       a__    (  )			-> int:


	"""simple docstring"""





	UpperCAmelCase_			:	Union[str, Any]      =   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"							)
	UpperCAmelCase_			:	List[str]      =   parser.parse_args()

	UpperCAmelCase_			:	str      =   ExternalSort(parse_memory(args.mem							)							)
	sorter.sort(args.filename[0]							)


if __name__ == "__main__":
					main()






def 				A__    (  lowerCamelCase  )     ->		Optional[Any]:
				UpperCamelCase_:							Optional[int]		=  len(lowerCamelCase  )
				for _ in range(
				    0   ,			int(((no_of_elements - 1) / 2) + 1  )  ):  # we don't need to traverse to end of list as
								for j in range(0   ,			no_of_elements - 1  ):
												if (
												    lst[j + 1] < lst[j]
												):  # applying bubble sort algorithm from left to right (or forwards)
																UpperCamelCase_:							str		=  lst[j + 1]
																UpperCamelCase_:							Tuple		=  lst[j]
																UpperCamelCase_:							str		=  temp
												if (
												    lst[no_of_elements - 1 - j] < lst[no_of_elements - 2 - j]
												):  # applying bubble sort algorithm from right to left (or backwards)
																UpperCamelCase_:							Union[str, Any]		=  lst[no_of_elements - 1 - j]
																UpperCamelCase_:							Dict		=  lst[no_of_elements - 2 - j]
																UpperCamelCase_:							List[Any]		=  temp
				return lst


if __name__ == "__main__":
							print("""enter the list to be sorted""")
							lowerCamelCase_  :       Union[str, Any]					      =     [int(x) for x in input().split()]  # inputing elements of the list in one line
							lowerCamelCase_  :       Union[str, Any]					      =     double_sort(lst)
							print("""the sorted list is""")
							print(sorted_lst)






