

def 					a				(      A__     :       Optional[int]					)   ->				int:





      """simple docstring"""



      if not isinstance(A__				,       A__					):
            raise ValueError('double_factorial() only accepts integral values'					)
      if num < 0:
            raise ValueError('double_factorial() not defined for negative values'					)
      _lowercase     	=1
      for i in range(A__				,       0				,       -2					):
            value *= i
      return value


if __name__ == "__main__":
  import doctest

  doctest.testmod()





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





class 			__lowerCAmelCase					:
  _a						      =  """block_{0}.dat"""




  def __init__(    self							,       lowerCAmelCase )  ->			List[str]:
        '''simple docstring'''






        _lowercase     	=filename
        _lowercase     	=[]




  def   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase )  ->			str:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Dict:
        '''simple docstring'''






        return self.block_filenames




  def   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase=None )  ->			Dict:
        '''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   A__					(    self )  ->			Optional[Any]:
        '''simple docstring'''






        map(os.remove							,       self.block_filenames )





class 			__lowerCAmelCase					:




  def   A__					(    self							,       lowerCAmelCase )  ->			Union[str, Any]:
        '''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					:




  def __init__(    self							,       lowerCAmelCase )  ->			int:
        '''simple docstring'''






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




  def   A__					(    self )  ->			int:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Union[str, Any]:
        '''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   A__					(    self							,       lowerCAmelCase )  ->			Optional[int]:
        '''simple docstring'''






        _lowercase     	=self.buffers[index]
        _lowercase     	=None

        return value





class 			__lowerCAmelCase					:




  def __init__(    self							,       lowerCAmelCase )  ->			Any:
        '''simple docstring'''






        _lowercase     	=merge_strategy




  def   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase )  ->			str:
        '''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   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase )  ->			Optional[int]:
        '''simple docstring'''






        _lowercase     	={}

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

        return files





class 			__lowerCAmelCase					:




  def __init__(    self							,       lowerCAmelCase )  ->			Union[str, Any]:
        '''simple docstring'''






        _lowercase     	=block_size




  def   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase=None )  ->			Dict:
        '''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   A__					(    self							,       lowerCAmelCase							,       lowerCAmelCase )  ->			Tuple:
        '''simple docstring'''






        return (os.stat(lowerCAmelCase ).st_size / block_size) + 1
def 					a				(      A__     :       Tuple					)   ->				Optional[Any]:





      """simple docstring"""



      if string[-1].lower() == "k":
            return int(string[:-1]					) * 1024
      elif string[-1].lower() == "m":
            return int(string[:-1]					) * 1024 * 1024
      elif string[-1].lower() == "g":
            return int(string[:-1]					) * 1024 * 1024 * 1024
      else:
            return int(A__					)
def 					a				(      )   ->				str:





      """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()


