





import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
        CTRLForSequenceClassification,
        CTRLLMHeadModel,
        CTRLModel,
    )



class  A__       :





      def __init__(			self	,							A_	,							A_=14	,							A_=7	,							A_=True	,							A_=True	,							A_=True	,							A_=True	,							A_=True	,							A_=99	,							A_=32	,							A_=5	,							A_=4	,							A_=37	,							A_="gelu"	,							A_=0.1	,							A_=0.1	,							A_=512	,							A_=16	,							A_=2	,							A_=0.02	,							A_=3	,							A_=4	,							A_=None	,							):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       parent
       UpperCamelCase     : Tuple	     =       batch_size
       UpperCamelCase     : Any	     =       seq_length
       UpperCamelCase     : int	     =       is_training
       UpperCamelCase     : List[str]	     =       use_token_type_ids
       UpperCamelCase     : str	     =       use_input_mask
       UpperCamelCase     : Dict	     =       use_labels
       UpperCamelCase     : str	     =       use_mc_token_ids
       UpperCamelCase     : int	     =       vocab_size
       UpperCamelCase     : List[str]	     =       hidden_size
       UpperCamelCase     : List[Any]	     =       num_hidden_layers
       UpperCamelCase     : str	     =       num_attention_heads
       UpperCamelCase     : Optional[int]	     =       intermediate_size
       UpperCamelCase     : Union[str, Any]	     =       hidden_act
       UpperCamelCase     : Union[str, Any]	     =       hidden_dropout_prob
       UpperCamelCase     : Any	     =       attention_probs_dropout_prob
       UpperCamelCase     : Optional[int]	     =       max_position_embeddings
       UpperCamelCase     : Optional[int]	     =       type_vocab_size
       UpperCamelCase     : Any	     =       type_sequence_label_size
       UpperCamelCase     : Optional[Any]	     =       initializer_range
       UpperCamelCase     : int	     =       num_labels
       UpperCamelCase     : Any	     =       num_choices
       UpperCamelCase     : Optional[Any]	     =       scope
       UpperCamelCase     : Optional[Any]	     =       self.vocab_size - 1





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       ids_tensor([self.batch_size, self.seq_length]	,							self.vocab_size       )

       UpperCamelCase     : Any	     =       None
       if self.use_input_mask:
        UpperCamelCase     : Union[str, Any]	     =       random_attention_mask([self.batch_size, self.seq_length]       )

       UpperCamelCase     : Dict	     =       None
       if self.use_token_type_ids:
        UpperCamelCase     : str	     =       ids_tensor([self.batch_size, self.seq_length]	,							self.type_vocab_size       )

       UpperCamelCase     : str	     =       None
       if self.use_mc_token_ids:
        UpperCamelCase     : Optional[int]	     =       ids_tensor([self.batch_size, self.num_choices]	,							self.seq_length       )

       UpperCamelCase     : Optional[Any]	     =       None
       UpperCamelCase     : Optional[int]	     =       None
       UpperCamelCase     : Union[str, Any]	     =       None
       if self.use_labels:
        UpperCamelCase     : List[str]	     =       ids_tensor([self.batch_size]	,							self.type_sequence_label_size       )
        UpperCamelCase     : List[str]	     =       ids_tensor([self.batch_size, self.seq_length]	,							self.num_labels       )
        UpperCamelCase     : List[str]	     =       ids_tensor([self.batch_size]	,							self.num_choices       )

       UpperCamelCase     : Optional[Any]	     =       self.get_config()

       UpperCamelCase     : int	     =       ids_tensor([self.num_hidden_layers, self.num_attention_heads]	,							2       )

       return (
           config,
           input_ids,
           input_mask,
           head_mask,
           token_type_ids,
           mc_token_ids,
           sequence_labels,
           token_labels,
           choice_labels,
       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return CTRLConfig(
           vocab_size=self.vocab_size	,							n_embd=self.hidden_size	,							n_layer=self.num_hidden_layers	,							n_head=self.num_attention_heads	,							n_positions=self.max_position_embeddings	,							pad_token_id=self.pad_token_id	,							)





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							*A_       ):
       '''simple docstring'''




       UpperCamelCase     : int	     =       CTRLModel(config=A_       )
       model.to(A_       )
       model.eval()

       model(A_	,							token_type_ids=A_	,							head_mask=A_       )
       model(A_	,							token_type_ids=A_       )
       UpperCamelCase     : Tuple	     =       model(A_       )
       self.parent.assertEqual(result.last_hidden_state.shape	,							(self.batch_size, self.seq_length, self.hidden_size)       )
       self.parent.assertEqual(len(result.past_key_values       )	,							config.n_layer       )





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_	,							*A_       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       CTRLLMHeadModel(A_       )
       model.to(A_       )
       model.eval()

       UpperCamelCase     : List[str]	     =       model(A_	,							token_type_ids=A_	,							labels=A_       )
       self.parent.assertEqual(result.loss.shape	,							()       )
       self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.seq_length, self.vocab_size)       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       self.prepare_config_and_inputs()

       (
           (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   (
           UpperCamelCase
       )     ,   
       )     : Any	     =       config_and_inputs

       UpperCamelCase     : Union[str, Any]	     =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

       return config, inputs_dict





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							*A_       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       self.num_labels
       UpperCamelCase     : Optional[int]	     =       CTRLForSequenceClassification(A_       )
       model.to(A_       )
       model.eval()
       UpperCamelCase     : Any	     =       ids_tensor([self.batch_size]	,							self.type_sequence_label_size       )
       UpperCamelCase     : List[Any]	     =       model(A_	,							token_type_ids=A_	,							labels=A_       )
       self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.num_labels)       )



