

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


A__										=      logging.get_logger(__name__)

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

A__										=      {
    "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"
        )
    },
}

A__										=      {"Helsinki-NLP/opus-mt-en-de": 512}
A__										=      {}







class  UpperCamelCase_      (	_snake_case      ):


  """simple docstring"""
  SCREAMING_SNAKE_CASE__					:			List[str]					    =   VOCAB_FILES_NAMES
  SCREAMING_SNAKE_CASE__					:			List[str]					    =   PRETRAINED_VOCAB_FILES_MAP
  SCREAMING_SNAKE_CASE__					:			List[str]					    =   PRETRAINED_INIT_CONFIGURATION
  SCREAMING_SNAKE_CASE__					:			List[Any]					    =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  SCREAMING_SNAKE_CASE__					:			Any					    =   ["""input_ids""", """attention_mask"""]
  SCREAMING_SNAKE_CASE__					:			List[Any]					    =   re.compile(""">>.+<<"""      )  # type: re.Pattern



  def __init__(						self     :					str  ,	A_     :					str  ,	A_     :					List[Any]  ,	A_     :					Optional[int]  ,	A_     :					Dict=None  ,	A_     :					Union[str, Any]=None  ,	A_     :					Optional[Any]=None  ,	A_     :					Optional[int]="<unk>"  ,	A_     :					str="</s>"  ,	A_     :					Optional[int]="<pad>"  ,	A_     :					List[str]=512  ,	A_     :					Optional[Dict[str, Any]] = None  ,	A_     :					Dict=False  ,	**A_     :					Any  ,	)       ->			None:
      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=A_  ,	target_lang=A_  ,	unk_token=A_  ,	eos_token=A_  ,	pad_token=A_  ,	model_max_length=A_  ,	sp_model_kwargs=self.sp_model_kwargs  ,	target_vocab_file=A_  ,	separate_vocabs=A_  ,	**A_  ,	)
      assert Path(A_						).exists(), f"cannot find spm source {source_spm}"

      SCREAMING_SNAKE_CASE__         =    separate_vocabs
      SCREAMING_SNAKE_CASE__         =    load_json(A_						)
      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(A_						)
          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(A_  ,	self.sp_model_kwargs						)
      SCREAMING_SNAKE_CASE__         =    load_spm(A_  ,	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   _UpperCamelCase     (						self     :					int						)       ->			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 A_						: x



  def   _UpperCamelCase     (						self     :					Any  ,	A_     :					str						)       ->			str:
      return self.punc_normalizer(A_						) if x else ""



  def   _UpperCamelCase     (						self     :					Dict  ,	A_     :					Dict						)       ->			str:
      return self.current_encoder.get(A_  ,	self.current_encoder[self.unk_token]						)



  def   _UpperCamelCase     (						self     :					List[str]  ,	A_     :					str						)       ->			int:
      SCREAMING_SNAKE_CASE__         =    self.language_code_re.match(A_						)
      SCREAMING_SNAKE_CASE__         =    [match.group(0						)] if match else []
      return code, self.language_code_re.sub(""  ,	A_						)



  def   _UpperCamelCase     (						self     :					Any  ,	A_     :					str						)       ->			List[str]:
      SCREAMING_SNAKE_CASE__  ,		SCREAMING_SNAKE_CASE__         =    self.remove_language_code(A_						)
      SCREAMING_SNAKE_CASE__         =    self.current_spm.encode(A_  ,	out_type=A_						)
      return code + pieces



  def   _UpperCamelCase     (						self     :					int  ,	A_     :					int						)       ->			str:
      return self.decoder.get(A_  ,	self.unk_token						)



  def   _UpperCamelCase     (						self     :					Optional[Any]  ,	A_     :					List[Any]  ,	**A_     :					Union[str, Any]						)       ->			List[str]:
      return super().batch_decode(A_  ,	**A_						)



  def   _UpperCamelCase     (						self     :					Any  ,	A_     :					List[str]  ,	**A_     :					Union[str, Any]						)       ->			Tuple:
      return super().decode(A_  ,	**A_						)



  def   _UpperCamelCase     (						self     :					int  ,	A_     :					List[str]						)       ->			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(A_						) + token + " "
              SCREAMING_SNAKE_CASE__         =    []
          else:
              current_sub_tokens.append(A_						)
      out_string += sp_model.decode_pieces(A_						)
      return out_string.strip()



  def   _UpperCamelCase     (						self     :					List[str]  ,	A_     :					Optional[Any]  ,	A_     :					str=None						)       ->			List[int]:
      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   _UpperCamelCase     (						self     :					List[Any]						)       ->			Union[str, Any]:
      SCREAMING_SNAKE_CASE__         =    self.spm_source
      SCREAMING_SNAKE_CASE__         =    self.encoder



  def   _UpperCamelCase     (						self     :					Dict						)       ->			Union[str, Any]:
      SCREAMING_SNAKE_CASE__         =    self.spm_target
      if self.separate_vocabs:
          SCREAMING_SNAKE_CASE__         =    self.target_encoder



  @property
  def   _UpperCamelCase     (						self     :					Optional[Any]						)       ->			int:
      return len(self.encoder						)



  def   _UpperCamelCase     (						self     :					Optional[Any]  ,	A_     :					str  ,	A_     :					Optional[str] = None						)       ->			Tuple[str]:
      if not os.path.isdir(A_						):
          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(
              A_  ,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab"]  ,	)
          SCREAMING_SNAKE_CASE__         =    os.path.join(
              A_  ,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["target_vocab_file"]  ,	)
          save_json(self.encoder  ,	A_						)
          save_json(self.target_encoder  ,	A_						)
          saved_files.append(A_						)
          saved_files.append(A_						)
      else:
          SCREAMING_SNAKE_CASE__         =    os.path.join(
              A_  ,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab"]						)
          save_json(self.encoder  ,	A_						)
          saved_files.append(A_						)

      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(
              A_  ,	(filename_prefix + "-" if filename_prefix else "") + spm_save_filename						)
          if os.path.abspath(A_						) != os.path.abspath(A_						) and os.path.isfile(A_						):
              copyfile(A_  ,	A_						)
              saved_files.append(A_						)
          elif not os.path.isfile(A_						):
              with open(A_  ,	"wb"						) as fi:
                  SCREAMING_SNAKE_CASE__         =    spm_model.serialized_model_proto()
                  fi.write(A_						)
              saved_files.append(A_						)

      return tuple(A_						)



  def   _UpperCamelCase     (						self     :					Tuple						)       ->			Dict:
      return self.get_src_vocab()



  def   _UpperCamelCase     (						self     :					Union[str, Any]						)       ->			Dict:
      return dict(self.encoder  ,	**self.added_tokens_encoder						)



  def   _UpperCamelCase     (						self     :					Dict						)       ->			Optional[Any]:
      return dict(self.target_encoder  ,	**self.added_tokens_decoder						)



  def __getstate__(						self     :					str						)       ->			Dict:
      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[str]  ,	A_     :					Dict						)       ->			None:
      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(A_  ,	self.sp_model_kwargs						) for f in self.spm_files)
      SCREAMING_SNAKE_CASE__         =    self.spm_source
      self._setup_normalizer()



  def   _UpperCamelCase     (						self     :					Optional[int]  ,	*A_     :					Optional[Any]  ,	**A_     :					Tuple						)       ->			str:
      return 1



  def   _UpperCamelCase     (						self     :					List[str]  ,	A_     :					int						)       ->			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   _UpperCamelCase     (						self     :					Any  ,	A_     :					List  ,	A_     :					Optional[List] = None  ,	A_     :					bool = False						)       ->			List[int]:
      if already_has_special_tokens:
          return self._special_token_mask(A_						)
      elif token_ids_a is None:
          return self._special_token_mask(A_						) + [1]
      else:
          return self._special_token_mask(token_ids_a + token_ids_a						) + [1]





def 				__a							(       __A			,							__A						):
    SCREAMING_SNAKE_CASE__         =    sentencepiece.SentencePieceProcessor(**__A						)
    spm.Load(__A						)
    return spm





def 				__a							(       __A			,							__A						):
    with open(__A			,							"w"						) as f:
        json.dump(__A			,							__A			,							indent=2						)





def 				__a							(       __A						):
    with open(__A			,							"r"						) as f:
        return json.load(__A						)





A__										=      10**8





def 				__a							(       __A						):
    if n % 10 == 0:
        return False
    SCREAMING_SNAKE_CASE__         =    str(__A						)
    return s == s[::-1]





def 				__a							(       ):
    SCREAMING_SNAKE_CASE__         =    set()
    SCREAMING_SNAKE_CASE__         =    1
    SCREAMING_SNAKE_CASE__         =    5
    while sum_squares < LIMIT:
        SCREAMING_SNAKE_CASE__         =    first_square + 1
        while sum_squares < LIMIT:
            if is_palindrome(__A						):
                answer.add(__A						)
            last_square += 1
            sum_squares += last_square**2
        first_square += 1
        SCREAMING_SNAKE_CASE__         =    first_square**2 + (first_square + 1) ** 2

    return sum(__A						)


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


