






import random
import sys

__magic_name__:  Tuple  	=			"ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def 					UpperCamelCase		( ):






						"""simple docstring"""







						__magic_name__    :     Any     		=      input("""Enter message: """				)
						__magic_name__    :     Union[str, Any]     		=      """LFWOAYUISVKMNXPBDCRJTQEGHZ"""
						__magic_name__    :     Optional[int]     		=      input("""Encrypt/Decrypt [e/d]: """				)

						check_valid_key(_A				)

						if resp.lower().startswith("""e"""				):
												__magic_name__    :     Dict     		=      """encrypt"""
												__magic_name__    :     List[str]     		=      encrypt_message(_A,					_A				)
						elif resp.lower().startswith("""d"""				):
												__magic_name__    :     List[str]     		=      """decrypt"""
												__magic_name__    :     Optional[Any]     		=      decrypt_message(_A,					_A				)

						print(f'\n{mode.title()}ion: \n{translated}'				)

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						__magic_name__    :     Dict     		=      list(_A				)
						__magic_name__    :     Dict     		=      list(_A				)
						key_list.sort()
						letters_list.sort()

						if key_list != letters_list:
												sys.exit("""Error in the key or symbol set."""				)

def 					UpperCamelCase		( _A,					_A				):






						"""simple docstring"""







						return translate_message(_A,					_A,					"""encrypt"""				)

def 					UpperCamelCase		( _A,					_A				):






						"""simple docstring"""







						return translate_message(_A,					_A,					"""decrypt"""				)

def 					UpperCamelCase		( _A,					_A,					_A				):






						"""simple docstring"""







						__magic_name__    :     List[str]     		=      """"""
						__magic_name__    :     List[Any]     		=      LETTERS
						__magic_name__    :     Tuple     		=      key

						if mode == "decrypt":
												__magic_name__		,__magic_name__    :     List[str]     		=      chars_b, chars_a

						for symbol in message:
												if symbol.upper() in chars_a:
																		__magic_name__    :     Optional[int]     		=      chars_a.find(symbol.upper()				)
																		if symbol.isupper():
																								translated += chars_b[sym_index].upper()
																		else:
																								translated += chars_b[sym_index].lower()
												else:
																		translated += symbol

						return translated

def 					UpperCamelCase		( ):






						"""simple docstring"""







						__magic_name__    :     Dict     		=      list(_A				)
						random.shuffle(_A				)
						return "".join(_A				)


if __name__ == "__main__":
		main()








class  snake_case__      :
	def __init__(       self				)							->   None:
							# numbermap keys are the number and its values are lists of indexes sorted
							# in ascending order
							__magic_name__    :     dict[int, list[int]]     		=      {}
							# indexmap keys are an index and it's values are the number at that index
							__magic_name__    :     dict[int, int]     		=      {}
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   list[int]:
							if isinstance(lowerCAmelCase__    ,     (range, str)				):
													__magic_name__    :     int     		=      list(lowerCAmelCase__				)
							elif not isinstance(lowerCAmelCase__    ,     lowerCAmelCase__				):
													raise TypeError(
													    """binary_search_delete() only accepts either a list, range or str"""				)

							__magic_name__    :     str     		=      0
							__magic_name__    :     int     		=      len(lowerCAmelCase__				) - 1

							while low <= high:
													__magic_name__    :     List[str]     		=      (low + high) // 2
													if array[mid] == item:
																			array.pop(lowerCAmelCase__				)
																			return array
													elif array[mid] < item:
																			__magic_name__    :     Tuple     		=      mid + 1
													else:
																			__magic_name__    :     Dict     		=      mid - 1
							raise ValueError(
							    """Either the item is not in the array or the array was unsorted"""				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   list[int]:
							if isinstance(lowerCAmelCase__    ,     (range, str)				):
													__magic_name__    :     Tuple     		=      list(lowerCAmelCase__				)
							elif not isinstance(lowerCAmelCase__    ,     lowerCAmelCase__				):
													raise TypeError(
													    """binary_search_insert() only accepts either a list, range or str"""				)

							__magic_name__    :     List[str]     		=      0
							__magic_name__    :     Tuple     		=      len(lowerCAmelCase__				) - 1

							while low <= high:
													__magic_name__    :     Dict     		=      (low + high) // 2
													if array[mid] == index:
																			# If the item already exists in the array,
																			# insert it after the existing item
																			array.insert(mid + 1    ,     lowerCAmelCase__				)
																			return array
													elif array[mid] < index:
																			__magic_name__    :     int     		=      mid + 1
													else:
																			__magic_name__    :     Tuple     		=      mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
							array.insert(lowerCAmelCase__    ,     lowerCAmelCase__				)
							return array
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   None:
							# Remove previous index
							if index in self.indexmap:
													__magic_name__    :     int     		=      self.indexmap[index]
													if len(self.numbermap[n]				) == 1:
																			del self.numbermap[n]
													else:
																			__magic_name__    :     Union[str, Any]     		=      self.binary_search_delete(self.numbermap[n]    ,     lowerCAmelCase__				)

        # Set new index
							__magic_name__    :     List[Any]     		=      number

							# Number not seen before or empty so insert number value
							if number not in self.numbermap:
													__magic_name__    :     Any     		=      [index]

							# Here we need to perform a binary search insertion in order to insert
							# The item in the correct place
							else:
													__magic_name__    :     Optional[Any]     		=      self.binary_search_insert(
													    self.numbermap[number]    ,     lowerCAmelCase__				)







	def     __magic_name__       (       self    ,     lowerCAmelCase__				)							->   int:
							return self.numbermap.get(lowerCAmelCase__    ,     [-1]				)[0]


if __name__ == "__main__":
		import doctest

		doctest.testmod()
