



import gc
import threading
import time

import psutil
import torch
class 					a	:



  def __init__(						self :					Tuple		)     ->					Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=psutil.Process()
     SCREAMING_SNAKE_CASE_: Tuple     			=False



  def 	lowerCamelCase__       (						self :					Optional[Any]		)     ->					str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[str]     			=-1

     while True:
        SCREAMING_SNAKE_CASE_: Optional[int]     			=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 	lowerCamelCase__       (						self :					List[str]		)     ->					Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[Any]     			=True
     SCREAMING_SNAKE_CASE_: int     			=threading.Thread(target=self.peak_monitor		)
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=True
     self.thread.start()





  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Optional[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=False
     self.thread.join()
     return self.cpu_memory_peak







_UpperCAmelCase     =			PeakCPUMemory()





def      __magic_name__				(							):
   # Time
   SCREAMING_SNAKE_CASE_: Optional[int]     			={"""time""": time.time()}

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

   # CPU mem
   SCREAMING_SNAKE_CASE_: List[Any]     			=psutil.Process().memory_info().rss
   cpu_peak_tracker.start()

   # GPU mem
   for i in range(torch.cuda.device_count() ):
      SCREAMING_SNAKE_CASE_: List[Any]     			=torch.cuda.memory_allocated(lowercase )
   torch.cuda.reset_peak_memory_stats()

   return measures





def      __magic_name__				(							lowercase ):
   # Time
   SCREAMING_SNAKE_CASE_: Union[str, Any]     			={"""time""": time.time() - start_measures["""time"""]}

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

   # CPU mem
   SCREAMING_SNAKE_CASE_: Any     			=(psutil.Process().memory_info().rss - start_measures["""cpu"""]) / 2**20
   SCREAMING_SNAKE_CASE_: Dict     			=(cpu_peak_tracker.stop() - start_measures["""cpu"""]) / 2**20

   # GPU mem
   for i in range(torch.cuda.device_count() ):
      SCREAMING_SNAKE_CASE_: Dict     			=(torch.cuda.memory_allocated(lowercase ) - start_measures[str(lowercase )]) / 2**20
      SCREAMING_SNAKE_CASE_: Optional[int]     			=(torch.cuda.max_memory_allocated(lowercase ) - start_measures[str(lowercase )]) / 2**20

   return measures





def      __magic_name__				(							lowercase							,			lowercase ):
   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(lowercase )]:.2f}MiB''' )
      SCREAMING_SNAKE_CASE_: int     			=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''' )








"""simple docstring"""
from __future__ import annotations





def      __magic_name__				(							lowercase							,			lowercase ):
   SCREAMING_SNAKE_CASE_: List[Any]     			=sorted(numsa + numsa )
   SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Tuple     			=divmod(len(lowercase )							,			2 )
   if mod == 1:
      return all_numbers[div]
   else:
      return (all_numbers[div] + all_numbers[div - 1]) / 2


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   _UpperCAmelCase     =			[float(x) for x in input("""Enter the elements of first array: """).split()]
   _UpperCAmelCase     =			[float(x) for x in input("""Enter the elements of second array: """).split()]
   print(f"""The median of two arrays is: {median_of_two_arrays(array_a, array_a)}""")



