



'''simple docstring'''
snake_case_					:      Union[str, Any]    			=    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'






def A__       (	):
						_UpperCamelCase   :						str												=  input('Enter message: '				)
						_UpperCamelCase   :						Union[str, Any]												=  input('Enter key [alphanumeric]: '				)
						_UpperCamelCase   :						int												=  input('Encrypt/Decrypt [e/d]: '				)

						if mode.lower().startswith('e'				):
												_UpperCamelCase   :						Tuple												=  'encrypt'
												_UpperCamelCase   :						Union[str, Any]												=  encrypt_message(UpperCAmelCase_    ,    UpperCAmelCase_				)
						elif mode.lower().startswith('d'				):
												_UpperCamelCase   :						List[Any]												=  'decrypt'
												_UpperCamelCase   :						Tuple												=  decrypt_message(UpperCAmelCase_    ,    UpperCAmelCase_				)

						print(f'\n{mode.title()}ed message:'				)
						print(UpperCAmelCase_				)






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return translate_message(UpperCAmelCase_    ,    UpperCAmelCase_    ,    'encrypt'				)






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return translate_message(UpperCAmelCase_    ,    UpperCAmelCase_    ,    'decrypt'				)






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_				):
						_UpperCamelCase   :						Optional[Any]												=  []
						_UpperCamelCase   :						Tuple												=  0
						_UpperCamelCase   :						Optional[Any]												=  key.upper()

						for symbol in message:
												_UpperCamelCase   :						Dict												=  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(UpperCAmelCase_				)

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

																		key_index += 1
																		if key_index == len(UpperCAmelCase_				):
																								_UpperCamelCase   :						Optional[Any]												=  0
												else:
																		translated.append(UpperCAmelCase_				)
						return "".join(UpperCAmelCase_				)


if __name__ == "__main__":
					main()







'''simple docstring'''
from __future__ import annotations






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						_UpperCamelCase							,     _UpperCamelCase   :						Dict												=  position
						_UpperCamelCase   :						Any												=  [
						    (y + 1, x + 2),
						    (y - 1, x + 2),
						    (y + 1, x - 2),
						    (y - 1, x - 2),
						    (y + 2, x + 1),
						    (y + 2, x - 1),
						    (y - 2, x + 1),
						    (y - 2, x - 1),
						]
						_UpperCamelCase   :						Optional[Any]												=  []

						for position in positions:
												_UpperCamelCase							,     _UpperCamelCase   :						Any												=  position
												if 0 <= y_test < n and 0 <= x_test < n:
																		permissible_positions.append(UpperCAmelCase_				)

						return permissible_positions






def A__       (	UpperCAmelCase_				):
						return not any(elem == 0 for row in board for elem in row				)






def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_    ,    UpperCAmelCase_				):

						if is_complete(UpperCAmelCase_				):
												return True

						for position in get_valid_pos(UpperCAmelCase_    ,    len(UpperCAmelCase_				)				):
												_UpperCamelCase							,     _UpperCamelCase   :						Any												=  position

												if board[y][x] == 0:
																		_UpperCamelCase   :						int												=  curr + 1
																		if open_knight_tour_helper(UpperCAmelCase_    ,    UpperCAmelCase_    ,    curr + 1				):
																								return True
																		_UpperCamelCase   :						Union[str, Any]												=  0

						return False






def A__       (	UpperCAmelCase_				):
						_UpperCamelCase   :						Dict												=  [[0 for i in range(UpperCAmelCase_				)] for j in range(UpperCAmelCase_				)]

						for i in range(UpperCAmelCase_				):
												for j in range(UpperCAmelCase_				):
																		_UpperCamelCase   :						Tuple												=  1
																		if open_knight_tour_helper(UpperCAmelCase_    ,    (i, j)    ,    1				):
																								return board
																		_UpperCamelCase   :						Union[str, Any]												=  0

						_UpperCamelCase   :						int												=  f'Open Kight Tour cannot be performed on a board of size {n}'
						raise ValueError(UpperCAmelCase_				)


if __name__ == "__main__":
					import doctest

					doctest.testmod()