@require_torch
class  A__       (	__snake_case	,       __snake_case	,       __snake_case	,       unittest.TestCase      ):
      _UpperCAmelCase     :Optional[int]						   =       (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
      _UpperCAmelCase     :Any						   =       (CTRLLMHeadModel,) if is_torch_available() else ()
      _UpperCAmelCase     :List[str]						   =       (
          {
              'feature-extraction': CTRLModel,
              'text-classification': CTRLForSequenceClassification,
              'text-generation': CTRLLMHeadModel,
              'zero-shot': CTRLForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      _UpperCAmelCase     :Optional[int]						   =       True
      _UpperCAmelCase     :str						   =       False
      _UpperCAmelCase     :Optional[Any]						   =       False





      def 	__UpperCamelCase(			self	,							A_	,							A_	,							A_	,							A_	,							A_       ):
       '''simple docstring'''




       if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
        # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
        # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
        # config could not be created.
        return True

       return False





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       CTRLModelTester(self       )
       UpperCamelCase     : List[str]	     =       ConfigTester(self	,							config_class=A_	,							n_embd=37       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       super().tearDown()
       # clean-up as much as possible GPU memory occupied by PyTorch
       gc.collect()
       torch.cuda.empty_cache()





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       self.config_tester.run_common_tests()





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_ctrl_model(*A_       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[str]	     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_lm_head_model(*A_       )





      @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."       )
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       pass





      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        UpperCamelCase     : Dict	     =       CTRLModel.from_pretrained(A_       )
        self.assertIsNotNone(A_       )





      @unittest.skip("The model doesn't support left padding"       )  # and it's not used enough to be worth fixing :)
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       pass



@require_torch
class  A__       (	unittest.TestCase      ):





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       super().tearDown()
       # clean-up as much as possible GPU memory occupied by PyTorch
       gc.collect()
       torch.cuda.empty_cache()





      @slow
      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : str	     =       CTRLLMHeadModel.from_pretrained("ctrl"       )
       model.to(A_       )
       UpperCamelCase     : List[Any]	     =       torch.tensor(
           [[1_1859, 0, 1611, 8]]	,							dtype=torch.long	,							device=A_       )  # Legal the president is
       UpperCamelCase     : Any	     =       [
           1_1859,
           0,
           1611,
           8,
           5,
           150,
           2_6449,
           2,
           19,
           348,
           469,
           3,
           2595,
           48,
           2_0740,
           24_6533,
           24_6533,
           19,
           30,
           5,
       ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

       UpperCamelCase     : Optional[Any]	     =       model.generate(A_	,							do_sample=A_       )
       self.assertListEqual(output_ids[0].tolist()	,							A_       )







def 		A_    (					_lowerCAmelCase					)						->			int:
 if n == 1 or not isinstance(_lowerCAmelCase							,       _lowerCAmelCase					):
  return 0
 elif n == 2:
  return 1
 else:
  UpperCamelCase     : Optional[Any]	     =       [0, 1]
  for i in range(2							,       n + 1					):
   sequence.append(sequence[i - 1] + sequence[i - 2]					)

  return sequence[n]



def 		A_    (					_lowerCAmelCase					)						->			int:
 UpperCamelCase     : Any	     =       0
 UpperCamelCase     : List[Any]	     =       2

 while digits < n:
  index += 1
  UpperCamelCase     : Union[str, Any]	     =       len(str(fibonacci(_lowerCAmelCase					)					)					)

 return index



def 		A_    (					_lowerCAmelCase = 1000					)						->			int:
 return fibonacci_digits_index(_lowerCAmelCase					)


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