code: 
  
  
  '''simple docstring'''
  
  #
  # Sort large text files in a minimum amount of memory
  #
  import argparse
  import os
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        lowerCAmelCase__      :  Optional[Any]						      =							"""block_{0}.dat"""
  
  
  
        def __init__(self					:					Dict     ,		UpperCamelCase					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				filename
               lowercase__       =				[]
  
  
  
        def    UpperCamelCase__	(self					:					Optional[Any]     ,		UpperCamelCase					:					Optional[Any]     ,		UpperCamelCase					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.BLOCK_FILENAME_FORMAT.format(lowerCAmelCase_				)
               with open(lowerCAmelCase_     ,		'''w'''				) as file:
                      file.write(lowerCAmelCase_				)
               self.block_filenames.append(lowerCAmelCase_				)
  
  
  
        def    UpperCamelCase__	(self					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.block_filenames
  
  
  
        def    UpperCamelCase__	(self					:					List[Any]     ,		UpperCamelCase					:					Tuple     ,		UpperCamelCase					:					Optional[int]=None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				0
               with open(self.filename				) as file:
                      while True:
                             lowercase__       =				file.readlines(lowerCAmelCase_				)
  
                             if lines == []:
                                    break
  
                             if sort_key is None:
                                    lines.sort()
                             else:
                                    lines.sort(key=lowerCAmelCase_				)
  
                             self.write_block(''''''.join(lowerCAmelCase_				)     ,		lowerCAmelCase_				)
                             i += 1
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					Any				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               map(os.remove     ,		self.block_filenames				)
  
  
  
  
  
  
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					Any     ,		UpperCamelCase					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				-1
               lowercase__       =				None
  
               for i in range(len(lowerCAmelCase_				)				):
                      if min_str is None or choices[i] < min_str:
                             lowercase__       =				i
  
               return min_index
  
  
  
  
  
  
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __init__(self					:					Tuple     ,		UpperCamelCase					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				files
               lowercase__       =				set()
               lowercase__       =				len(lowerCAmelCase_				)
               lowercase__       =				{i: None for i in range(self.num_buffers				)}
  
  
  
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return {
                   i: self.buffers[i] for i in range(self.num_buffers				) if i not in self.empty
               }
  
  
  
        def    UpperCamelCase__	(self					:					Dict				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               for i in range(self.num_buffers				):
                      if self.buffers[i] is None and i not in self.empty:
                             lowercase__       =				self.files[i].readline()
  
                             if self.buffers[i] == "":
                                    self.empty.add(lowerCAmelCase_				)
                                    self.files[i].close()
  
               if len(self.empty				) == self.num_buffers:
                      return False
  
               return True
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					int     ,		UpperCamelCase					:					Union[str, Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.buffers[index]
               lowercase__       =				None
  
               return value
  
  
  
  
  
  
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __init__(self					:					Any     ,		UpperCamelCase					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				merge_strategy
  
  
  
        def    UpperCamelCase__	(self					:					List[str]     ,		UpperCamelCase					:					Dict     ,		UpperCamelCase					:					Union[str, Any]     ,		UpperCamelCase					:					Union[str, Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				FilesArray(self.get_file_handles(lowerCAmelCase_     ,		lowerCAmelCase_				)				)
               with open(lowerCAmelCase_     ,		'''w'''     ,		lowerCAmelCase_				) as outfile:
                      while buffers.refresh():
                             lowercase__       =				self.merge_strategy.select(buffers.get_dict()				)
                             outfile.write(buffers.unshift(lowerCAmelCase_				)				)
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					List[str]     ,		UpperCamelCase					:					Union[str, Any]     ,		UpperCamelCase					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				{}
  
               for i in range(len(lowerCAmelCase_				)				):
                      lowercase__       =				open(filenames[i]     ,		'''r'''     ,		lowerCAmelCase_				)  # noqa: UP015
  
               return files
  
  
  
  
  
  
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __init__(self					:					int     ,		UpperCamelCase					:					List[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				block_size
  
  
  
        def    UpperCamelCase__	(self					:					Optional[Any]     ,		UpperCamelCase					:					Optional[int]     ,		UpperCamelCase					:					int=None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.get_number_blocks(lowerCAmelCase_     ,		self.block_size				)
               lowercase__       =				FileSplitter(lowerCAmelCase_				)
               splitter.split(self.block_size     ,		lowerCAmelCase_				)
  
               lowercase__       =				FileMerger(NWayMerge()				)
               lowercase__       =				self.block_size / (num_blocks + 1)
               merger.merge(splitter.get_block_filenames()     ,		filename + '''.out'''     ,		lowerCAmelCase_				)
  
               splitter.cleanup()
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					int     ,		UpperCamelCase					:					Dict     ,		UpperCamelCase					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return (os.stat(lowerCAmelCase_				).st_size / block_size) + 1
  
  
  
  
  
  
  def _SCREAMING_SNAKE_CASE   (A ) -> List[Any]:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         if string[-1].lower() == "k":
                return int(string[:-1] ) * 1_024
         elif string[-1].lower() == "m":
                return int(string[:-1] ) * 1_024 * 1_024
         elif string[-1].lower() == "g":
                return int(string[:-1] ) * 1_024 * 1_024 * 1_024
         else:
                return int(A )
  
  def _SCREAMING_SNAKE_CASE   () -> Tuple:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				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''' )
         lowercase__       =				parser.parse_args()
  
         lowercase__       =				ExternalSort(parse_memory(args.mem ) )
         sorter.sort(args.filename[0] )
  
  
  if __name__ == "__main__":
   main()
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  from __future__ import annotations
  
  from collections import Counter
  
  def _SCREAMING_SNAKE_CASE   (A ) -> list[int]:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				[True] * n
         lowercase__       =				False
         lowercase__       =				False
         lowercase__       =				True
  
         for i in range(3						,				int(n**0.5 + 1 )						,				2 ):
                lowercase__       =				i * 2
                while index < n:
                       lowercase__       =				False
                       lowercase__       =				index + i
  
         lowercase__       =				[2]
  
         for i in range(3						,				A						,				2 ):
                if is_prime[i]:
                       primes.append(A )
  
         return primes
  
  def _SCREAMING_SNAKE_CASE   (A ) -> list[list[int]]:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				str(A )
         lowercase__       =				[]
         lowercase__       =				['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']
  
         for duplicate in Counter(A ) - Counter(set(A ) ):
                lowercase__       =				[int(number_str.replace(A						,				A ) ) for digit in digits]
                replacements.append(A )
  
         return replacements
  
  def _SCREAMING_SNAKE_CASE   (A = 8 ) -> int:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				set()
  
         # Filter primes with less than 3 replaceable digits
         lowercase__       =				{
             x for x in set(prime_sieve(1_000_000 ) ) if len(str(A ) ) - len(set(str(A ) ) ) >= 3
         }
  
         for prime in primes:
                if prime in numbers_checked:
                       continue
  
                lowercase__       =				digit_replacements(A )
  
                for family in replacements:
                       numbers_checked.update(A )
                       lowercase__       =				primes.intersection(A )
  
                       if len(A ) != family_length:
                              continue
  
                       return min(A )
  
         return -1
  
  
  if __name__ == "__main__":
   print(solution())
  
  
  
  
  