






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''': 5_1_2}
_a	 =     {}






class 							A_				(	snake_case__      ):
     _lowercase    :  Union[str, Any]          =			VOCAB_FILES_NAMES
     _lowercase    :  List[str]          =			PRETRAINED_VOCAB_FILES_MAP
     _lowercase    :  Dict          =			PRETRAINED_INIT_CONFIGURATION
     _lowercase    :  Dict          =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     _lowercase    :  Optional[int]          =			["input_ids", "attention_mask"]
     _lowercase    :  Optional[int]          =			re.compile('>>.+<<'      )  # type: re.Pattern


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

      __lowerCAmelCase:     Dict     			=   separate_vocabs
      __lowerCAmelCase:     List[str]     			=   load_json(UpperCAmelCase      )
      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:
       __lowerCAmelCase:     Optional[int]     			=   load_json(UpperCAmelCase      )
       __lowerCAmelCase:     Optional[Any]     			=   {v: k for k, v in self.target_encoder.items()}
       __lowerCAmelCase:     Dict     			=   []
      else:
       __lowerCAmelCase:     List[Any]     			=   {v: k for k, v in self.encoder.items()}
       __lowerCAmelCase:     list     			=   [k for k in self.encoder if k.startswith('>>'      ) and k.endswith('<<'      )]

      __lowerCAmelCase:     List[str]     			=   source_lang
      __lowerCAmelCase:     Union[str, Any]     			=   target_lang
      __lowerCAmelCase:     int     			=   [source_spm, target_spm]

      # load SentencePiece model for pre-processing
      __lowerCAmelCase:     str     			=   load_spm(UpperCAmelCase    ,						self.sp_model_kwargs      )
      __lowerCAmelCase:     Optional[Any]     			=   load_spm(UpperCAmelCase    ,						self.sp_model_kwargs      )
      __lowerCAmelCase:     str     			=   self.spm_source
      __lowerCAmelCase:     Tuple     			=   self.encoder

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

      self._setup_normalizer()


     def 						UpperCAmelCase						(							self    :	Optional[Any]      )							->			List[str]:






      try:
       from sacremoses import MosesPunctNormalizer

       __lowerCAmelCase:     Union[str, Any]     			=   MosesPunctNormalizer(self.source_lang      ).normalize
      except (ImportError, FileNotFoundError):
       warnings.warn('Recommended: pip install sacremoses.'      )
       __lowerCAmelCase:     Dict     			=   lambda UpperCAmelCase      : x


     def 						UpperCAmelCase						(							self    :	List[str]    ,						UpperCAmelCase    :	Any      )							->			str:
      return self.punc_normalizer(UpperCAmelCase      ) if x else ""


     def 						UpperCAmelCase						(							self    :	Any    ,						UpperCAmelCase    :	int      )							->			Optional[Any]:
      return self.current_encoder.get(UpperCAmelCase    ,						self.current_encoder[self.unk_token]      )


     def 						UpperCAmelCase						(							self    :	List[Any]    ,						UpperCAmelCase    :	Dict      )							->			int:
      __lowerCAmelCase:     Any     			=   self.language_code_re.match(UpperCAmelCase      )
      __lowerCAmelCase:     list     			=   [match.group(0      )] if match else []
      return code, self.language_code_re.sub(''    ,						UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Optional[int]    ,						UpperCAmelCase    :	List[str]      )							->			List[str]:
      __lowerCAmelCase:     Dict     			=   self.remove_language_code(UpperCAmelCase      )
      __lowerCAmelCase:     Union[str, Any]     			=   self.current_spm.encode(UpperCAmelCase    ,						out_type=UpperCAmelCase      )
      return code + pieces


     def 						UpperCAmelCase						(							self    :	Optional[Any]    ,						UpperCAmelCase    :	Union[str, Any]      )							->			str:
      return self.decoder.get(UpperCAmelCase    ,						self.unk_token      )


     def 						UpperCAmelCase						(							self    :	Optional[Any]    ,						UpperCAmelCase    :	Optional[int]    ,						**UpperCAmelCase    :	Optional[int]      )							->			Any:
      return super().batch_decode(UpperCAmelCase    ,						**UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	List[Any]    ,						UpperCAmelCase    :	Optional[int]    ,						**UpperCAmelCase    :	List[Any]      )							->			Dict:
      return super().decode(UpperCAmelCase    ,						**UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Optional[Any]    ,						UpperCAmelCase    :	Union[str, Any]      )							->			str:
      __lowerCAmelCase:     str     			=   self.spm_source if self._decode_use_source_tokenizer else self.spm_target
      __lowerCAmelCase:     List[Any]     			=   []
      __lowerCAmelCase:     Tuple     			=   ""
      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(UpperCAmelCase      ) + token + " "
        __lowerCAmelCase:     Tuple     			=   []
       else:
        current_sub_tokens.append(UpperCAmelCase      )
      out_string += sp_model.decode_pieces(UpperCAmelCase      )
      return out_string.strip()


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


     def 						UpperCAmelCase						(							self    :	List[str]      )							->			List[Any]:
      __lowerCAmelCase:     str     			=   self.spm_target
      if self.separate_vocabs:
       __lowerCAmelCase:     Any     			=   self.target_encoder


     @property
     def 						UpperCAmelCase						(							self    :	int      )							->			int:
      return len(self.encoder      )


     def 						UpperCAmelCase						(							self    :	int    ,						UpperCAmelCase    :	Any    ,						UpperCAmelCase    :	Union[str, Any] = None      )							->			Tuple[str]:






      if not os.path.isdir(UpperCAmelCase      ):
       logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''      )
       return
      __lowerCAmelCase:     List[Any]     			=   []

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

      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]    ,						):
       __lowerCAmelCase:     Union[str, Any]     			=   os.path.join(
           UpperCAmelCase    ,						(filename_prefix + '-' if filename_prefix else '') + spm_save_filename      )
       if os.path.abspath(UpperCAmelCase      ) != os.path.abspath(UpperCAmelCase      ) and os.path.isfile(UpperCAmelCase      ):
        copyfile(UpperCAmelCase    ,						UpperCAmelCase      )
        saved_files.append(UpperCAmelCase      )
       elif not os.path.isfile(UpperCAmelCase      ):
        with open(UpperCAmelCase    ,						'wb'      ) as fi:
         __lowerCAmelCase:     List[str]     			=   spm_model.serialized_model_proto()
         fi.write(UpperCAmelCase      )
        saved_files.append(UpperCAmelCase      )

      return tuple(UpperCAmelCase      )


     def 						UpperCAmelCase						(							self    :	Dict      )							->			Dict:
      return self.get_src_vocab()


     def 						UpperCAmelCase						(							self    :	Dict      )							->			List[Any]:
      return dict(self.encoder    ,						**self.added_tokens_encoder      )


     def 						UpperCAmelCase						(							self    :	List[str]      )							->			List[Any]:
      return dict(self.target_encoder    ,						**self.added_tokens_decoder      )


     def __getstate__(							self    :	int      )							->			Dict:
      __lowerCAmelCase:     Union[str, Any]     			=   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    :	str    ,						UpperCAmelCase    :	Optional[Any]      )							->			None:
      __lowerCAmelCase:     str     			=   d

      # for backward compatibility
      if not hasattr(self    ,						'sp_model_kwargs'      ):
       __lowerCAmelCase:     List[str]     			=   {}

      __lowerCAmelCase:     List[str]     			=   (load_spm(UpperCAmelCase    ,						self.sp_model_kwargs      ) for f in self.spm_files)
      __lowerCAmelCase:     Dict     			=   self.spm_source
      self._setup_normalizer()


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


     def 						UpperCAmelCase						(							self    :	Tuple    ,						UpperCAmelCase    :	int      )							->			Dict:
      __lowerCAmelCase:     List[str]     			=   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    :	Tuple    ,						UpperCAmelCase    :	int    ,						UpperCAmelCase    :	Optional[int] = None    ,						UpperCAmelCase    :	Union[str, Any] = False      )							->			List[int]:






      if already_has_special_tokens:
       return self._special_token_mask(UpperCAmelCase      )
      elif token_ids_a is None:
       return self._special_token_mask(UpperCAmelCase      ) + [1]
      else:
       return self._special_token_mask(token_ids_a + token_ids_a      ) + [1]







def _a				( SCREAMING_SNAKE_CASE	:    str					,      SCREAMING_SNAKE_CASE	:    Dict[str, Any]	)					->					sentencepiece.SentencePieceProcessor:

 """simple docstring"""






 __lowerCAmelCase:     Tuple     			=   sentencepiece.SentencePieceProcessor(**SCREAMING_SNAKE_CASE	)
 spm.Load(SCREAMING_SNAKE_CASE	)
 return spm







def _a				( SCREAMING_SNAKE_CASE	:    Optional[Any]					,      SCREAMING_SNAKE_CASE	:    str	)					->					None:

 """simple docstring"""






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







def _a				( SCREAMING_SNAKE_CASE	:    str	)					->					Union[Dict, List]:

 """simple docstring"""






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








from math import floor, sqrt







def _a				( SCREAMING_SNAKE_CASE	:    int	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0.0
 __lowerCAmelCase:     Any     			=   1.0
 __lowerCAmelCase:     List[str]     			=   int(sqrt(SCREAMING_SNAKE_CASE	)	)
 __lowerCAmelCase:     Union[str, Any]     			=   root
 __lowerCAmelCase:     List[str]     			=   0
 while integer_part != 2 * root:
  __lowerCAmelCase:     List[str]     			=   denominator * integer_part - numerator
  __lowerCAmelCase:     Optional[int]     			=   (n - numerator**2) / denominator
  __lowerCAmelCase:     Union[str, Any]     			=   int((root + numerator) / denominator	)
  period += 1
 return period







def _a				( SCREAMING_SNAKE_CASE	:    int = 1_00_00	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0
 for i in range(2					,      n + 1	):
  __lowerCAmelCase:     List[str]     			=   sqrt(SCREAMING_SNAKE_CASE	)
  if sr - floor(SCREAMING_SNAKE_CASE	) != 0 and continuous_fraction_period(SCREAMING_SNAKE_CASE	) % 2 == 1:
   count_odd_periods += 1
 return count_odd_periods


if __name__ == "__main__":
  print(f"{solution(int(input().strip()))}")





