
'''simple docstring'''



import json
import os
from functools import lru_cache
from typing import TYPE_CHECKING, List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
						from transformers.pipelines.conversational import Conversation

_lowercase    =		logging.get_logger(__name__)


_lowercase    =		{
    "vocab_file": "vocab.json",
    "merges_file": "merges.txt",
    "tokenizer_config_file": "tokenizer_config.json",
}

_lowercase    =		{
    "vocab_file": {"facebook/blenderbot-3B": "https://huggingface.co/facebook/blenderbot-3B/resolve/main/vocab.json"},
    "merges_file": {"facebook/blenderbot-3B": "https://huggingface.co/facebook/blenderbot-3B/resolve/main/merges.txt"},
    "tokenizer_config_file": {
        "facebook/blenderbot-3B": "https://huggingface.co/facebook/blenderbot-3B/resolve/main/tokenizer_config.json"
    },
}

_lowercase    =		{"facebook/blenderbot-3B": 128}


@lru_cache()
# Copied from transformers.models.roberta.tokenization_roberta.bytes_to_unicode
def A				():
						_lowerCAmelCase  						=			(
						    list(range(ord("""!"""		)			,     ord("""~"""		) + 1		)		) + list(range(ord("""¡"""		)			,     ord("""¬"""		) + 1		)		) + list(range(ord("""®"""		)			,     ord("""ÿ"""		) + 1		)		)
						)
						_lowerCAmelCase  						=			bs[:]
						_lowerCAmelCase  						=			0
						for b in range(2**8		):
												if b not in bs:
																		bs.append(__lowerCamelCase		)
																		cs.append(2**8 + n		)
																		n += 1
						_lowerCAmelCase  						=			[chr(__lowerCamelCase		) for n in cs]
						return dict(zip(__lowerCamelCase			,     __lowerCamelCase		)		)


def A				(__lowerCamelCase				:Any		):
						_lowerCAmelCase  						=			set()
						_lowerCAmelCase  						=			word[0]
						for char in word[1:]:
												pairs.add((prev_char, char)		)
												_lowerCAmelCase  						=			char
						return pairs





