


'''simple docstring'''







import unittest

from transformers import BertGenerationConfig, 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, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import BertGenerationDecoder, BertGenerationEncoder


class  lowerCAmelCase_						:





  """simple docstring"""



  def __init__(					self     :							List[Any]				,							SCREAMING_SNAKE_CASE__     :							Optional[int]				,							SCREAMING_SNAKE_CASE__     :							Dict=1_3				,							SCREAMING_SNAKE_CASE__     :							int=7				,							SCREAMING_SNAKE_CASE__     :							List[Any]=True				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]=True				,							SCREAMING_SNAKE_CASE__     :							Any=9_9				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=3_2				,							SCREAMING_SNAKE_CASE__     :							List[str]=5				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]=4				,							SCREAMING_SNAKE_CASE__     :							Optional[int]=3_7				,							SCREAMING_SNAKE_CASE__     :							Optional[int]="gelu"				,							SCREAMING_SNAKE_CASE__     :							Optional[int]=0.1				,							SCREAMING_SNAKE_CASE__     :							List[Any]=0.1				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]=5_0				,							SCREAMING_SNAKE_CASE__     :							int=0.0_2				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]=True				,							SCREAMING_SNAKE_CASE__     :							List[str]=None				,							):





       '''simple docstring'''

       __a       =   parent
       __a       =   batch_size
       __a       =   seq_length
       __a       =   is_training
       __a       =   use_input_mask
       __a       =   vocab_size
       __a       =   hidden_size
       __a       =   num_hidden_layers
       __a       =   num_attention_heads
       __a       =   intermediate_size
       __a       =   hidden_act
       __a       =   hidden_dropout_prob
       __a       =   attention_probs_dropout_prob
       __a       =   max_position_embeddings
       __a       =   initializer_range
       __a       =   use_labels
       __a       =   scope

  def __a						(					self     :							Tuple						):





       '''simple docstring'''

       __a       =   ids_tensor([self.batch_size, self.seq_length]				,							self.vocab_size						)

       __a       =   None
       if self.use_input_mask:
            __a       =   random_attention_mask([self.batch_size, self.seq_length]						)

       if self.use_labels:
            __a       =   ids_tensor([self.batch_size, self.seq_length]				,							self.vocab_size						)

       __a       =   self.get_config()

       return config, input_ids, input_mask, token_labels

  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       return BertGenerationConfig(
           vocab_size=self.vocab_size				,							hidden_size=self.hidden_size				,							num_hidden_layers=self.num_hidden_layers				,							num_attention_heads=self.num_attention_heads				,							intermediate_size=self.intermediate_size				,							hidden_act=self.hidden_act				,							hidden_dropout_prob=self.hidden_dropout_prob				,							attention_probs_dropout_prob=self.attention_probs_dropout_prob				,							max_position_embeddings=self.max_position_embeddings				,							is_decoder=UpperCamelCase__				,							initializer_range=self.initializer_range				,							)

  def __a						(					self     :							Dict						):





       '''simple docstring'''

       (
           __a       
       )       =   self.prepare_config_and_inputs()

       __a       =   True
       __a       =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
       __a       =   ids_tensor([self.batch_size, self.seq_length]				,							vocab_size=2						)

       return (
           config,
           input_ids,
           input_mask,
           token_labels,
           encoder_hidden_states,
           encoder_attention_mask,
       )

  def __a						(					self     :							str				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Any				,							SCREAMING_SNAKE_CASE__     :							Dict				,							**SCREAMING_SNAKE_CASE__     :							Union[str, Any]				,							):





       '''simple docstring'''

       __a       =   BertGenerationEncoder(config=UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       __a       =   model(UpperCamelCase__				,							attention_mask=UpperCamelCase__						)
       __a       =   model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)						)

  def __a						(					self     :							Optional[int]				,							SCREAMING_SNAKE_CASE__     :							Any				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Tuple				,							SCREAMING_SNAKE_CASE__     :							Optional[int]				,							SCREAMING_SNAKE_CASE__     :							Any				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							**SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							):





       '''simple docstring'''

       __a       =   True
       __a       =   BertGenerationEncoder(config=UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       __a       =   model(
           UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							encoder_hidden_states=UpperCamelCase__				,							encoder_attention_mask=UpperCamelCase__				,							)
       __a       =   model(
           UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							encoder_hidden_states=UpperCamelCase__				,							)
       self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)						)

  def __a						(					self     :							Union[str, Any]				,							SCREAMING_SNAKE_CASE__     :							Tuple				,							SCREAMING_SNAKE_CASE__     :							str				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Union[str, Any]				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							**SCREAMING_SNAKE_CASE__     :							Dict				,							):





       '''simple docstring'''

       __a       =   True
       __a       =   True
       __a       =   BertGenerationDecoder(config=UpperCamelCase__						).to(UpperCamelCase__						).eval()

       # first forward pass
       __a       =   model(
           UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							encoder_hidden_states=UpperCamelCase__				,							encoder_attention_mask=UpperCamelCase__				,							use_cache=UpperCamelCase__				,							)
       __a       =   outputs.past_key_values

       # create hypothetical multiple next token and extent to next_input_ids
       __a       =   ids_tensor((self.batch_size, 3)				,							config.vocab_size						)
       __a       =   ids_tensor((self.batch_size, 3)				,							vocab_size=2						)

       # append to next input_ids and
       __a       =   torch.cat([input_ids, next_tokens]				,							dim=-1						)
       __a       =   torch.cat([input_mask, next_mask]				,							dim=-1						)

       __a       =   model(
           UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							encoder_hidden_states=UpperCamelCase__				,							encoder_attention_mask=UpperCamelCase__				,							output_hidden_states=UpperCamelCase__				,							)['hidden_states'][0]
       __a       =   model(
           UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							encoder_hidden_states=UpperCamelCase__				,							encoder_attention_mask=UpperCamelCase__				,							past_key_values=UpperCamelCase__				,							output_hidden_states=UpperCamelCase__				,							)['hidden_states'][0]

       # select random slice
       __a       =   ids_tensor((1,)				,							output_from_past.shape[-1]						).item()
       __a       =   output_from_no_past[:, -3:, random_slice_idx].detach()
       __a       =   output_from_past[:, :, random_slice_idx].detach()

       self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]						)

       # test that outputs are equal for slice
       self.parent.assertTrue(torch.allclose(UpperCamelCase__				,							UpperCamelCase__				,							atol=1E-3						)						)

  def __a						(					self     :							str				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Optional[Any]				,							SCREAMING_SNAKE_CASE__     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							Any				,							*SCREAMING_SNAKE_CASE__     :							Any				,							):





       '''simple docstring'''

       __a       =   BertGenerationDecoder(UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       __a       =   model(UpperCamelCase__				,							attention_mask=UpperCamelCase__				,							labels=UpperCamelCase__						)
       self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.vocab_size)						)


  def __a						(					self     :							List[str]						):





       '''simple docstring'''

       __a       =   self.prepare_config_and_inputs()
       __a       =   {'input_ids': input_ids, 'attention_mask': input_mask}
       return config, inputs_dict


