



"""simple docstring"""






def      _lowercase							(    __snake_case   ,__snake_case      )		->  int:
			__lowerCAmelCase :    List[str]				=			1  # To kept the Calculated Value
			# Since C(n, k) = C(n, n-k)
			if k > (n - k):
						__lowerCAmelCase :    List[str]				=			n - k
			# Calculate C(n,k)
			for i in range(__snake_case      ):
						result *= n - i
						result //= i + 1
			return result


def      _lowercase							(    __snake_case      )		->  int:
			return binomial_coefficient(2 * node_count   ,__snake_case      ) // (node_count + 1)


def      _lowercase							(    __snake_case      )		->  int:
			if n < 0:
						raise ValueError("factorial() not defined for negative values"      )
			__lowerCAmelCase :    Optional[int]				=			1
			for i in range(1   ,n + 1      ):
						result *= i
			return result


def      _lowercase							(    __snake_case      )		->  int:
			return catalan_number(__snake_case      ) * factorial(__snake_case      )


if __name__ == "__main__":
	__snake_case				:  Dict =       int(input('Enter the number of nodes: ').strip() or 0)
	if node_count <= 0:
		raise ValueError('We need some nodes to work with.')
	print(
	    F"""Given {node_count} nodes, there are {binary_tree_count(node_count)} """
	    F"""binary trees and {catalan_number(node_count)} binary search trees."""
	)
'''simple docstring'''

import gc
import threading
import time

import psutil
import torch


class     __UpperCAmelCase       :





  def __init__(	self ):
     lowerCAmelCase_			=      psutil.Process()
     lowerCAmelCase_			=      False





  def 						UpperCAmelCase_	(	self ):
     lowerCAmelCase_			=      -1

     while True:
        lowerCAmelCase_			=      max(self.process.memory_info().rss    ,     self.cpu_memory_peak )

        # can't sleep or will not catch the peak right (this comment is here on purpose)
        if not self.peak_monitoring:
           break





  def 						UpperCAmelCase_	(	self ):
     lowerCAmelCase_			=      True
     lowerCAmelCase_			=      threading.Thread(target=self.peak_monitor )
     lowerCAmelCase_			=      True
     self.thread.start()







  def 						UpperCAmelCase_	(	self ):
     lowerCAmelCase_			=      False
     self.thread.join()
     return self.cpu_memory_peak






A_     :						List[str]    							=PeakCPUMemory()



def snake_case_      (					)			->					Tuple:
   # Time
   lowerCAmelCase_			=      {'''time''': time.time()}

   gc.collect()
   torch.cuda.empty_cache()

   # CPU mem
   lowerCAmelCase_			=      psutil.Process().memory_info().rss
   cpu_peak_tracker.start()

   # GPU mem
   for i in range(torch.cuda.device_count()):
      lowerCAmelCase_			=      torch.cuda.memory_allocated(__snake_case)
   torch.cuda.reset_peak_memory_stats()

   return measures



def snake_case_      (					__snake_case  :							Any)			->					List[str]:
   # Time
   lowerCAmelCase_			=      {'''time''': time.time() - start_measures['''time''']}

   gc.collect()
   torch.cuda.empty_cache()

   # CPU mem
   lowerCAmelCase_			=      (psutil.Process().memory_info().rss - start_measures['''cpu''']) / 2**20
   lowerCAmelCase_			=      (cpu_peak_tracker.stop() - start_measures['''cpu''']) / 2**20

   # GPU mem
   for i in range(torch.cuda.device_count()):
      lowerCAmelCase_			=      (torch.cuda.memory_allocated(__snake_case) - start_measures[str(__snake_case)]) / 2**20
      lowerCAmelCase_			=      (torch.cuda.max_memory_allocated(__snake_case) - start_measures[str(__snake_case)]) / 2**20

   return measures






def snake_case_      (					__snake_case  :							Dict	,   __snake_case  :							Optional[int])			->					Dict:
   print(F'''{description}:''')
   print(F'''- Time: {measures['time']:.2f}s''')
   for i in range(torch.cuda.device_count()):
      print(F'''- GPU {i} allocated: {measures[str(__snake_case)]:.2f}MiB''')
      lowerCAmelCase_			=      measures[F'''{i}-peak''']
      print(F'''- GPU {i} peak: {peak:.2f}MiB''')
   print(F'''- CPU RAM allocated: {measures['cpu']:.2f}MiB''')
   print(F'''- CPU RAM peak: {measures['cpu-peak']:.2f}MiB''')





