





import json
import os
import re
import unicodedata
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
from ...utils import logging


_a									=				logging.get_logger(__name__)

_a									=				{
    "vocab_file": "vocab.json",
    "merges_file": "merges.txt",
}

_a									=				{
    "vocab_file": {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/vocab.json"},
    "merges_file": {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/merges.txt"},
}

_a									=				{
    "openai-gpt": 512,
}





def lowerCAmelCase__(__snake_case							)    ->				Any:







	'''simple docstring'''







	lowerCamelCase__        =		text.strip()
	if not text:
		return []
	lowerCamelCase__        =		text.split()
	return tokens






class  __A   (   lowerCAmelCase			):

			'''simple docstring'''







			def __init__(   self	,  __lowerCAmelCase=True	,  __lowerCAmelCase=None	,  __lowerCAmelCase=True	,  __lowerCAmelCase=None	,  __lowerCAmelCase=True	,  ):



				'''simple docstring'''







				if never_split is None:
					lowerCamelCase__        =		[]
				lowerCamelCase__        =		do_lower_case
				lowerCamelCase__        =		set(__lowerCAmelCase							)
				lowerCamelCase__        =		tokenize_chinese_chars
				lowerCamelCase__        =		strip_accents
				lowerCamelCase__        =		do_split_on_punc





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase	,  __lowerCAmelCase=None							):



				'''simple docstring'''







				lowerCamelCase__        =		self.never_split.union(set(__lowerCAmelCase							)							) if never_split else self.never_split
				lowerCamelCase__        =		self._clean_text(__lowerCAmelCase							)

				# This was added on November 1st, 2018 for the multilingual and Chinese
				# models. This is also applied to the English models now, but it doesn't
				# matter since the English models were not trained on any Chinese data
				# and generally don't have any Chinese data in them (there are Chinese
				# characters in the vocabulary because Wikipedia does have some Chinese
				# words in the English Wikipedia.).
				if self.tokenize_chinese_chars:
					lowerCamelCase__        =		self._tokenize_chinese_chars(__lowerCAmelCase							)
				# prevents treating the same character with different unicode codepoints as different characters
				lowerCamelCase__        =		unicodedata.normalize('''NFC'''	,  __lowerCAmelCase							)
				lowerCamelCase__        =		whitespace_tokenize(__lowerCAmelCase							)
				lowerCamelCase__        =		[]
				for token in orig_tokens:
					if token not in never_split:
						if self.do_lower_case:
							lowerCamelCase__        =		token.lower()
							if self.strip_accents is not False:
								lowerCamelCase__        =		self._run_strip_accents(__lowerCAmelCase							)
						elif self.strip_accents:
							lowerCamelCase__        =		self._run_strip_accents(__lowerCAmelCase							)
					split_tokens.extend(self._run_split_on_punc(__lowerCAmelCase	,  __lowerCAmelCase							)							)

				lowerCamelCase__        =		whitespace_tokenize(''' '''.join(__lowerCAmelCase							)							)
				return output_tokens





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		unicodedata.normalize('''NFD'''	,  __lowerCAmelCase							)
				lowerCamelCase__        =		[]
				for char in text:
					lowerCamelCase__        =		unicodedata.category(__lowerCAmelCase							)
					if cat == "Mn":
						continue
					output.append(__lowerCAmelCase							)
				return "".join(__lowerCAmelCase							)





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase	,  __lowerCAmelCase=None							):



				'''simple docstring'''







				if not self.do_split_on_punc or (never_split is not None and text in never_split):
					return [text]
				lowerCamelCase__        =		list(__lowerCAmelCase							)
				lowerCamelCase__        =		0
				lowerCamelCase__        =		True
				lowerCamelCase__        =		[]
				while i < len(__lowerCAmelCase							):
					lowerCamelCase__        =		chars[i]
					if _is_punctuation(__lowerCAmelCase							):
						output.append([char]							)
						lowerCamelCase__        =		True
					else:
						if start_new_word:
							output.append([]							)
						lowerCamelCase__        =		False
						output[-1].append(__lowerCAmelCase							)
					i += 1

				return ["".join(__lowerCAmelCase							) for x in output]





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		[]
				for char in text:
					lowerCamelCase__        =		ord(__lowerCAmelCase							)
					if self._is_chinese_char(__lowerCAmelCase							):
						output.append(''' '''							)
						output.append(__lowerCAmelCase							)
						output.append(''' '''							)
					else:
						output.append(__lowerCAmelCase							)
				return "".join(__lowerCAmelCase							)





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				if (
				    (cp >= 0x4_E_0_0 and cp <= 0x9_F_F_F)
				    or (cp >= 0x3_4_0_0 and cp <= 0x4_D_B_F)  #
				    or (cp >= 0x2_0_0_0_0 and cp <= 0x2_A_6_D_F)  #
				    or (cp >= 0x2_A_7_0_0 and cp <= 0x2_B_7_3_F)  #
				    or (cp >= 0x2_B_7_4_0 and cp <= 0x2_B_8_1_F)  #
				    or (cp >= 0x2_B_8_2_0 and cp <= 0x2_C_E_A_F)  #
				    or (cp >= 0xF_9_0_0 and cp <= 0xF_A_F_F)
				    or (cp >= 0x2_F_8_0_0 and cp <= 0x2_F_A_1_F)  #
				):  #
					return True

				return False





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		[]
				for char in text:
					lowerCamelCase__        =		ord(__lowerCAmelCase							)
					if cp == 0 or cp == 0xF_F_F_D or _is_control(__lowerCAmelCase							):
						continue
					if _is_whitespace(__lowerCAmelCase							):
						output.append(''' '''							)
					else:
						output.append(__lowerCAmelCase							)
				return "".join(__lowerCAmelCase							)