@require_torch
class  lowerCAmelCase_						(       __A		,    __A		,    __A		,    unittest.TestCase      ):





  """simple docstring"""



  a_       :List[str]												=(BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
  a_       :Dict												=(BertGenerationDecoder,) if is_torch_available() else ()
  a_       :Dict												=(
      {"""feature-extraction""": BertGenerationEncoder, """text-generation""": BertGenerationDecoder}
      if is_torch_available()
      else {}
  )

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   BertGenerationEncoderTester(self						)
       __a       =   ConfigTester(self				,							config_class=UpperCamelCase__				,							hidden_size=3_7						)

  def __a						(					self     :							Dict						):





       '''simple docstring'''

       self.config_tester.run_common_tests()

  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__						)

  def __a						(					self     :							Union[str, Any]						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs()
       __a       =   'bert'
       self.model_tester.create_and_check_model(UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__						)

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs_for_decoder()
       self.model_tester.create_and_check_model_as_decoder(*UpperCamelCase__						)

  def __a						(					self     :							Tuple						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs_for_decoder()
       self.model_tester.create_and_check_decoder_model_past_large_inputs(*UpperCamelCase__						)

  def __a						(					self     :							Optional[Any]						):





       '''simple docstring'''

       (
           __a       
       )       =   self.model_tester.prepare_config_and_inputs_for_decoder()

       __a       =   None

       self.model_tester.create_and_check_model_as_decoder(
           UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__				,							)

  def __a						(					self     :							Any						):





       '''simple docstring'''

       __a       =   self.model_tester.prepare_config_and_inputs_for_decoder()
       self.model_tester.create_and_check_for_causal_lm(*UpperCamelCase__						)


  @slow
  def __a						(					self     :							Union[str, Any]						):





       '''simple docstring'''

       __a       =   BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
       self.assertIsNotNone(UpperCamelCase__						)


@require_torch
class  lowerCAmelCase_						(       unittest.TestCase      ):





  """simple docstring"""



  @slow
  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
       __a       =   torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]						)
       with torch.no_grad():
            __a       =   model(UpperCamelCase__						)[0]
       __a       =   torch.Size([1, 8, 1_0_2_4]						)
       self.assertEqual(output.shape				,							UpperCamelCase__						)
       __a       =   torch.tensor(
           [[[0.1_7_7_5, 0.0_0_8_3, -0.0_3_2_1], [1.6_0_0_2, 0.1_2_8_7, 0.3_9_1_2], [2.1_4_7_3, 0.5_7_9_1, 0.6_0_6_6]]]						)
       self.assertTrue(torch.allclose(output[:, :3, :3]				,							UpperCamelCase__				,							atol=1E-4						)						)


@require_torch
class  lowerCAmelCase_						(       unittest.TestCase      ):





  """simple docstring"""



  @slow
  def __a						(					self     :							List[str]						):





       '''simple docstring'''

       __a       =   BertGenerationDecoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
       __a       =   torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]						)
       with torch.no_grad():
            __a       =   model(UpperCamelCase__						)[0]
       __a       =   torch.Size([1, 8, 5_0_3_5_8]						)
       self.assertEqual(output.shape				,							UpperCamelCase__						)
       __a       =   torch.tensor(
           [[[-0.5_7_8_8, -2.5_9_9_4, -3.7_0_5_4], [0.0_4_3_8, 4.7_9_9_7, 1.8_7_9_5], [1.5_8_6_2, 6.6_4_0_9, 4.4_6_3_8]]]						)
       self.assertTrue(torch.allclose(output[:, :3, :3]				,							UpperCamelCase__				,							atol=1E-4						)						)










'''simple docstring'''







def        __lowercase						(      __SCREAMING_SNAKE_CASE = 100_0000		)				->					int:
     """simple docstring"""




     __a       =   1
     __a       =   1
     __a       =   {1: 1}

     for inputa in range(2				,  __SCREAMING_SNAKE_CASE		):
          __a       =   0
          __a       =   inputa

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

          if inputa not in counters:
               __a       =   counter

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


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






