

'''simple docstring'''
import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

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


lowerCamelCase			:				Tuple 			=					logging.get_logger(__name__)

lowerCamelCase			:				Optional[int] 			=					"▁"

lowerCamelCase			:				Optional[int] 			=					{
    "vocab_file": "vocab.json",
    "spm_file": "sentencepiece.bpe.model",
    "tokenizer_config_file": "tokenizer_config.json",
}

lowerCamelCase			:				Any 			=					{
    "vocab_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/vocab.json",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/vocab.json",
    },
    "spm_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/sentencepiece.bpe.model",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/sentencepiece.bpe.model",
    },
    "tokenizer_config_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/tokenizer_config.json",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/tokenizer_config.json",
    },
}

lowerCamelCase			:				Dict 			=					{
    "facebook/m2m100_418M": 1_0_2_4,
}

# fmt: off
lowerCamelCase			:				str 			=					{
    "m2m100": ["af", "am", "ar", "ast", "az", "ba", "be", "bg", "bn", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "en", "es", "et", "fa", "ff", "fi", "fr", "fy", "ga", "gd", "gl", "gu", "ha", "he", "hi", "hr", "ht", "hu", "hy", "id", "ig", "ilo", "is", "it", "ja", "jv", "ka", "kk", "km", "kn", "ko", "lb", "lg", "ln", "lo", "lt", "lv", "mg", "mk", "ml", "mn", "mr", "ms", "my", "ne", "nl", "no", "ns", "oc", "or", "pa", "pl", "ps", "pt", "ro", "ru", "sd", "si", "sk", "sl", "so", "sq", "sr", "ss", "su", "sv", "sw", "ta", "th", "tl", "tn", "tr", "uk", "ur", "uz", "vi", "wo", "xh", "yi", "yo", "zh", "zu"],
    "wmt21": ["en", "ha", "is", "ja", "cs", "ru", "zh", "de"]
}







