"""simple docstring"""




from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

__lowerCAmelCase													=						TypeVar("T")







def 							_UpperCAmelCase		(       lowerCamelCase__     ):





		"""simple docstring"""




		return (position - 1) // 2







def 							_UpperCAmelCase		(       lowerCamelCase__     ):





		"""simple docstring"""




		return (2 * position) + 1







def 							_UpperCAmelCase		(       lowerCamelCase__     ):





		"""simple docstring"""




		return (2 * position) + 2

class       a_      (     Generic[T]			):




					def __init__(	self						:     Optional[Any]     ):
							lowerCAmelCase__        =   []
							lowerCAmelCase__        =   {}
							lowerCAmelCase__        =   0




					def __len__(	self						:     Dict     ):
							return self.elements




					def __repr__(	self						:     Dict     ):
							return str(self.heap     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Tuple     ):
							return self.elements == 0




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Any  ,						snake_case__						:     T  ,						snake_case__						:     int     ):
							self.heap.append((elem, weight)     )
							lowerCAmelCase__        =   self.elements
							self.elements += 1
							self._bubble_up(UpperCAmelCase_     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]     ):



							if self.elements > 1:
									self._swap_nodes(0  ,						self.elements - 1     )
							lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap.pop()
							del self.position_map[elem]
							self.elements -= 1
							if self.elements > 0:
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[0]
									self._bubble_down(UpperCAmelCase_     )
							return elem




					def 						_SCREAMING_SNAKE_CASE						(	self						:     List[Any]  ,						snake_case__						:     T  ,						snake_case__						:     int     ):
							lowerCAmelCase__        =   self.position_map[elem]
							lowerCAmelCase__        =   (elem, weight)
							if position > 0:
									lowerCAmelCase__        =   get_parent_position(UpperCAmelCase_     )
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[parent_position]
									if parent_weight > weight:
											self._bubble_up(UpperCAmelCase_     )
									else:
											self._bubble_down(UpperCAmelCase_     )
							else:
									self._bubble_down(UpperCAmelCase_     )




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]  ,						snake_case__						:     T     ):
							lowerCAmelCase__        =   self.position_map[elem]
							if curr_pos == 0:
									return None
							lowerCAmelCase__        =   get_parent_position(UpperCAmelCase_     )
							lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[curr_pos]
							lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[parent_position]
							if parent_weight > weight:
									self._swap_nodes(UpperCAmelCase_  ,						UpperCAmelCase_     )
									return self._bubble_up(UpperCAmelCase_     )
							return None




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Optional[Any]  ,						snake_case__						:     T     ):
							lowerCAmelCase__        =   self.position_map[elem]
							lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[curr_pos]
							lowerCAmelCase__        =   get_child_left_position(UpperCAmelCase_     )
							lowerCAmelCase__        =   get_child_right_position(UpperCAmelCase_     )
							if child_left_position < self.elements and child_right_position < self.elements:
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[child_left_position]
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[child_right_position]
									if child_right_weight < child_left_weight and child_right_weight < weight:
											self._swap_nodes(UpperCAmelCase_  ,						UpperCAmelCase_     )
											return self._bubble_down(UpperCAmelCase_     )
							if child_left_position < self.elements:
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[child_left_position]
									if child_left_weight < weight:
											self._swap_nodes(UpperCAmelCase_  ,						UpperCAmelCase_     )
											return self._bubble_down(UpperCAmelCase_     )
							else:
									return None
							if child_right_position < self.elements:
									lowerCAmelCase__   ,					lowerCAmelCase__        =   self.heap[child_right_position]
									if child_right_weight < weight:
											self._swap_nodes(UpperCAmelCase_  ,						UpperCAmelCase_     )
											return self._bubble_down(UpperCAmelCase_     )
							return None




					def 						_SCREAMING_SNAKE_CASE						(	self						:     List[Any]  ,						snake_case__						:     int  ,						snake_case__						:     int     ):
							lowerCAmelCase__        =   self.heap[nodea_pos][0]
							lowerCAmelCase__        =   self.heap[nodea_pos][0]
							lowerCAmelCase__   ,					lowerCAmelCase__        =   (
							    self.heap[nodea_pos],
							    self.heap[nodea_pos],
							)
							lowerCAmelCase__        =   nodea_pos
							lowerCAmelCase__        =   nodea_pos

