

import json
import os
import re
import warnings
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_lowerCamelCase							=logging.get_logger(__name__)

_lowerCamelCase							={
    "source_spm": "source.spm",
    "target_spm": "target.spm",
    "vocab": "vocab.json",
    "target_vocab_file": "target_vocab.json",
    "tokenizer_config_file": "tokenizer_config.json",
}

_lowerCamelCase							={
    "source_spm": {
        "Helsinki-NLP/opus-mt-en-de": "https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/source.spm"
    },
    "target_spm": {
        "Helsinki-NLP/opus-mt-en-de": "https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/target.spm"
    },
    "vocab": {
        "Helsinki-NLP/opus-mt-en-de": "https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/vocab.json"
    },
    "tokenizer_config_file": {
        "Helsinki-NLP/opus-mt-en-de": (
            "https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/tokenizer_config.json"
        )
    },
}

_lowerCamelCase							={"Helsinki-NLP/opus-mt-en-de": 5_12}
_lowerCamelCase							={}



class 						a_			(				lowerCamelCase_	):



      """simple docstring"""







      __UpperCAmelCase     						= VOCAB_FILES_NAMES
      __UpperCAmelCase     						= PRETRAINED_VOCAB_FILES_MAP
      __UpperCAmelCase     						= PRETRAINED_INIT_CONFIGURATION
      __UpperCAmelCase     						= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      __UpperCAmelCase     						= ['input_ids', 'attention_mask']
      __UpperCAmelCase     						= re.compile('>>.+<<'	)  # type: re.Pattern
      def __init__( self	:				Optional[int]     ,snake_case	:				Optional[int]     ,snake_case	:				List[str]     ,snake_case	:				List[Any]     ,snake_case	:				Union[str, Any]=None     ,snake_case	:				Optional[int]=None     ,snake_case	:				Union[str, Any]=None     ,snake_case	:				Any="<unk>"     ,snake_case	:				int="</s>"     ,snake_case	:				Dict="<pad>"     ,snake_case	:				Union[str, Any]=512     ,snake_case	:				Optional[Dict[str, Any]] = None     ,snake_case	:				int=False     ,**snake_case	:				Optional[int]     ,):
           SCREAMING_SNAKE_CASE 		={} if sp_model_kwargs is None else sp_model_kwargs

           super().__init__(
               # bos_token=bos_token,  unused. Start decoding with config.decoder_start_token_id
               source_lang=snake_case     ,target_lang=snake_case     ,unk_token=snake_case     ,eos_token=snake_case     ,pad_token=snake_case     ,model_max_length=snake_case     ,sp_model_kwargs=self.sp_model_kwargs     ,target_vocab_file=snake_case     ,separate_vocabs=snake_case     ,**snake_case     ,)
           assert Path(snake_case							).exists(), f'cannot find spm source {source_spm}'

           SCREAMING_SNAKE_CASE 		=separate_vocabs
           SCREAMING_SNAKE_CASE 		=load_json(snake_case							)
           if self.unk_token not in self.encoder:
                raise KeyError('<unk> token must be in vocab'							)
           assert self.pad_token in self.encoder

           if separate_vocabs:
                SCREAMING_SNAKE_CASE 		=load_json(snake_case							)
                SCREAMING_SNAKE_CASE 		={v: k for k, v in self.target_encoder.items()}
                SCREAMING_SNAKE_CASE 		=[]
           else:
                SCREAMING_SNAKE_CASE 		={v: k for k, v in self.encoder.items()}
                SCREAMING_SNAKE_CASE 		=[k for k in self.encoder if k.startswith('>>'							) and k.endswith('<<'							)]

           SCREAMING_SNAKE_CASE 		=source_lang
           SCREAMING_SNAKE_CASE 		=target_lang
           SCREAMING_SNAKE_CASE 		=[source_spm, target_spm]

           # load SentencePiece model for pre-processing
           SCREAMING_SNAKE_CASE 		=load_spm(snake_case     ,self.sp_model_kwargs							)
           SCREAMING_SNAKE_CASE 		=load_spm(snake_case     ,self.sp_model_kwargs							)
           SCREAMING_SNAKE_CASE 		=self.spm_source
           SCREAMING_SNAKE_CASE 		=self.encoder

           # Multilingual target side: default to using first supported language code.

           self._setup_normalizer()
      def 			_lowerCAmelCase	( self	:				Tuple							):
           try:
                from sacremoses import MosesPunctNormalizer

                SCREAMING_SNAKE_CASE 		=MosesPunctNormalizer(self.source_lang							).normalize
           except (ImportError, FileNotFoundError):
                warnings.warn('Recommended: pip install sacremoses.'							)
                SCREAMING_SNAKE_CASE 		=lambda snake_case							: x
      def 			_lowerCAmelCase	( self	:				Optional[Any]     ,snake_case	:				str							):
           return self.punc_normalizer(snake_case							) if x else ""
      def 			_lowerCAmelCase	( self	:				List[str]     ,snake_case	:				List[str]							):
           return self.current_encoder.get(snake_case     ,self.current_encoder[self.unk_token]							)
      def 			_lowerCAmelCase	( self	:				List[str]     ,snake_case	:				str							):
           SCREAMING_SNAKE_CASE 		=self.language_code_re.match(snake_case							)
           SCREAMING_SNAKE_CASE 		=[match.group(0							)] if match else []
           return code, self.language_code_re.sub(''     ,snake_case							)
      def 			_lowerCAmelCase	( self	:				Dict     ,snake_case	:				str							):
           SCREAMING_SNAKE_CASE		,    SCREAMING_SNAKE_CASE 		=self.remove_language_code(snake_case							)
           SCREAMING_SNAKE_CASE 		=self.current_spm.encode(snake_case     ,out_type=snake_case							)
           return code + pieces
      def 			_lowerCAmelCase	( self	:				Dict     ,snake_case	:				int							):
           return self.decoder.get(snake_case     ,self.unk_token							)
      def 			_lowerCAmelCase	( self	:				Any     ,snake_case	:				Any     ,**snake_case	:				Tuple							):
           return super().batch_decode(snake_case     ,**snake_case							)
      def 			_lowerCAmelCase	( self	:				int     ,snake_case	:				Tuple     ,**snake_case	:				List[str]							):
           return super().decode(snake_case     ,**snake_case							)
      def 			_lowerCAmelCase	( self	:				str     ,snake_case	:				List[str]							):
           SCREAMING_SNAKE_CASE 		=self.spm_source if self._decode_use_source_tokenizer else self.spm_target
           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 += sp_model.decode_pieces(snake_case							) + token + " "
                     SCREAMING_SNAKE_CASE 		=[]
                else:
                     current_sub_tokens.append(snake_case							)
           out_string += sp_model.decode_pieces(snake_case							)
           return out_string.strip()
      def 			_lowerCAmelCase	( self	:				List[Any]     ,snake_case	:				Union[str, Any]     ,snake_case	:				Optional[int]=None							):
           if token_ids_a is None:
                return token_ids_a + [self.eos_token_id]
           # We don't expect to process pairs, but leave the pair logic for API consistency
           return token_ids_a + token_ids_a + [self.eos_token_id]
      def 			_lowerCAmelCase	( self	:				Optional[Any]							):
           SCREAMING_SNAKE_CASE 		=self.spm_source
           SCREAMING_SNAKE_CASE 		=self.encoder
      def 			_lowerCAmelCase	( self	:				int							):
           SCREAMING_SNAKE_CASE 		=self.spm_target
           if self.separate_vocabs:
                SCREAMING_SNAKE_CASE 		=self.target_encoder
      @property
      def 			_lowerCAmelCase	( self	:				List[Any]							):
           return len(self.encoder							)
      def 			_lowerCAmelCase	( self	:				List[Any]     ,snake_case	:				str     ,snake_case	:				Optional[str] = None							):
           if not os.path.isdir(snake_case							):
                logger.error(f'Vocabulary path ({save_directory}) should be a directory'							)
                return
           SCREAMING_SNAKE_CASE 		=[]

           if self.separate_vocabs:
                SCREAMING_SNAKE_CASE 		=os.path.join(
                    snake_case     ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab']     ,)
                SCREAMING_SNAKE_CASE 		=os.path.join(
                    snake_case     ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['target_vocab_file']     ,)
                save_json(self.encoder     ,snake_case							)
                save_json(self.target_encoder     ,snake_case							)
                saved_files.append(snake_case							)
                saved_files.append(snake_case							)
           else:
                SCREAMING_SNAKE_CASE 		=os.path.join(
                    snake_case     ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab']							)
                save_json(self.encoder     ,snake_case							)
                saved_files.append(snake_case							)

           for spm_save_filename, spm_orig_path, spm_model in zip(
               [VOCAB_FILES_NAMES['source_spm'], VOCAB_FILES_NAMES['target_spm']]     ,self.spm_files     ,[self.spm_source, self.spm_target]     ,):
                SCREAMING_SNAKE_CASE 		=os.path.join(
                    snake_case     ,(filename_prefix + '-' if filename_prefix else '') + spm_save_filename							)
                if os.path.abspath(snake_case							) != os.path.abspath(snake_case							) and os.path.isfile(snake_case							):
                     copyfile(snake_case     ,snake_case							)
                     saved_files.append(snake_case							)
                elif not os.path.isfile(snake_case							):
                     with open(snake_case     ,'wb'							) as fi:
                          SCREAMING_SNAKE_CASE 		=spm_model.serialized_model_proto()
                          fi.write(snake_case							)
                     saved_files.append(snake_case							)

           return tuple(snake_case							)
      def 			_lowerCAmelCase	( self	:				Any							):
           return self.get_src_vocab()
      def 			_lowerCAmelCase	( self	:				int							):
           return dict(self.encoder     ,**self.added_tokens_encoder							)
      def 			_lowerCAmelCase	( self	:				List[Any]							):
           return dict(self.target_encoder     ,**self.added_tokens_decoder							)
      def __getstate__( self	:				Union[str, Any]							):
           SCREAMING_SNAKE_CASE 		=self.__dict__.copy()
           state.update(
               {k: None for k in ['spm_source', 'spm_target', 'current_spm', 'punc_normalizer', 'target_vocab_file']}							)
           return state
      def __setstate__( self	:				List[Any]     ,snake_case	:				Dict							):
           SCREAMING_SNAKE_CASE 		=d

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

           SCREAMING_SNAKE_CASE		,    SCREAMING_SNAKE_CASE 		=(load_spm(snake_case     ,self.sp_model_kwargs							) for f in self.spm_files)
           SCREAMING_SNAKE_CASE 		=self.spm_source
           self._setup_normalizer()
      def 			_lowerCAmelCase	( self	:				Union[str, Any]     ,*snake_case	:				Tuple     ,**snake_case	:				List[Any]							):
           return 1
      def 			_lowerCAmelCase	( self	:				int     ,snake_case	:				str							):
           SCREAMING_SNAKE_CASE 		=set(self.all_special_ids							)  # call it once instead of inside list comp
           all_special_ids.remove(self.unk_token_id							)  # <unk> is only sometimes special
           return [1 if x in all_special_ids else 0 for x in seq]


      def 			_lowerCAmelCase	( self	:				Optional[int]     ,snake_case	:				List     ,snake_case	:				Optional[List] = None     ,snake_case	:				bool = False							):
           if already_has_special_tokens:
                return self._special_token_mask(snake_case							)
           elif token_ids_a is None:
                return self._special_token_mask(snake_case							) + [1]
           else:
                return self._special_token_mask(token_ids_a + token_ids_a							) + [1]







def      snake_case__							(  lowerCAmelCase_,       lowerCAmelCase_     ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE 		=sentencepiece.SentencePieceProcessor(**lowerCAmelCase_     )
     spm.Load(lowerCAmelCase_     )
     return spm







def      snake_case__							(  lowerCAmelCase_,       lowerCAmelCase_     ):





     """simple docstring"""







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







def      snake_case__							(  lowerCAmelCase_     ):





     """simple docstring"""







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




def      snake_case__							(  lowerCAmelCase_ = 100     ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE 		=[[0 for _ in range(lowerCAmelCase_     )] for _ in range(m + 1     )]
     for i in range(m + 1     ):
          SCREAMING_SNAKE_CASE 		=1

     for n in range(m + 1     ):
          for k in range(1,       lowerCAmelCase_     ):
               memo[n][k] += memo[n][k - 1]
               if n > k:
                    memo[n][k] += memo[n - k - 1][k]

     return memo[m][m - 1] - 1


if __name__ == "__main__":
 print(solution(int(input("Enter a number: ").strip())))

