



from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

__magic_name__       =     TypeVar('''T''')
__magic_name__       =     TypeVar('''U''')


class 	a__       (       Generic[T, U]       ):


					"""simple docstring"""



					def __init__(		self     :List[Any]      ,  lowercase__     :T | None      ,  lowercase__     :U | None    ):
										lowercase						   =       key
										lowercase						   =       val
										lowercase						   =       0
										lowercase						   =       None
										lowercase						   =       None



					def __repr__(		self     :List[str]    ):
										return "Node: key: {}, val: {}, freq: {}, has next: {}, has prev: {}".format(
										    self.key      ,  self.val      ,  self.freq      ,  self.next is not None      ,  self.prev is not None    )




class 	a__       (       Generic[T, U]       ):


					"""simple docstring"""



					def __init__(		self     :Dict    ):
										lowercase						   =       DoubleLinkedListNode(lowercase__      ,  lowercase__    )
										lowercase						   =       DoubleLinkedListNode(lowercase__      ,  lowercase__    )
										lowercase   ,      lowercase						   =       self.rear, self.head

					def __repr__(		self     :Optional[Any]    ):
										lowercase						   =       ['DoubleLinkedList']
										lowercase						   =       self.head
										while node.next is not None:
															rep.append(str(lowercase__    )    )
															lowercase						   =       node.next
										rep.append(str(self.rear    )    )
										return ",\n    ".join(lowercase__    )

					def 				__UpperCAmelCase		(		self     :List[str]      ,  lowercase__     :DoubleLinkedListNode[T, U]    ):
										lowercase						   =       self.rear.prev

										# All nodes other than self.head are guaranteed to have non-None previous
										assert previous is not None

										lowercase						   =       node
										lowercase						   =       previous
										lowercase						   =       node
										lowercase						   =       self.rear
										node.freq += 1
										self._position_node(lowercase__    )

					def 				__UpperCAmelCase		(		self     :Tuple      ,  lowercase__     :DoubleLinkedListNode[T, U]    ):

										while node.prev is not None and node.prev.freq > node.freq:
															# swap node with previous node
															lowercase						   =       node.prev

															lowercase						   =       previous_node.prev
															lowercase						   =       node.prev
															lowercase						   =       previous_node
															lowercase						   =       node



					def 				__UpperCAmelCase		(		self     :int      ,  lowercase__     :DoubleLinkedListNode[T, U]    ):

										if node.prev is None or node.next is None:
															return None

										lowercase						   =       node.next
										lowercase						   =       node.prev
										lowercase						   =       None
										lowercase						   =       None
										return node




class 	a__       (       Generic[T, U]       ):


					"""simple docstring"""



					A__  :				dict[Callable[[T], U], LFUCache[T, U]]					 =				{}

					def __init__(		self     :Tuple      ,  lowercase__     :int    ):
										lowercase						   =       DoubleLinkedList()
										lowercase						   =       capacity
										lowercase						   =       0
										lowercase						   =       0
										lowercase						   =       0
										lowercase						   =       {}

					def __repr__(		self     :Union[str, Any]    ):
										return (
										    F"""CacheInfo(hits={self.hits}, misses={self.miss}, """
										    F"""capacity={self.capacity}, current_size={self.num_keys})"""
										)

					def __contains__(		self     :int      ,  lowercase__     :T    ):
										return key in self.cache

					def 				__UpperCAmelCase		(		self     :Optional[Any]      ,  lowercase__     :T    ):

										if key in self.cache:
															self.hits += 1
															lowercase						   =       self.cache[key]
															lowercase						   =       self.list.remove(self.cache[key]    )
															assert node == value_node

															# node is guaranteed not None because it is in self.cache
															assert node is not None
															self.list.add(lowercase__    )
															return node.val
										self.miss += 1
										return None

					def 				__UpperCAmelCase		(		self     :Dict      ,  lowercase__     :T      ,  lowercase__     :U    ):

										if key not in self.cache:
															if self.num_keys >= self.capacity:
																				# delete first node when over capacity
																				lowercase						   =       self.list.head.next

																				# guaranteed to have a non-None first node when num_keys > 0
																				# explain to type checker via assertions
																				assert first_node is not None
																				assert first_node.key is not None
																				assert self.list.remove(lowercase__    ) is not None
																				# first_node guaranteed to be in list

																				del self.cache[first_node.key]
																				self.num_keys -= 1
															lowercase						   =       DoubleLinkedListNode(lowercase__      ,  lowercase__    )
															self.list.add(self.cache[key]    )
															self.num_keys += 1

										else:
															lowercase						   =       self.list.remove(self.cache[key]    )
															assert node is not None  # node guaranteed to be in list
															lowercase						   =       value
															self.list.add(lowercase__    )



					@classmethod
					def 				__UpperCAmelCase		(		cls     :type[LFUCache[T, U]]      ,  lowercase__     :int = 128    ):

										def cache_decorator_inner(lowercase__     :Callable[[T], U]    ) -> Callable[..., U]:
															def cache_decorator_wrapper(*lowercase__     :T    ) -> U:
																				if func not in cls.decorator_function_to_instance_map:
																									lowercase						   =       LFUCache(lowercase__    )

																				lowercase						   =       cls.decorator_function_to_instance_map[func].get(args[0]    )
																				if result is None:
																									lowercase						   =       func(*lowercase__    )
																									cls.decorator_function_to_instance_map[func].put(args[0]      ,  lowercase__    )
																				return result

															def cache_info() -> LFUCache[T, U]:
																				return cls.decorator_function_to_instance_map[func]

															setattr(lowercase__      ,  'cache_info'      ,  lowercase__    )  # noqa: B010

															return cache_decorator_wrapper

										return cache_decorator_inner


if __name__ == "__main__":
		import doctest

		doctest.testmod()











from __future__ import annotations

# Define the Gravitational Constant G and the function
__magic_name__       =     6.6743E-11  # unit of G : m^3 * kg^-1 * s^-2





def 		__snake_case						(    _UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase				):
					"""simple docstring"""






					lowercase						   =       mass_a * mass_a

					if (force, mass_a, mass_a, distance).count(0				) != 1:
										raise ValueError('One and only one argument must be 0'				)
					if force < 0:
										raise ValueError('Gravitational force can not be negative'				)
					if distance < 0:
										raise ValueError('Distance can not be negative'				)
					if mass_a < 0 or mass_a < 0:
										raise ValueError('Mass can not be negative'				)
					if force == 0:
										lowercase						   =       GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
										return {"force": force}
					elif mass_a == 0:
										lowercase						   =       (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
										return {"mass_1": mass_a}
					elif mass_a == 0:
										lowercase						   =       (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
										return {"mass_2": mass_a}
					elif distance == 0:
										lowercase						   =       (GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
										return {"distance": distance}
					raise ValueError('One and only one argument must be 0'				)


# Run doctest
if __name__ == "__main__":
		import doctest

		doctest.testmod()