class       a_      (     Generic[T]			):




					def __init__(	self						:     Any     ):
							lowerCAmelCase__        =   {}
							lowerCAmelCase__        =   0




					def __repr__(	self						:     Tuple     ):
							return str(self.connections     )




					def __len__(	self						:     Dict     ):
							return self.nodes




					def 						_SCREAMING_SNAKE_CASE						(	self						:     int  ,						snake_case__						:     T     ):



							if node not in self.connections:
									lowerCAmelCase__        =   {}
									self.nodes += 1




					def 						_SCREAMING_SNAKE_CASE						(	self						:     Any  ,						snake_case__						:     T  ,						snake_case__						:     T  ,						snake_case__						:     int     ):
							self.add_node(UpperCAmelCase_     )
							self.add_node(UpperCAmelCase_     )
							lowerCAmelCase__        =   weight
							lowerCAmelCase__        =   weight







def 							_UpperCAmelCase		(       lowerCamelCase__			,  ):





		"""simple docstring"""




		lowerCAmelCase__        =   {node: maxsize for node in graph.connections}
		lowerCAmelCase__        =   {node: None for node in graph.connections}

		lowerCAmelCase__        =   MinPriorityQueue()
		for node, weight in dist.items():
				priority_queue.push(_SCREAMING_SNAKE_CASE			,  _SCREAMING_SNAKE_CASE     )

		if priority_queue.is_empty():
				return dist, parent

		# initialization
		lowerCAmelCase__        =   priority_queue.extract_min()
		lowerCAmelCase__        =   0
		for neighbour in graph.connections[node]:
				if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
						lowerCAmelCase__        =   dist[node] + graph.connections[node][neighbour]
						priority_queue.update_key(_SCREAMING_SNAKE_CASE			,  dist[neighbour]     )
						lowerCAmelCase__        =   node

    # running prim's algorithm
		while not priority_queue.is_empty():
				lowerCAmelCase__        =   priority_queue.extract_min()
				for neighbour in graph.connections[node]:
						if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
								lowerCAmelCase__        =   dist[node] + graph.connections[node][neighbour]
								priority_queue.update_key(_SCREAMING_SNAKE_CASE			,  dist[neighbour]     )
								lowerCAmelCase__        =   node
		return dist, parent





"""simple docstring"""




from math import pi, sqrt







def 							_UpperCAmelCase		(       lowerCamelCase__     ):





		"""simple docstring"""




		if num <= 0:
				raise ValueError("""math domain error"""     )
		if num > 1_71.5:
				raise OverflowError("""math range error"""     )
		elif num - int(lowerCamelCase__     ) not in (0, 0.5):
				raise NotImplementedError("""num must be an integer or a half-integer"""     )
		elif num == 0.5:
				return sqrt(lowerCamelCase__     )
		else:
				return 1.0 if num == 1 else (num - 1) * gamma(num - 1     )







def 							_UpperCAmelCase		(       ):





		"""simple docstring"""




		assert gamma(0.5     ) == sqrt(lowerCamelCase__     )
		assert gamma(1     ) == 1.0
		assert gamma(2     ) == 1.0


if __name__ == "__main__":
			from doctest import testmod

			testmod()
			__lowerCAmelCase    :							Dict													=						1.0
			while num:
						__lowerCAmelCase    :							Any													=						float(input("Gamma of: "))
						print(F"gamma({num}) = {gamma(num)}")
						print("\nEnter 0 to exit...")




