


'''simple docstring'''




import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import SPIECE_UNDERLINE, logging


__snake_case    						=logging.get_logger(__name__)

__snake_case    						={"""vocab_file""": """spiece.model"""}

__snake_case    						={
    """vocab_file""": {
        """xlnet-base-cased""": """https://huggingface.co/xlnet-base-cased/resolve/main/spiece.model""",
        """xlnet-large-cased""": """https://huggingface.co/xlnet-large-cased/resolve/main/spiece.model""",
    }
}

__snake_case    						={
    """xlnet-base-cased""": None,
    """xlnet-large-cased""": None,
}

# Segments (not really needed)
__snake_case    						=0
__snake_case    						=1
__snake_case    						=2
__snake_case    						=3
__snake_case    						=4

class 		UpperCAmelCase_      (  __UpperCAmelCase		):
     lowerCamelCase				:	List[Any]		=     VOCAB_FILES_NAMES
     lowerCamelCase				:	List[Any]		=     PRETRAINED_VOCAB_FILES_MAP
     lowerCamelCase				:	Optional[int]		=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     lowerCamelCase				:	Optional[Any]		=     '''left'''





     def __init__( self       :      List[str]    ,      UpperCAmelCase__       :      Optional[Any]    ,      UpperCAmelCase__       :      List[Any]=False    ,      UpperCAmelCase__       :      str=True    ,      UpperCAmelCase__       :      Optional[int]=False    ,      UpperCAmelCase__       :      List[Any]="<s>"    ,      UpperCAmelCase__       :      Any="</s>"    ,      UpperCAmelCase__       :      Tuple="<unk>"    ,      UpperCAmelCase__       :      int="<sep>"    ,      UpperCAmelCase__       :      Optional[Any]="<pad>"    ,      UpperCAmelCase__       :      Dict="<cls>"    ,      UpperCAmelCase__       :      Dict="<mask>"    ,      UpperCAmelCase__       :      int=["<eop>", "<eod>"]    ,      UpperCAmelCase__       :      str = None    ,      **UpperCAmelCase__       :      Optional[int]    ,      )				->  Union[str, Any]:
        lowerCAmelCase     =			AddedToken(UpperCamelCase__    ,      lstrip=UpperCamelCase__    ,      rstrip=UpperCamelCase__    ) if isinstance(UpperCamelCase__    ,      UpperCamelCase__    ) else mask_token

        lowerCAmelCase     =			{} if sp_model_kwargs is None else sp_model_kwargs

        super().__init__(
            do_lower_case=UpperCamelCase__    ,      remove_space=UpperCamelCase__    ,      keep_accents=UpperCamelCase__    ,      bos_token=UpperCamelCase__    ,      eos_token=UpperCamelCase__    ,      unk_token=UpperCamelCase__    ,      sep_token=UpperCamelCase__    ,      pad_token=UpperCamelCase__    ,      cls_token=UpperCamelCase__    ,      mask_token=UpperCamelCase__    ,      additional_special_tokens=UpperCamelCase__    ,      sp_model_kwargs=self.sp_model_kwargs    ,      **UpperCamelCase__    ,      )

        lowerCAmelCase     =			3

        lowerCAmelCase     =			do_lower_case
        lowerCAmelCase     =			remove_space
        lowerCAmelCase     =			keep_accents
        lowerCAmelCase     =			vocab_file

        lowerCAmelCase     =			spm.SentencePieceProcessor(**self.sp_model_kwargs    )
        self.sp_model.Load(UpperCamelCase__    )





     @property
     def 							__UpperCAmelCase      ( self       :      int    )				->  Tuple:
        return len(self.sp_model    )





     def 							__UpperCAmelCase      ( self       :      Tuple    )				->  Tuple:
        lowerCAmelCase     =			{self.convert_ids_to_tokens(UpperCamelCase__    ): i for i in range(self.vocab_size    )}
        vocab.update(self.added_tokens_encoder    )
        return vocab





     def __getstate__( self       :      Tuple    )				->  Optional[int]:
        lowerCAmelCase     =			self.__dict__.copy()
        lowerCAmelCase     =			None
        return state





     def __setstate__( self       :      str    ,      UpperCAmelCase__       :      Union[str, Any]    )				->  List[Any]:
        lowerCAmelCase     =			d

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

        lowerCAmelCase     =			spm.SentencePieceProcessor(**self.sp_model_kwargs    )
        self.sp_model.Load(self.vocab_file    )





     def 							__UpperCAmelCase      ( self       :      List[Any]    ,      UpperCAmelCase__       :      Tuple    )				->  Optional[Any]:



        if self.remove_space:
           lowerCAmelCase     =			' '.join(inputs.strip().split()    )
        else:
           lowerCAmelCase     =			inputs
        lowerCAmelCase     =			outputs.replace('``'    ,      '"'    ).replace('\'\''    ,      '"'    )

        if not self.keep_accents:
           lowerCAmelCase     =			unicodedata.normalize('NFKD'    ,      UpperCamelCase__    )
           lowerCAmelCase     =			''.join([c for c in outputs if not unicodedata.combining(UpperCamelCase__    )]    )
        if self.do_lower_case:
           lowerCAmelCase     =			outputs.lower()

        return outputs





     def 							__UpperCAmelCase      ( self       :      Optional[int]    ,      UpperCAmelCase__       :      Dict    )				->  Dict:
        lowerCAmelCase     =			self.preprocess_text(UpperCamelCase__    )
        lowerCAmelCase     =			self.sp_model.encode(UpperCamelCase__    ,      out_type=UpperCamelCase__    )
        lowerCAmelCase     =			[]
        for piece in pieces:
           if len(UpperCamelCase__    ) > 1 and piece[-1] == str(','    ) and piece[-2].isdigit():
              lowerCAmelCase     =			self.sp_model.EncodeAsPieces(piece[:-1].replace(UpperCamelCase__    ,      ''    )    )
              if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                 if len(cur_pieces[0]    ) == 1:
                    lowerCAmelCase     =			cur_pieces[1:]
                 else:
                    lowerCAmelCase     =			cur_pieces[0][1:]
              cur_pieces.append(piece[-1]    )
              new_pieces.extend(UpperCamelCase__    )
           else:
              new_pieces.append(UpperCamelCase__    )

        return new_pieces





     def 							__UpperCAmelCase      ( self       :      Any    ,      UpperCAmelCase__       :      Union[str, Any]    )				->  Any:
        return self.sp_model.PieceToId(UpperCamelCase__    )





     def 							__UpperCAmelCase      ( self       :      Optional[int]    ,      UpperCAmelCase__       :      int    )				->  Any:
        return self.sp_model.IdToPiece(UpperCamelCase__    )





     def 							__UpperCAmelCase      ( self       :      Optional[int]    ,      UpperCAmelCase__       :      str    )				->  int:
        lowerCAmelCase     =			''.join(UpperCamelCase__    ).replace(UpperCamelCase__    ,      ' '    ).strip()
        return out_string





     def 							__UpperCAmelCase      ( self       :      List[Any]    ,      UpperCAmelCase__       :      Optional[Any]    ,      UpperCAmelCase__       :      Optional[int] = False    ,      UpperCAmelCase__       :      List[Any] = None    ,      UpperCAmelCase__       :      int = True    ,      **UpperCAmelCase__       :      Union[str, Any]    ,      )				->  Optional[int]:
        lowerCAmelCase     =			kwargs.pop('use_source_tokenizer'    ,      UpperCamelCase__    )

        lowerCAmelCase     =			self.convert_ids_to_tokens(UpperCamelCase__    ,      skip_special_tokens=UpperCamelCase__    )

        # To avoid mixing byte-level and unicode for byte-level BPT
        # we need to build string separately for added tokens and byte-level tokens
        # cf. https://github.com/huggingface/transformers/issues/1133
        lowerCAmelCase     =			[]
        lowerCAmelCase     =			[]
        for token in filtered_tokens:
           if skip_special_tokens and token in self.all_special_ids:
              continue
           if token in self.added_tokens_encoder:
              if current_sub_text:
                 sub_texts.append(self.convert_tokens_to_string(UpperCamelCase__    )    )
                 lowerCAmelCase     =			[]
              sub_texts.append(UpperCamelCase__    )
           else:
              current_sub_text.append(UpperCamelCase__    )
        if current_sub_text:
           sub_texts.append(self.convert_tokens_to_string(UpperCamelCase__    )    )

        # Mimic the behavior of the Rust tokenizer:
        # By default, there are no spaces between special tokens
        lowerCAmelCase     =			''.join(UpperCamelCase__    )

        lowerCAmelCase     =			(
            clean_up_tokenization_spaces
            if clean_up_tokenization_spaces is not None
            else self.clean_up_tokenization_spaces
        )
        if clean_up_tokenization_spaces:
           lowerCAmelCase     =			self.clean_up_tokenization(UpperCamelCase__    )
           return clean_text
        else:
           return text





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    ,      UpperCAmelCase__       :      Tuple    ,      UpperCAmelCase__       :      List[str] = None    )				->  str:
        lowerCAmelCase     =			[self.sep_token_id]
        lowerCAmelCase     =			[self.cls_token_id]
        if token_ids_a is None:
           return token_ids_a + sep + cls
        return token_ids_a + sep + token_ids_a + sep + cls





     def 							__UpperCAmelCase      ( self       :      List[str]    ,      UpperCAmelCase__       :      str    ,      UpperCAmelCase__       :      Union[str, Any] = None    ,      UpperCAmelCase__       :      int = False    )				->  str:



        if already_has_special_tokens:
           return super().get_special_tokens_mask(
               token_ids_a=UpperCamelCase__    ,      token_ids_a=UpperCamelCase__    ,      already_has_special_tokens=UpperCamelCase__    )

        if token_ids_a is not None:
           return ([0] * len(UpperCamelCase__    )) + [1] + ([0] * len(UpperCamelCase__    )) + [1, 1]
        return ([0] * len(UpperCamelCase__    )) + [1, 1]





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    ,      UpperCAmelCase__       :      List[Any]    ,      UpperCAmelCase__       :      List[Any] = None    )				->  Union[str, Any]:
        lowerCAmelCase     =			[self.sep_token_id]
        lowerCAmelCase     =			[2]

        if token_ids_a is None:
           return len(token_ids_a + sep    ) * [0] + cls_segment_id
        return len(token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1] + cls_segment_id





     def 							__UpperCAmelCase      ( self       :      List[Any]    ,      UpperCAmelCase__       :      List[Any]    ,      UpperCAmelCase__       :      str = None    )				->  Any:



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

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

        return (out_vocab_file,)











def __UpperCamelCase			(       _A = 1000000  ):
						lowerCAmelCase_      			=  1
						lowerCAmelCase_      			=  1
						lowerCAmelCase_      			=  {1: 1}

						for inputa in range(2 ,  _A  ):
												lowerCAmelCase_      			=  0
												lowerCAmelCase_      			=  inputa

												while True:
																		if number in counters:
																								counter += counters[number]
																								break
																		if number % 2 == 0:
																								number //= 2
																								counter += 1
																		else:
																								lowerCAmelCase_      			=  (3 * number) + 1
																								counter += 1

												if inputa not in counters:
																		lowerCAmelCase_      			=  counter

												if counter > pre_counter:
																		lowerCAmelCase_      			=  inputa
																		lowerCAmelCase_      			=  counter
						return largest_number


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