class 							A__   (	A__  ):
  A__					=    VOCAB_FILES_NAMES
  A__					=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  A__					=    PRETRAINED_VOCAB_FILES_MAP
  A__					=    ['input_ids', 'attention_mask']

  A__					=    []
  A__					=    []





  def __init__(		self				:     Optional[int]							, _a				:     Dict							, _a				:     List[str]							, _a				:     str=None							, _a				:     List[str]=None							, _a				:     Union[str, Any]="<s>"							, _a				:     Dict="</s>"							, _a				:     int="</s>"							, _a				:     List[str]="<pad>"							, _a				:     Optional[Any]="<unk>"							, _a				:     Tuple="m2m100"							, _a				:     Optional[Dict[str, Any]] = None							, _a				:     Dict=8							, **_a				:     int							, )     ->   None:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   ={} if sp_model_kwargs is None else sp_model_kwargs

       _SCREAMING_SNAKE_CASE							   =language_codes
       _SCREAMING_SNAKE_CASE							   =FAIRSEQ_LANGUAGE_CODES[language_codes]
       _SCREAMING_SNAKE_CASE							   ={lang_code: f"__{lang_code}__" for lang_code in fairseq_language_code}

       _SCREAMING_SNAKE_CASE							   =kwargs.get('additional_special_tokens'							, []			)
       kwargs["additional_special_tokens"] += [
           self.get_lang_token(_a			)
           for lang_code in fairseq_language_code
           if self.get_lang_token(_a			) not in kwargs["additional_special_tokens"]
       ]

       super().__init__(
           src_lang=_a							, tgt_lang=_a							, bos_token=_a							, eos_token=_a							, sep_token=_a							, unk_token=_a							, pad_token=_a							, language_codes=_a							, sp_model_kwargs=self.sp_model_kwargs							, num_madeup_words=_a							, **_a							, )

       _SCREAMING_SNAKE_CASE							   =vocab_file
       _SCREAMING_SNAKE_CASE							   =load_json(_a			)
       _SCREAMING_SNAKE_CASE							   ={v: k for k, v in self.encoder.items()}
       _SCREAMING_SNAKE_CASE							   =spm_file
       _SCREAMING_SNAKE_CASE							   =load_spm(_a							, self.sp_model_kwargs			)

       _SCREAMING_SNAKE_CASE							   =len(self.encoder			)

       _SCREAMING_SNAKE_CASE							   ={
           self.get_lang_token(_a			): self.encoder_size + i for i, lang_code in enumerate(_a			)
       }
       _SCREAMING_SNAKE_CASE							   ={lang_code: self.encoder_size + i for i, lang_code in enumerate(_a			)}
       _SCREAMING_SNAKE_CASE							   ={v: k for k, v in self.lang_token_to_id.items()}

       _SCREAMING_SNAKE_CASE							   =src_lang if src_lang is not None else 'en'
       _SCREAMING_SNAKE_CASE							   =tgt_lang
       _SCREAMING_SNAKE_CASE							   =self.get_lang_id(self._src_lang			)
       self.set_src_lang_special_tokens(self._src_lang			)

       _SCREAMING_SNAKE_CASE							   =num_madeup_words





  @property
  def 						A  (		self				:     List[Any]			)     ->   int:





       '''simple docstring'''






       return len(self.encoder			) + len(self.lang_token_to_id			)





  @property
  def 						A  (		self				:     int			)     ->   str:





       '''simple docstring'''






       return self._src_lang





  @src_lang.setter
  def 						A  (		self				:     List[Any]							, _a				:     str			)     ->   None:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =new_src_lang
       self.set_src_lang_special_tokens(self._src_lang			)





  def 						A  (		self				:     Optional[int]							, _a				:     str			)     ->   List[str]:





       '''simple docstring'''






       return self.sp_model.encode(_a							, out_type=_a			)





  def 						A  (		self				:     Optional[int]							, _a				:     Dict			)     ->   Optional[Any]:





       '''simple docstring'''






       if token in self.lang_token_to_id:
            return self.lang_token_to_id[token]
       return self.encoder.get(_a							, self.encoder[self.unk_token]			)





  def 						A  (		self				:     Dict							, _a				:     int			)     ->   str:





       '''simple docstring'''






       if index in self.id_to_lang_token:
            return self.id_to_lang_token[index]
       return self.decoder.get(_a							, self.unk_token			)





  def 						A  (		self				:     Union[str, Any]							, _a				:     Union[str, Any]			)     ->   Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =[]
       _SCREAMING_SNAKE_CASE							   =''
       for token in tokens:
            # make sure that special tokens are not decoded using sentencepiece model
            if token in self.all_special_tokens:
                 out_string += self.sp_model.decode(_a			) + token
                 _SCREAMING_SNAKE_CASE							   =[]
            else:
                 current_sub_tokens.append(_a			)
       out_string += self.sp_model.decode(_a			)
       return out_string.strip()





  def 						A  (		self				:     List[Any]							, _a				:     List[int]							, _a				:     Optional[List[int]] = None							, _a				:     bool = False			)     ->   List[int]:





       '''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			)

       _SCREAMING_SNAKE_CASE							   =[1] * len(self.prefix_tokens			)
       _SCREAMING_SNAKE_CASE							   =[1] * len(self.suffix_tokens			)
       if token_ids_a is None:
            return prefix_ones + ([0] * len(_a			)) + suffix_ones
       return prefix_ones + ([0] * len(_a			)) + ([0] * len(_a			)) + suffix_ones





  def 						A  (		self				:     Optional[int]							, _a				:     List[int]							, _a				:     Optional[List[int]] = None			)     ->   List[int]:





       '''simple docstring'''






       if token_ids_a is None:
            return self.prefix_tokens + token_ids_a + self.suffix_tokens
       # We don't expect to process pairs, but leave the pair logic for API consistency
       return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens





  def 						A  (		self				:     Optional[Any]			)     ->   Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   ={self.convert_ids_to_tokens(_a			): i for i in range(self.vocab_size			)}
       vocab.update(self.added_tokens_encoder			)
       return vocab





  def __getstate__(		self				:     Optional[Any]			)     ->   Dict:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.__dict__.copy()
       _SCREAMING_SNAKE_CASE							   =None
       return state





  def __setstate__(		self				:     List[str]							, _a				:     Dict			)     ->   None:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =d

       # for backward compatibility
       if not hasattr(self							, 'sp_model_kwargs'			):
            _SCREAMING_SNAKE_CASE							   ={}

       _SCREAMING_SNAKE_CASE							   =load_spm(self.spm_file							, self.sp_model_kwargs			)





  def 						A  (		self				:     int							, _a				:     str							, _a				:     Optional[str] = None			)     ->   Tuple[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =Path(_a			)
       if not save_dir.is_dir():
            raise OSError(f"{save_directory} should be a directory"			)
       _SCREAMING_SNAKE_CASE							   =save_dir / (
           (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['vocab_file']
       )
       _SCREAMING_SNAKE_CASE							   =save_dir / (
           (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['spm_file']
       )

       save_json(self.encoder							, _a			)

       if os.path.abspath(self.spm_file			) != os.path.abspath(_a			) and os.path.isfile(self.spm_file			):
            copyfile(self.spm_file							, _a			)
       elif not os.path.isfile(self.spm_file			):
            with open(_a							, 'wb'			) as fi:
                 _SCREAMING_SNAKE_CASE							   =self.sp_model.serialized_model_proto()
                 fi.write(_a			)

       return (str(_a			), str(_a			))





  def 						A  (		self				:     List[Any]							, _a				:     List[str]							, _a				:     str = "en"							, _a				:     Optional[List[str]] = None							, _a				:     str = "ro"							, **_a				:     Optional[Any]							, )     ->   BatchEncoding:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =src_lang
       _SCREAMING_SNAKE_CASE							   =tgt_lang
       self.set_src_lang_special_tokens(self.src_lang			)
       return super().prepare_seqaseq_batch(_a							, _a							, **_a			)





  def 						A  (		self				:     List[Any]							, _a				:     Union[str, Any]							, _a				:     Optional[str]							, _a				:     Optional[str]							, **_a				:     List[Any]			)     ->   Optional[int]:





       '''simple docstring'''






       if src_lang is None or tgt_lang is None:
            raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'			)
       _SCREAMING_SNAKE_CASE							   =src_lang
       _SCREAMING_SNAKE_CASE							   =self(_a							, add_special_tokens=_a							, **_a			)
       _SCREAMING_SNAKE_CASE							   =self.get_lang_id(_a			)
       _SCREAMING_SNAKE_CASE							   =tgt_lang_id
       return inputs





  def 						A  (		self				:     Dict			)     ->   Tuple:





       '''simple docstring'''






       self.set_src_lang_special_tokens(self.src_lang			)





  def 						A  (		self				:     Optional[int]			)     ->   List[str]:





       '''simple docstring'''






       self.set_tgt_lang_special_tokens(self.tgt_lang			)





  def 						A  (		self				:     List[Any]							, _a				:     str			)     ->   None:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.get_lang_token(_a			)
       _SCREAMING_SNAKE_CASE							   =self.lang_token_to_id[lang_token]
       _SCREAMING_SNAKE_CASE							   =[self.cur_lang_id]
       _SCREAMING_SNAKE_CASE							   =[self.eos_token_id]





  def 						A  (		self				:     str							, _a				:     str			)     ->   None:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.get_lang_token(_a			)
       _SCREAMING_SNAKE_CASE							   =self.lang_token_to_id[lang_token]
       _SCREAMING_SNAKE_CASE							   =[self.cur_lang_id]
       _SCREAMING_SNAKE_CASE							   =[self.eos_token_id]





  def 						A  (		self				:     Optional[Any]							, _a				:     str			)     ->   str:





       '''simple docstring'''






       return self.lang_code_to_token[lang]





  def 						A  (		self				:     Tuple							, _a				:     str			)     ->   int:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =self.get_lang_token(_a			)
       return self.lang_token_to_id[lang_token]


def 	_lowerCAmelCase (						_UpperCamelCase						:					str							,			_UpperCamelCase						:					Dict[str, Any]    )				->      sentencepiece.SentencePieceProcessor:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   =sentencepiece.SentencePieceProcessor(**_UpperCamelCase    )
     spm.Load(str(_UpperCamelCase    )    )
     return spm


def 	_lowerCAmelCase (						_UpperCamelCase						:					str    )				->      Union[Dict, List]:
     """simple docstring"""




     with open(_UpperCamelCase							,			'r'    ) as f:
          return json.load(_UpperCamelCase    )







def 	_lowerCAmelCase (						_UpperCamelCase						:					Dict							,			_UpperCamelCase						:					str    )				->      None:
     """simple docstring"""




     with open(_UpperCamelCase							,			'w'    ) as f:
          json.dump(_UpperCamelCase							,			_UpperCamelCase							,			indent=2    )



'''simple docstring'''
import os


def 	_lowerCAmelCase (						)				->      List[str]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							   =os.path.dirname(os.path.realpath(_UpperCamelCase    )    )
     _SCREAMING_SNAKE_CASE							   =os.path.join(_UpperCamelCase							,			'triangle.txt'    )

     with open(_UpperCamelCase    ) as f:
          _SCREAMING_SNAKE_CASE							   =f.readlines()

     _SCREAMING_SNAKE_CASE							   =[]
     for line in triangle:
          _SCREAMING_SNAKE_CASE							   =[]
          for number in line.strip().split(' '    ):
               numbers_from_line.append(int(_UpperCamelCase    )    )
          a.append(_UpperCamelCase    )

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


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