import random
import sys

from . import cryptomath_module as cryptomath

_lowerCamelCase    :      Union[str, Any]	 =						(
    r""" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"""
    r"""abcdefghijklmnopqrstuvwxyz{|}~"""
)





def 		__lowerCamelCase							(UpperCAmelCase__   :							Dict					,       UpperCAmelCase__   :							Tuple					,       UpperCAmelCase__   :							List[str]     ):



					if mode == "encrypt":
										if key_a == 1:
															sys.exit(
															    "The affine cipher becomes weak when key "
															    "A is set to 1. Choose different key"     )
										if key_b == 0:
															sys.exit(
															    "The affine cipher becomes weak when key "
															    "B is set to 0. Choose different key"     )
					if key_a < 0 or key_b < 0 or key_b > len(UpperCAmelCase__     ) - 1:
										sys.exit(
										    "Key A must be greater than 0 and key B must "
										    F"be between 0 and {len(UpperCAmelCase__     ) - 1}."     )
					if cryptomath.gcd(UpperCAmelCase__					,       len(UpperCAmelCase__     )     ) != 1:
										sys.exit(
										    F"Key A {key_a} and the symbol set size {len(UpperCAmelCase__     )} "
										    "are not relatively prime. Choose a different key."     )





def 		__lowerCamelCase							(UpperCAmelCase__   :							Union[str, Any]					,       UpperCAmelCase__   :							Dict     ):
					SCREAMING_SNAKE_CASE				=				divmod(UpperCAmelCase__					,       len(UpperCAmelCase__     )     )
					check_keys(UpperCAmelCase__					,       UpperCAmelCase__					,       "encrypt"     )
					SCREAMING_SNAKE_CASE				=				""
					for symbol in message:
										if symbol in SYMBOLS:
															SCREAMING_SNAKE_CASE				=				SYMBOLS.find(UpperCAmelCase__     )
															cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(UpperCAmelCase__     )]
										else:
															cipher_text += symbol
					return cipher_text





def 		__lowerCamelCase							(UpperCAmelCase__   :							Dict					,       UpperCAmelCase__   :							Optional[int]     ):
					SCREAMING_SNAKE_CASE				=				divmod(UpperCAmelCase__					,       len(UpperCAmelCase__     )     )
					check_keys(UpperCAmelCase__					,       UpperCAmelCase__					,       "decrypt"     )
					SCREAMING_SNAKE_CASE				=				""
					SCREAMING_SNAKE_CASE				=				cryptomath.find_mod_inverse(UpperCAmelCase__					,       len(UpperCAmelCase__     )     )
					for symbol in message:
										if symbol in SYMBOLS:
															SCREAMING_SNAKE_CASE				=				SYMBOLS.find(UpperCAmelCase__     )
															plain_text += SYMBOLS[
															    (sym_index - key_b) * mod_inverse_of_key_a % len(UpperCAmelCase__     )
															]
										else:
															plain_text += symbol
					return plain_text





def 		__lowerCamelCase							():



					while True:
										SCREAMING_SNAKE_CASE				=				random.randint(2					,       len(UpperCAmelCase__     )     )
										SCREAMING_SNAKE_CASE				=				random.randint(2					,       len(UpperCAmelCase__     )     )
										if cryptomath.gcd(UpperCAmelCase__					,       len(UpperCAmelCase__     )     ) == 1 and key_b % len(UpperCAmelCase__     ) != 0:
															return key_b * len(UpperCAmelCase__     ) + key_b





def 		__lowerCamelCase							():
					SCREAMING_SNAKE_CASE				=				input("Enter message: "     ).strip()
					SCREAMING_SNAKE_CASE				=				int(input("Enter key [2000 - 9000]: "     ).strip()     )
					SCREAMING_SNAKE_CASE				=				input("Encrypt/Decrypt [E/D]: "     ).strip().lower()

					if mode.startswith("e"     ):
										SCREAMING_SNAKE_CASE				=				"encrypt"
										SCREAMING_SNAKE_CASE				=				encrypt_message(UpperCAmelCase__					,       UpperCAmelCase__     )
					elif mode.startswith("d"     ):
										SCREAMING_SNAKE_CASE				=				"decrypt"
										SCREAMING_SNAKE_CASE				=				decrypt_message(UpperCAmelCase__					,       UpperCAmelCase__     )
					print(F"\n{mode.title()}ed text: \n{translated}"     )


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							# main()












"""simple docstring"""







def 						lowercase__(A = 1_000						)				->int:




						"""simple docstring"""



						lowercase__				:      Any=       [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
						# number of letters in twenty, thirty, ..., ninety (0 for numbers less than
						# 20 due to inconsistency in teens)
						lowercase__				:      List[str]=       [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

						lowercase__				:      Dict=       0

						for i in range(1					,		n + 1						):
												if i < 1_000:
																		if i >= 100:
																								# add number of letters for "n hundred"
																								count += ones_counts[i // 100] + 7

																								if i % 100 != 0:
																														# add number of letters for "and" if number is not multiple
																														# of 100
																														count += 3

																		if 0 < i % 100 < 20:
																								# add number of letters for one, two, three, ..., nineteen
																								# (could be combined with below if not for inconsistency in
																								# teens)
																								count += ones_counts[i % 100]
																		else:
																								# add number of letters for twenty, twenty one, ..., ninety
																								# nine
																								count += ones_counts[i % 10]
																								count += tens_counts[(i % 100 - i % 10) // 10]
												else:
																		count += ones_counts[i // 1_000] + 8
						return count


if __name__ == "__main__":
			print(solution(int(input().strip())))