class   UpperCAmelCase_					(		lowercase_			):






						'''simple docstring'''






						_lowercase		:				Union[str, Any]									=       VOCAB_FILES_NAMES
						_lowercase		:				int									=       PRETRAINED_VOCAB_FILES_MAP
						_lowercase		:				List[Any]									=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_lowercase		:				Union[str, Any]									=       ["input_ids", "attention_mask"]




						def __init__( self   ,       _lowercase   ,       _lowercase   ,       _lowercase="replace"   ,       _lowercase="<s>"   ,       _lowercase="</s>"   ,       _lowercase="</s>"   ,       _lowercase="<s>"   ,       _lowercase="<unk>"   ,       _lowercase="<pad>"   ,       _lowercase="<mask>"   ,       _lowercase=False   ,       **_lowercase   ,       ):

												"""simple docstring"""



												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else bos_token
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else eos_token
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else sep_token
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else cls_token
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else unk_token
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else pad_token

												# Mask token behave like a normal word, i.e. include the space before it
												_lowerCAmelCase  						=			AddedToken(a__   ,       lstrip=a__   ,       rstrip=a__				) if isinstance(a__   ,       a__				) else mask_token

												super().__init__(
												    errors=a__   ,       bos_token=a__   ,       eos_token=a__   ,       unk_token=a__   ,       sep_token=a__   ,       cls_token=a__   ,       pad_token=a__   ,       mask_token=a__   ,       add_prefix_space=a__   ,       **a__   ,       )

												with open(a__   ,       encoding="""utf-8"""				) as vocab_handle:
																		_lowerCAmelCase  						=			json.load(a__				)
												_lowerCAmelCase  						=			{v: k for k, v in self.encoder.items()}
												_lowerCAmelCase  						=			errors  # how to handle errors in decoding
												_lowerCAmelCase  						=			bytes_to_unicode()
												_lowerCAmelCase  						=			{v: k for k, v in self.byte_encoder.items()}
												with open(a__   ,       encoding="""utf-8"""				) as merges_handle:
																		_lowerCAmelCase  						=			merges_handle.read().split("""\n"""				)[1:-1]
												_lowerCAmelCase  						=			[tuple(merge.split()				) for merge in bpe_merges]
												_lowerCAmelCase  						=			dict(zip(a__   ,       range(len(a__				)				)				)				)
												_lowerCAmelCase  						=			{}
												_lowerCAmelCase  						=			add_prefix_space

												# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
												_lowerCAmelCase  						=			re.compile(R"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""				)




						@property
						# Copied from transformers.models.roberta.tokenization_roberta.RobertaTokenizer.vocab_size with Roberta->Blenderbot, RoBERTa->Blenderbot
						def  _lowercase     ( self				):

												"""simple docstring"""



												return len(self.encoder				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												return dict(self.encoder   ,       **self.added_tokens_encoder				)




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												if token in self.cache:
																		return self.cache[token]
												_lowerCAmelCase  						=			tuple(a__				)
												_lowerCAmelCase  						=			get_pairs(a__				)

												if not pairs:
																		return token

												while True:
																		_lowerCAmelCase  						=			min(a__   ,       key=lambda _lowercase				: self.bpe_ranks.get(a__   ,       float("""inf"""				)				)				)
																		if bigram not in self.bpe_ranks:
																								break
																		_lowerCAmelCase						,   _lowerCAmelCase  						=			bigram
																		_lowerCAmelCase  						=			[]
																		_lowerCAmelCase  						=			0
																		while i < len(a__				):
																								try:
																														_lowerCAmelCase  						=			word.index(a__   ,       a__				)
																								except ValueError:
																														new_word.extend(word[i:]				)
																														break
																								else:
																														new_word.extend(word[i:j]				)
																														_lowerCAmelCase  						=			j

																								if word[i] == first and i < len(a__				) - 1 and word[i + 1] == second:
																														new_word.append(first + second				)
																														i += 2
																								else:
																														new_word.append(word[i]				)
																														i += 1
																		_lowerCAmelCase  						=			tuple(a__				)
																		_lowerCAmelCase  						=			new_word
																		if len(a__				) == 1:
																								break
																		else:
																								_lowerCAmelCase  						=			get_pairs(a__				)
												_lowerCAmelCase  						=			""" """.join(a__				)
												_lowerCAmelCase  						=			word
												return word




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			[]
												for token in re.findall(self.pat   ,       a__				):
																		_lowerCAmelCase  						=			"""""".join(
																		    self.byte_encoder[b] for b in token.encode("""utf-8"""				)				)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
																		bpe_tokens.extend(bpe_token for bpe_token in self.bpe(a__				).split(""" """				)				)
												return bpe_tokens




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												return self.encoder.get(a__   ,       self.encoder.get(self.unk_token				)				)




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												return self.decoder.get(a__				)




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			"""""".join(a__				)
												_lowerCAmelCase  						=			bytearray([self.byte_decoder[c] for c in text]				).decode("""utf-8"""   ,       errors=self.errors				)
												return text




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = None				):

												"""simple docstring"""



												if not os.path.isdir(a__				):
																		logger.error(F'Vocabulary path ({save_directory}) should be a directory'				)
																		return
												_lowerCAmelCase  						=			os.path.join(
												    a__   ,       (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]				)
												_lowerCAmelCase  						=			os.path.join(
												    a__   ,       (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]				)

												with open(a__   ,       """w"""   ,       encoding="""utf-8"""				) as f:
																		f.write(json.dumps(self.encoder   ,       indent=2   ,       sort_keys=a__   ,       ensure_ascii=a__				) + """\n"""				)

												_lowerCAmelCase  						=			0
												with open(a__   ,       """w"""   ,       encoding="""utf-8"""				) as writer:
																		writer.write("""#version: 0.2\n"""				)
																		for bpe_tokens, token_index in sorted(self.bpe_ranks.items()   ,       key=lambda _lowercase				: kv[1]				):
																								if index != token_index:
																														logger.warning(
																														    F'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
																														    """ Please check that the tokenizer is not corrupted!"""				)
																														_lowerCAmelCase  						=			token_index
																								writer.write(""" """.join(a__				) + """\n"""				)
																								index += 1

												return vocab_file, merge_file




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = None   ,       _lowercase = False				):

												"""simple docstring"""



												if already_has_special_tokens:
																		return super().get_special_tokens_mask(
																		    token_ids_a=a__   ,       token_ids_a=a__   ,       already_has_special_tokens=a__				)

												if token_ids_a is None:
																		return [1] + ([0] * len(a__				)) + [1]
												return [1] + ([0] * len(a__				)) + [1, 1] + ([0] * len(a__				)) + [1]




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = None				):

												"""simple docstring"""



												_lowerCAmelCase  						=			[self.sep_token_id]
												_lowerCAmelCase  						=			[self.cls_token_id]

												if token_ids_a is None:
																		return len(cls + token_ids_a + sep				) * [0]
												return len(cls + token_ids_a + sep + sep + token_ids_a + sep				) * [0]




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase=False   ,       **_lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			kwargs.pop("""add_prefix_space"""   ,       self.add_prefix_space				)
												if (is_split_into_words or add_prefix_space) and (len(a__				) > 0 and not text[0].isspace()):
																		_lowerCAmelCase  						=			""" """ + text
												return (text, kwargs)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase = None				):

												"""simple docstring"""



												return token_ids_a + [self.eos_token_id]




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			[]
												for is_user, text in conversation.iter_texts():
																		if is_user:
																								# We need to space prefix as it's being done within blenderbot
																								inputs.append(""" """ + text				)
																		else:
																								# Generated responses should contain them already.
																								inputs.append(a__				)

												_lowerCAmelCase  						=			"""  """.join(a__				)
												_lowerCAmelCase  						=			self.encode(a__				)
												if len(a__				) > self.model_max_length:
																		_lowerCAmelCase  						=			input_ids[-self.model_max_length :]
																		logger.warning(F'Trimmed input from conversation as it was longer than {self.model_max_length} tokens.'				)
												return input_ids


'''simple docstring'''



import os


def A				():
						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())
