'''simple docstring'''

def snake_case_      (					__snake_case  :							Union[str, Any]	,   __snake_case  :							int)			->					List[str]:
   lowerCAmelCase_			=      [0 for i in range(r + 1)]
   # nc0 = 1
   lowerCAmelCase_			=      1
   for i in range(1	,   n + 1):
      # to compute current row from previous row.
      lowerCAmelCase_			=      min(__snake_case	,   __snake_case)
      while j > 0:
         c[j] += c[j - 1]
         j -= 1
   return c[r]






print(binomial_coefficient(n=10, r=5))






'''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''')





