

import random
import sys

from . import cryptomath_module as cryptomath

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







def _a					(			SCREAMING_SNAKE_CASE						:     int       ,   SCREAMING_SNAKE_CASE						:     int       ,   SCREAMING_SNAKE_CASE						:     str						)       ->       None:

 """simple docstring"""






 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(SCREAMING_SNAKE_CASE						) - 1:
  sys.exit(
      'Key A must be greater than 0 and key B must '
      f'''be between 0 and {len(SCREAMING_SNAKE_CASE						) - 1}.'''						)
 if cryptomath.gcd(SCREAMING_SNAKE_CASE       ,   len(SCREAMING_SNAKE_CASE						)						) != 1:
  sys.exit(
      f'''Key A {key_a} and the symbol set size {len(SCREAMING_SNAKE_CASE						)} '''
      'are not relatively prime. Choose a different key.'						)







def _a					(			SCREAMING_SNAKE_CASE						:     int       ,   SCREAMING_SNAKE_CASE						:     str						)       ->       str:

 """simple docstring"""






 __lowerCAmelCase      ,				__lowerCAmelCase:  Tuple        = divmod(SCREAMING_SNAKE_CASE       ,   len(SCREAMING_SNAKE_CASE						)						)
 check_keys(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   'encrypt'						)
 __lowerCAmelCase:  Any        = ''
 for symbol in message:
  if symbol in SYMBOLS:
   __lowerCAmelCase:  List[Any]        = SYMBOLS.find(SCREAMING_SNAKE_CASE						)
   cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(SCREAMING_SNAKE_CASE						)]
  else:
   cipher_text += symbol
 return cipher_text







def _a					(			SCREAMING_SNAKE_CASE						:     int       ,   SCREAMING_SNAKE_CASE						:     str						)       ->       str:

 """simple docstring"""






 __lowerCAmelCase      ,				__lowerCAmelCase:  Tuple        = divmod(SCREAMING_SNAKE_CASE       ,   len(SCREAMING_SNAKE_CASE						)						)
 check_keys(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   'decrypt'						)
 __lowerCAmelCase:  Dict        = ''
 __lowerCAmelCase:  Union[str, Any]        = cryptomath.find_mod_inverse(SCREAMING_SNAKE_CASE       ,   len(SCREAMING_SNAKE_CASE						)						)
 for symbol in message:
  if symbol in SYMBOLS:
   __lowerCAmelCase:  Optional[Any]        = SYMBOLS.find(SCREAMING_SNAKE_CASE						)
   plain_text += SYMBOLS[
       (sym_index - key_b) * mod_inverse_of_key_a % len(SCREAMING_SNAKE_CASE						)
   ]
  else:
   plain_text += symbol
 return plain_text







def _a					(			)       ->       int:

 """simple docstring"""






 while True:
  __lowerCAmelCase:  str        = random.randint(2       ,   len(SCREAMING_SNAKE_CASE						)						)
  __lowerCAmelCase:  Optional[int]        = random.randint(2       ,   len(SCREAMING_SNAKE_CASE						)						)
  if cryptomath.gcd(SCREAMING_SNAKE_CASE       ,   len(SCREAMING_SNAKE_CASE						)						) == 1 and key_b % len(SCREAMING_SNAKE_CASE						) != 0:
   return key_b * len(SCREAMING_SNAKE_CASE						) + key_b







def _a					(			)       ->       None:

 """simple docstring"""






 __lowerCAmelCase:  Union[str, Any]        = input('Enter message: '						).strip()
 __lowerCAmelCase:  List[str]        = int(input('Enter key [2000 - 9000]: '						).strip()						)
 __lowerCAmelCase:  Tuple        = input('Encrypt/Decrypt [E/D]: '						).strip().lower()

 if mode.startswith('e'						):
  __lowerCAmelCase:  Dict        = 'encrypt'
  __lowerCAmelCase:  Optional[Any]        = encrypt_message(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE						)
 elif mode.startswith('d'						):
  __lowerCAmelCase:  Union[str, Any]        = 'decrypt'
  __lowerCAmelCase:  Optional[int]        = decrypt_message(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE						)
 print(f'''\n{mode.title()}ed text: \n{translated}'''						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  # main()








def _a					(			SCREAMING_SNAKE_CASE						:     int = 10_00						)       ->       int:

 """simple docstring"""






 __lowerCAmelCase:  Tuple        = [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)
 __lowerCAmelCase:  List[Any]        = [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

 __lowerCAmelCase:  Dict        = 0

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

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

   if 0 < i % 1_00 < 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 % 1_00]
   else:
    # add number of letters for twenty, twenty one, ..., ninety
    # nine
    count += ones_counts[i % 10]
    count += tens_counts[(i % 1_00 - i % 10) // 10]
  else:
   count += ones_counts[i // 10_00] + 8
 return count


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





