






from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

lowerCamelCase       :       List[str]        =				TypeVar('''T''')
def 					snake_case_						(   lowerCAmelCase_				:  int					):
							return (position - 1) // 2
def 					snake_case_						(   lowerCAmelCase_				:  int					):
							return (2 * position) + 1
def 					snake_case_						(   lowerCAmelCase_				:  int					):
							return (2 * position) + 2

class 						lowerCAmelCase   (       Generic[T]	):

					'''simple docstring'''

					def __init__(     self :		Tuple							)	->     None:


												"""simple docstring"""

												__lowercase					:							list[tuple[T, int]]			=   []
												__lowercase					:							dict[T, int]			=   {}
												__lowercase					:							int			=   0



					def __len__(     self :		List[str]							)	->     int:


												"""simple docstring"""

												return self.elements



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


												"""simple docstring"""

												return str(self.heap							)



					def 					lowerCAmelCase (     self :		List[str]							)	->     bool:


												"""simple docstring"""

												return self.elements == 0



					def 					lowerCAmelCase (     self :		Tuple						,   __a :		T						,   __a :		int							)	->     None:


												"""simple docstring"""

												self.heap.append((elem, weight)							)
												__lowercase					:							Union[str, Any]			=   self.elements
												self.elements += 1
												self._bubble_up(__a							)



					def 					lowerCAmelCase (     self :		Tuple							)	->     T:


												"""simple docstring"""

												if self.elements > 1:
																			self._swap_nodes(0						,   self.elements - 1							)
												__lowercase	,	__lowercase					:							List[str]			=   self.heap.pop()
												del self.position_map[elem]
												self.elements -= 1
												if self.elements > 0:
																			__lowercase	,	__lowercase					:							List[str]			=   self.heap[0]
																			self._bubble_down(__a							)
												return elem



					def 					lowerCAmelCase (     self :		int						,   __a :		T						,   __a :		int							)	->     None:


												"""simple docstring"""

												__lowercase					:							Union[str, Any]			=   self.position_map[elem]
												__lowercase					:							Any			=   (elem, weight)
												if position > 0:
																			__lowercase					:							Dict			=   get_parent_position(__a							)
																			__lowercase	,	__lowercase					:							List[Any]			=   self.heap[parent_position]
																			if parent_weight > weight:
																										self._bubble_up(__a							)
																			else:
																										self._bubble_down(__a							)
												else:
																			self._bubble_down(__a							)



					def 					lowerCAmelCase (     self :		Tuple						,   __a :		T							)	->     None:


												"""simple docstring"""

												__lowercase					:							Optional[int]			=   self.position_map[elem]
												if curr_pos == 0:
																			return None
												__lowercase					:							Any			=   get_parent_position(__a							)
												__lowercase	,	__lowercase					:							str			=   self.heap[curr_pos]
												__lowercase	,	__lowercase					:							List[str]			=   self.heap[parent_position]
												if parent_weight > weight:
																			self._swap_nodes(__a						,   __a							)
																			return self._bubble_up(__a							)
												return None



					def 					lowerCAmelCase (     self :		List[str]						,   __a :		T							)	->     None:


												"""simple docstring"""

												__lowercase					:							Union[str, Any]			=   self.position_map[elem]
												__lowercase	,	__lowercase					:							Dict			=   self.heap[curr_pos]
												__lowercase					:							Union[str, Any]			=   get_child_left_position(__a							)
												__lowercase					:							Any			=   get_child_right_position(__a							)
												if child_left_position < self.elements and child_right_position < self.elements:
																			__lowercase	,	__lowercase					:							List[str]			=   self.heap[child_left_position]
																			__lowercase	,	__lowercase					:							Tuple			=   self.heap[child_right_position]
																			if child_right_weight < child_left_weight and child_right_weight < weight:
																										self._swap_nodes(__a						,   __a							)
																										return self._bubble_down(__a							)
												if child_left_position < self.elements:
																			__lowercase	,	__lowercase					:							Optional[int]			=   self.heap[child_left_position]
																			if child_left_weight < weight:
																										self._swap_nodes(__a						,   __a							)
																										return self._bubble_down(__a							)
												else:
																			return None
												if child_right_position < self.elements:
																			__lowercase	,	__lowercase					:							List[Any]			=   self.heap[child_right_position]
																			if child_right_weight < weight:
																										self._swap_nodes(__a						,   __a							)
																										return self._bubble_down(__a							)
												return None



					def 					lowerCAmelCase (     self :		List[Any]						,   __a :		int						,   __a :		int							)	->     None:


												"""simple docstring"""

												__lowercase					:							Optional[Any]			=   self.heap[nodea_pos][0]
												__lowercase					:							Dict			=   self.heap[nodea_pos][0]
												__lowercase	,	__lowercase					:							List[str]			=   (
												    self.heap[nodea_pos],
												    self.heap[nodea_pos],
												)
												__lowercase					:							Any			=   nodea_pos
												__lowercase					:							int			=   nodea_pos







