
"""simple docstring"""
from __future__ import annotations

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

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

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

def  lowercase     (_lowerCAmelCase ,    _lowerCAmelCase						):
						__lowerCAmelCase     =  ""
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  42

						for keychar, cipherchar in zip(cycle(_lowerCAmelCase						) ,    _lowerCAmelCase						):
												__lowerCAmelCase     =  cipherchar ^ keychar
												if decodedchar not in VALID_INTS:
																		return None
												decoded += chr(_lowerCAmelCase						)

						return decoded

def  lowercase     (_lowerCAmelCase						):
						__lowerCAmelCase     =  []
						for key in product(_lowerCAmelCase ,    repeat=3						):
												__lowerCAmelCase     =  try_key(_lowerCAmelCase ,    _lowerCAmelCase						)
												if encoded is not None:
																		possibles.append(_lowerCAmelCase						)
						return possibles

def  lowercase     (_lowerCAmelCase ,    _lowerCAmelCase						):
						return [possible for possible in possibles if common_word in possible.lower()]

def  lowercase     (_lowerCAmelCase = "p059_cipher.txt"						):
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  42
						__lowerCAmelCase     =  Path(_lowerCAmelCase						).parent.joinpath(_lowerCAmelCase						).read_text(encoding="""utf-8"""						)

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

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

						__lowerCAmelCase     =  possibles[0]
						return sum(ord(_lowerCAmelCase						) for char in decoded_text						)


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


"""simple docstring"""
import os

def  lowercase     ():
						with open(os.path.dirname(_lowerCAmelCase						) + """/grid.txt"""						) as f:
												__lowerCAmelCase     =  []  # noqa: E741
												for _ in range(20						):
																		l.append([int(_lowerCAmelCase						) for x in f.readline().split()]						)

												__lowerCAmelCase     =  0

												# right
												for i in range(20						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # down
												for i in range(17						):
																		for j in range(20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 1
												for i in range(17						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 2
												for i in range(17						):
																		for j in range(3 ,    20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp
												return maximum


if __name__ == "__main__":
			print(solution())
