

"""simple docstring"""


from __future__ import annotations

import string
from itertools import cycle, product
from pathlib import Path

__A						   =			(
    string.ascii_letters + string.digits + string.punctuation + string.whitespace
)
__A						   =			[ord(letter) for letter in string.ascii_lowercase]
__A						   =			{ord(char) for char in VALID_CHARS}

__A						   =			["the", "be", "to", "of", "and", "in", "that", "have"]






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	str | None:
		__lowerCAmelCase:       str          =			""
		__lowerCAmelCase:       int
		__lowerCAmelCase:       int
		__lowerCAmelCase:       int

		for keychar, cipherchar in zip(cycle(__SCREAMING_SNAKE_CASE )					, __SCREAMING_SNAKE_CASE ):
				__lowerCAmelCase:       Optional[Any]          =			cipherchar ^ keychar
				if decodedchar not in VALID_INTS:
						return None
				decoded += chr(__SCREAMING_SNAKE_CASE )

		return decoded






def     a__    (    __SCREAMING_SNAKE_CASE )	->	list[str]:
		__lowerCAmelCase:       list[str]          =			[]
		for key in product(__SCREAMING_SNAKE_CASE					, repeat=3 ):
				__lowerCAmelCase:       str          =			try_key(__SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )
				if encoded is not None:
						possibles.append(__SCREAMING_SNAKE_CASE )
		return possibles






def     a__    (    __SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )	->	list[str]:
		return [possible for possible in possibles if common_word in possible.lower()]






def     a__    (    __SCREAMING_SNAKE_CASE = "p059_cipher.txt" )	->	int:
		__lowerCAmelCase:       list[int]
		__lowerCAmelCase:       list[str]
		__lowerCAmelCase:       str
		__lowerCAmelCase:       str
		__lowerCAmelCase:       str          =			Path(__SCREAMING_SNAKE_CASE ).parent.joinpath(__SCREAMING_SNAKE_CASE ).read_text(encoding="utf-8" )

		__lowerCAmelCase:       Dict          =			[int(__SCREAMING_SNAKE_CASE ) for number in data.strip().split("," )]

		__lowerCAmelCase:       Tuple          =			filter_valid_chars(__SCREAMING_SNAKE_CASE )
		for common_word in COMMON_WORDS:
				__lowerCAmelCase:       int          =			filter_common_word(__SCREAMING_SNAKE_CASE					, __SCREAMING_SNAKE_CASE )
				if len(__SCREAMING_SNAKE_CASE ) == 1:
						break

		__lowerCAmelCase:       Dict          =			possibles[0]
		return sum(ord(__SCREAMING_SNAKE_CASE ) for char in decoded_text )


if __name__ == "__main__":
			print(F'''{solution() = }''')





"""simple docstring"""


from __future__ import annotations






def     a__    (    __SCREAMING_SNAKE_CASE )	->	bool:
		__lowerCAmelCase:       Tuple          =			str(__SCREAMING_SNAKE_CASE )
		return len(__SCREAMING_SNAKE_CASE ) == 9 and set(__SCREAMING_SNAKE_CASE ) == set("123456789" )






def     a__    (    )	->	int | None:
		for base_num in range(9_9_9_9					, 4_9_9_9					, -1 ):
				__lowerCAmelCase:       Tuple          =			1_0_0_0_0_2 * base_num
				if is_9_pandigital(__SCREAMING_SNAKE_CASE ):
						return candidate

		for base_num in range(3_3_3					, 9_9					, -1 ):
				__lowerCAmelCase:       int          =			1_0_0_2_0_0_3 * base_num
				if is_9_pandigital(__SCREAMING_SNAKE_CASE ):
						return candidate

		return None


if __name__ == "__main__":
			print(F'''{solution() = }''')