def lowerCAmelCase__(__snake_case							)    ->				Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__        =		set()
	lowerCamelCase__        =		word[0]
	for char in word[1:]:
		pairs.add((prev_char, char)							)
		lowerCamelCase__        =		char
	return pairs





def lowerCAmelCase__(__snake_case							)    ->				Dict:







	'''simple docstring'''







	lowerCamelCase__        =		text.replace('''—'''	,'''-'''							)
	lowerCamelCase__        =		text.replace('''–'''	,'''-'''							)
	lowerCamelCase__        =		text.replace('''―'''	,'''-'''							)
	lowerCamelCase__        =		text.replace('''…'''	,'''...'''							)
	lowerCamelCase__        =		text.replace('''´'''	,'''\''''							)
	lowerCamelCase__        =		re.sub(R'''(-+|~+|!+|"+|;+|\?+|\++|,+|\)+|\(+|\\+|\/+|\*+|\[+|\]+|}+|{+|\|+|_+)'''	,R''' \1 '''	,__snake_case							)
	lowerCamelCase__        =		re.sub(R'''\s*\n\s*'''	,''' \n '''	,__snake_case							)
	lowerCamelCase__        =		re.sub(R'''[^\S\n]+'''	,''' '''	,__snake_case							)
	return text.strip()






class  __A   (   lowerCAmelCase			):

			'''simple docstring'''







			lowerCAmelCase_												=						VOCAB_FILES_NAMES
			lowerCAmelCase_												=						PRETRAINED_VOCAB_FILES_MAP
			lowerCAmelCase_												=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			lowerCAmelCase_												=						["""input_ids""", """attention_mask"""]





			def __init__(   self	,  __lowerCAmelCase	,  __lowerCAmelCase	,  __lowerCAmelCase="<unk>"	,  **__lowerCAmelCase							):



				'''simple docstring'''







				super().__init__(unk_token=__lowerCAmelCase	,  **__lowerCAmelCase							)

				try:
					import ftfy
					from spacy.lang.en import English

					lowerCamelCase__        =		English()
					lowerCamelCase__        =		_nlp.tokenizer
					lowerCamelCase__        =		ftfy.fix_text
				except ImportError:
					logger.warning('''ftfy or spacy is not installed using BERT BasicTokenizer instead of SpaCy & ftfy.'''							)
					lowerCamelCase__        =		BasicTokenizer(do_lower_case=__lowerCAmelCase							)
					lowerCamelCase__        =		None

				with open(__lowerCAmelCase	,  encoding='''utf-8'''							) as vocab_handle:
					lowerCamelCase__        =		json.load(__lowerCAmelCase							)
				lowerCamelCase__        =		{v: k for k, v in self.encoder.items()}
				with open(__lowerCAmelCase	,  encoding='''utf-8'''							) as merges_handle:
					lowerCamelCase__        =		merges_handle.read().split('''\n'''							)[1:-1]
				lowerCamelCase__        =		[tuple(merge.split()							) for merge in merges]
				lowerCamelCase__        =		dict(zip(__lowerCAmelCase	,  range(len(__lowerCAmelCase							)							)							)							)
				lowerCamelCase__        =		{}





			@property
			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				return True





			@property
			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				return len(self.encoder							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







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





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		tuple(token[:-1]							) + (token[-1] + '''</w>''',)
				if token in self.cache:
					return self.cache[token]
				lowerCamelCase__        =		get_pairs(__lowerCAmelCase							)

				if not pairs:
					return token + "</w>"

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

						if word[i] == first and i < len(__lowerCAmelCase							) - 1 and word[i + 1] == second:
							new_word.append(first + second							)
							i += 2
						else:
							new_word.append(word[i]							)
							i += 1
					lowerCamelCase__        =		tuple(__lowerCAmelCase							)
					lowerCamelCase__        =		new_word
					if len(__lowerCAmelCase							) == 1:
						break
					else:
						lowerCamelCase__        =		get_pairs(__lowerCAmelCase							)
				lowerCamelCase__        =		''' '''.join(__lowerCAmelCase							)
				if word == "\n  </w>":
					lowerCamelCase__        =		'''\n</w>'''
				lowerCamelCase__        =		word
				return word





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		[]
				if self.fix_text is None:
					# Using BERT's BasicTokenizer
					lowerCamelCase__        =		self.nlp.tokenize(__lowerCAmelCase							)
					for token in text:
						split_tokens.extend(list(self.bpe(__lowerCAmelCase							).split(''' '''							)							)							)
				else:
					# Using SpaCy & ftfy (original tokenization process of OpenAI GPT)
					lowerCamelCase__        =		self.nlp(text_standardize(self.fix_text(__lowerCAmelCase							)							)							)
					for token in text:
						split_tokens.extend(list(self.bpe(token.text.lower()							).split(''' '''							)							)							)
				return split_tokens





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				return self.decoder.get(__lowerCAmelCase	,  self.unk_token							)





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__        =		''''''.join(__lowerCAmelCase							).replace('''</w>'''	,  ''' '''							).strip()
				return out_string





			def 		__lowerCamelCase    (   self	,  __lowerCAmelCase	,  __lowerCAmelCase = None							):



				'''simple docstring'''







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

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

				lowerCamelCase__        =		0
				with open(__lowerCAmelCase	,  '''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 __lowerCAmelCase							: 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(__lowerCAmelCase							) + '''\n'''							)
						index += 1

				return vocab_file, merge_file










import os





def lowerCAmelCase__()    ->				Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__        =		os.path.dirname(os.path.realpath(__snake_case							)							)
	lowerCamelCase__        =		os.path.join(__snake_case	,'''triangle.txt'''							)

	with open(__snake_case							) as f:
		lowerCamelCase__        =		f.readlines()

	lowerCamelCase__        =		[[int(__snake_case							) for y in x.rstrip('''\r\n'''							).split(''' '''							)] for x in triangle]

	for i in range(1	,len(__snake_case							)							):
		for j in range(len(a[i]							)							):
			lowerCamelCase__        =		a[i - 1][j] if j != len(a[i - 1]							) else 0
			lowerCamelCase__        =		a[i - 1][j - 1] if j > 0 else 0
			a[i][j] += max(__snake_case	,__snake_case							)
	return max(a[-1]							)


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



