


'''simple docstring'''






from math import pow





def lowerCamelCase__     (		__lowerCamelCase			:				int			,       __lowerCamelCase			:				int			,       __lowerCamelCase			:				int			,       __lowerCamelCase			:				int			,       __lowerCamelCase			:				int			,       ):







   '''simple docstring'''




   if current_sum == needed_sum:
      # If the sum of the powers is equal to needed_sum, then we have a solution.
      solutions_count += 1
      return current_sum, solutions_count

   _UpperCAmelCase  :  List[Any]				       =int(pow(__lowerCamelCase			,       __lowerCamelCase				)				)
   if current_sum + i_to_n <= needed_sum:
      # If the sum of the powers is less than needed_sum, then continue adding powers.
      current_sum += i_to_n
      _UpperCAmelCase       ,			_UpperCAmelCase  :  Union[str, Any]				       =backtrack(
          __lowerCamelCase			,       __lowerCamelCase			,       current_number + 1			,       __lowerCamelCase			,       __lowerCamelCase				)
      current_sum -= i_to_n
   if i_to_n < needed_sum:
      # If the power of i is less than needed_sum, then try with the next power.
      _UpperCAmelCase       ,			_UpperCAmelCase  :  List[Any]				       =backtrack(
          __lowerCamelCase			,       __lowerCamelCase			,       current_number + 1			,       __lowerCamelCase			,       __lowerCamelCase				)
   return current_sum, solutions_count





def lowerCamelCase__     (		__lowerCamelCase			:				int			,       __lowerCamelCase			:				int				):







   '''simple docstring'''




   if not (1 <= needed_sum <= 1_0_0_0 and 2 <= power <= 1_0):
      raise ValueError(
          'Invalid input\n'
          'needed_sum must be between 1 and 1000, power between 2 and 10.'				)

   return backtrack(__lowerCamelCase			,       __lowerCamelCase			,       1			,       0			,       0				)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()





'''simple docstring'''






def lowerCamelCase__     (		__lowerCamelCase			:				str				):







   '''simple docstring'''




   _UpperCAmelCase  :  Dict				       =''
   for ch in key:
      if ch == " " or ch not in key_no_dups and ch.isalpha():
         key_no_dups += ch
   return key_no_dups





def lowerCamelCase__     (		__lowerCamelCase			:				str				):







   '''simple docstring'''




   _UpperCAmelCase  :  List[str]				       =[chr(i + 6_5				) for i in range(2_6				)]
   # Remove duplicate characters from key
   _UpperCAmelCase  :  Any				       =remove_duplicates(key.upper()				)
   _UpperCAmelCase  :  Optional[Any]				       =len(__lowerCamelCase				)
   # First fill cipher with key characters
   _UpperCAmelCase  :  List[Any]				       ={alphabet[i]: char for i, char in enumerate(__lowerCamelCase				)}
   # Then map remaining characters in alphabet to
   # the alphabet from the beginning
   for i in range(len(__lowerCamelCase				)			,       2_6				):
      _UpperCAmelCase  :  Union[str, Any]				       =alphabet[i - offset]
      # Ensure we are not mapping letters to letters previously mapped
      while char in key:
         offset -= 1
         _UpperCAmelCase  :  str				       =alphabet[i - offset]
      _UpperCAmelCase  :  Any				       =char
   return cipher_alphabet





def lowerCamelCase__     (		__lowerCamelCase			:				str			,       __lowerCamelCase			:				dict[str, str]				):







   '''simple docstring'''




   return "".join(cipher_map.get(__lowerCamelCase			,       __lowerCamelCase				) for ch in message.upper()				)





def lowerCamelCase__     (		__lowerCamelCase			:				str			,       __lowerCamelCase			:				dict[str, str]				):







   '''simple docstring'''




   _UpperCAmelCase  :  List[str]				       ={v: k for k, v in cipher_map.items()}
   return "".join(rev_cipher_map.get(__lowerCamelCase			,       __lowerCamelCase				) for ch in message.upper()				)





def lowerCamelCase__     (		):







   '''simple docstring'''




   _UpperCAmelCase  :  Union[str, Any]				       =input('Enter message to encode or decode: '				).strip()
   _UpperCAmelCase  :  int				       =input('Enter keyword: '				).strip()
   _UpperCAmelCase  :  int				       =input('Encipher or decipher? E/D:'				).strip()[0].lower()
   try:
      _UpperCAmelCase  :  Tuple				       ={'e': encipher, 'd': decipher}[option]
   except KeyError:
      raise KeyError('invalid input option'				)
   _UpperCAmelCase  :  List[str]				       =create_cipher_map(__lowerCamelCase				)
   print(func(__lowerCamelCase			,       __lowerCamelCase				)				)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()