class 						lowerCAmelCase   (       Generic[T]	):

					'''simple docstring'''

					def __init__(     self :		List[str]							)	->     None:


												"""simple docstring"""

												__lowercase					:							dict[T, dict[T, int]]			=   {}
												__lowercase					:							int			=   0



					def __repr__(     self :		List[str]							)	->     str:


												"""simple docstring"""

												return str(self.connections							)



					def __len__(     self :		Union[str, Any]							)	->     int:


												"""simple docstring"""

												return self.nodes



					def 					lowerCAmelCase (     self :		Union[str, Any]						,   __a :		T							)	->     None:


												"""simple docstring"""

												if node not in self.connections:
																			__lowercase					:							List[str]			=   {}
																			self.nodes += 1



					def 					lowerCAmelCase (     self :		Dict						,   __a :		T						,   __a :		T						,   __a :		int							)	->     None:


												"""simple docstring"""

												self.add_node(__a							)
												self.add_node(__a							)
												__lowercase					:							int			=   weight
												__lowercase					:							Any			=   weight







def 					snake_case_						(   lowerCAmelCase_				:  GraphUndirectedWeighted[T]				,				):
							__lowercase					:							dict[T, int]			=   {node: maxsize for node in graph.connections}
							__lowercase					:							dict[T, T | None]			=   {node: None for node in graph.connections}

							__lowercase					:							MinPriorityQueue[T]			=   MinPriorityQueue()
							for node, weight in dist.items():
														priority_queue.push(lowerCAmelCase_				,				lowerCAmelCase_					)

							if priority_queue.is_empty():
														return dist, parent

							# initialization
							__lowercase					:							List[Any]			=   priority_queue.extract_min()
							__lowercase					:							List[Any]			=   0
							for neighbour in graph.connections[node]:
														if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
																					__lowercase					:							Dict			=   dist[node] + graph.connections[node][neighbour]
																					priority_queue.update_key(lowerCAmelCase_				,				dist[neighbour]					)
																					__lowercase					:							Tuple			=   node

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







lowerCamelCase       :       Optional[Any]        =				'''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''
def 					snake_case_						(   ):
							__lowercase					:							List[str]			=   input("""Enter message: """					)
							__lowercase					:							int			=   input("""Enter key [alphanumeric]: """					)
							__lowercase					:							Optional[Any]			=   input("""Encrypt/Decrypt [e/d]: """					)

							if mode.lower().startswith("""e"""					):
														__lowercase					:							Optional[int]			=   """encrypt"""
														__lowercase					:							Dict			=   encrypt_message(lowerCAmelCase_				,				lowerCAmelCase_					)
							elif mode.lower().startswith("""d"""					):
														__lowercase					:							Union[str, Any]			=   """decrypt"""
														__lowercase					:							Optional[int]			=   decrypt_message(lowerCAmelCase_				,				lowerCAmelCase_					)

							print(F"\n{mode.title()}ed message:"					)
							print(lowerCAmelCase_					)
def 					snake_case_						(   lowerCAmelCase_				:  str				,				lowerCAmelCase_				:  str					):
							return translate_message(lowerCAmelCase_				,				lowerCAmelCase_				,				"""encrypt"""					)
def 					snake_case_						(   lowerCAmelCase_				:  str				,				lowerCAmelCase_				:  str					):
							return translate_message(lowerCAmelCase_				,				lowerCAmelCase_				,				"""decrypt"""					)
def 					snake_case_						(   lowerCAmelCase_				:  str				,				lowerCAmelCase_				:  str				,				lowerCAmelCase_				:  str					):
							__lowercase					:							Union[str, Any]			=   []
							__lowercase					:							Tuple			=   0
							__lowercase					:							Dict			=   key.upper()

							for symbol in message:
														__lowercase					:							Optional[Any]			=   LETTERS.find(symbol.upper()					)
														if num != -1:
																					if mode == "encrypt":
																												num += LETTERS.find(key[key_index]					)
																					elif mode == "decrypt":
																												num -= LETTERS.find(key[key_index]					)

																					num %= len(lowerCAmelCase_					)

																					if symbol.isupper():
																												translated.append(LETTERS[num]					)
																					elif symbol.islower():
																												translated.append(LETTERS[num].lower()					)

																					key_index += 1
																					if key_index == len(lowerCAmelCase_					):
																												__lowercase					:							str			=   0
														else:
																					translated.append(lowerCAmelCase_					)
							return "".join(lowerCAmelCase_					)


if __name__ == "__main__":
	main()