



'''simple docstring'''


import inspect
import unittest

from transformers import YolosConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import YolosForObjectDetection, YolosModel
  from transformers.models.yolos.modeling_yolos import YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import AutoImageProcessor







class 	UpperCAmelCase	:


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_=1_3							,  lowerCAmelCase_=[3_0, 3_0]							,  lowerCAmelCase_=2							,  lowerCAmelCase_=3							,  lowerCAmelCase_=True							,  lowerCAmelCase_=True							,  lowerCAmelCase_=3_2							,  lowerCAmelCase_=5							,  lowerCAmelCase_=4							,  lowerCAmelCase_=3_7							,  lowerCAmelCase_="gelu"							,  lowerCAmelCase_=0.1							,  lowerCAmelCase_=0.1							,  lowerCAmelCase_=1_0							,  lowerCAmelCase_=0.0_2							,  lowerCAmelCase_=3							,  lowerCAmelCase_=None							,  lowerCAmelCase_=8							,  lowerCAmelCase_=1_0							,  ) ->      List[Any]:



      """simple docstring"""







      a_       		=parent
      a_       		=batch_size
      a_       		=image_size
      a_       		=patch_size
      a_       		=num_channels
      a_       		=is_training
      a_       		=use_labels
      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_       		=type_sequence_label_size
      a_       		=initializer_range
      a_       		=num_labels
      a_       		=scope
      a_       		=n_targets
      a_       		=num_detection_tokens
      # we set the expected sequence length (which is used in several tests)
      # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token) + num_detection_tokens
      a_       		=(image_size[1] // patch_size) * (image_size[0] // patch_size)
      a_       		=num_patches + 1 + self.num_detection_tokens




 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      a_       		=floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]])

      a_       		=None
      if self.use_labels:
           # labels is a list of Dict (each Dict being the labels for a given example in the batch)
           a_       		=[]
           for i in range(self.batch_size):
                a_       		={}
                a_       		=torch.randint(
                    high=self.num_labels							,  size=(self.n_targets,)							,  device=_SCREAMING_SNAKE_CASE)
                a_       		=torch.rand(self.n_targets							,  4							,  device=_SCREAMING_SNAKE_CASE)
                labels.append(_SCREAMING_SNAKE_CASE)

      a_       		=self.get_config()

      return config, pixel_values, labels




 def       lowercase_  (   self) ->      List[Any]:



      """simple docstring"""







      return YolosConfig(
          image_size=self.image_size							,  patch_size=self.patch_size							,  num_channels=self.num_channels							,  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							,  is_decoder=_SCREAMING_SNAKE_CASE							,  initializer_range=self.initializer_range							,  num_detection_tokens=self.num_detection_tokens							,  num_labels=self.num_labels							,  )




 def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      Tuple:



      """simple docstring"""







      a_       		=YolosModel(config=_SCREAMING_SNAKE_CASE)
      model.to(_SCREAMING_SNAKE_CASE)
      model.eval()
      a_       		=model(_SCREAMING_SNAKE_CASE)
      self.parent.assertEqual(
          result.last_hidden_state.shape							,  (self.batch_size, self.expected_seq_len, self.hidden_size))




 def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      int:



      """simple docstring"""







      a_       		=YolosForObjectDetection(_SCREAMING_SNAKE_CASE)
      model.to(_SCREAMING_SNAKE_CASE)
      model.eval()

      a_       		=model(pixel_values=_SCREAMING_SNAKE_CASE)
      a_       		=model(_SCREAMING_SNAKE_CASE)

      self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_detection_tokens, self.num_labels + 1))
      self.parent.assertEqual(result.pred_boxes.shape							,  (self.batch_size, self.num_detection_tokens, 4))

      a_       		=model(pixel_values=_SCREAMING_SNAKE_CASE							,  labels=_SCREAMING_SNAKE_CASE)

      self.parent.assertEqual(result.loss.shape							,  ())
      self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_detection_tokens, self.num_labels + 1))
      self.parent.assertEqual(result.pred_boxes.shape							,  (self.batch_size, self.num_detection_tokens, 4))




 def       lowercase_  (   self) ->      List[Any]:



      """simple docstring"""







      a_       		=self.prepare_config_and_inputs()
      a_		,						a_		,						a_       		=config_and_inputs
      a_       		={"pixel_values": pixel_values}
      return config, inputs_dict







@require_torch
class 	UpperCAmelCase	(		lowerCAmelCase__					,	lowerCAmelCase__					,	unittest.TestCase):


 '''simple docstring'''




 __magic_name__					: Dict  =      (YolosModel, YolosForObjectDetection) if is_torch_available() else ()
 __magic_name__					: List[str]  =      (
     {"feature-extraction": YolosModel, "object-detection": YolosForObjectDetection} if is_torch_available() else {}
 )

 __magic_name__					: List[str]  =      False
 __magic_name__					: Optional[Any]  =      False
 __magic_name__					: int  =      False
 __magic_name__					: Optional[int]  =      False




 def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_=False) ->      Any:



      """simple docstring"""







      a_       		=super()._prepare_for_class(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE							,  return_labels=_SCREAMING_SNAKE_CASE)

      if return_labels:
           if model_class.__name__ == "YolosForObjectDetection":
                a_       		=[]
                for i in range(self.model_tester.batch_size):
                     a_       		={}
                     a_       		=torch.ones(
                         size=(self.model_tester.n_targets,)							,  device=_SCREAMING_SNAKE_CASE							,  dtype=torch.long)
                     a_       		=torch.ones(
                         self.model_tester.n_targets							,  4							,  device=_SCREAMING_SNAKE_CASE							,  dtype=torch.float)
                     labels.append(_SCREAMING_SNAKE_CASE)
                a_       		=labels

      return inputs_dict




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      a_       		=YolosModelTester(self)
      a_       		=ConfigTester(self							,  config_class=_SCREAMING_SNAKE_CASE							,  has_text_modality=_SCREAMING_SNAKE_CASE							,  hidden_size=3_7)




 def       lowercase_  (   self) ->      int:



      """simple docstring"""







      self.config_tester.run_common_tests()




 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      pass




 def       lowercase_  (   self) ->      Optional[Any]:



      """simple docstring"""







      a_		,						a_       		=self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           self.assertIsInstance(model.get_input_embeddings()							,  (nn.Module))
           a_       		=model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(_SCREAMING_SNAKE_CASE							,  nn.Linear))




 def       lowercase_  (   self) ->      Union[str, Any]:



      """simple docstring"""







      a_		,						a_       		=self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           a_       		=inspect.signature(model.forward)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           a_       		=[*signature.parameters.keys()]

           a_       		=["pixel_values"]
           self.assertListEqual(arg_names[:1]							,  _SCREAMING_SNAKE_CASE)




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      a_       		=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)




 def       lowercase_  (   self) ->      Optional[int]:



      """simple docstring"""







      a_		,						a_       		=self.model_tester.prepare_config_and_inputs_for_common()
      a_       		=True

      # in YOLOS, the seq_len is different
      a_       		=self.model_tester.expected_seq_len
      for model_class in self.all_model_classes:
           a_       		=True
           a_       		=False
           a_       		=True
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           model.to(_SCREAMING_SNAKE_CASE)
           model.eval()
           with torch.no_grad():
                a_       		=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE))
           a_       		=outputs.attentions
           self.assertEqual(len(_SCREAMING_SNAKE_CASE)							,  self.model_tester.num_hidden_layers)

           # check that output_attentions also work using config
           del inputs_dict["output_attentions"]
           a_       		=True
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           model.to(_SCREAMING_SNAKE_CASE)
           model.eval()
           with torch.no_grad():
                a_       		=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE))
           a_       		=outputs.attentions
           self.assertEqual(len(_SCREAMING_SNAKE_CASE)							,  self.model_tester.num_hidden_layers)

           self.assertListEqual(
               list(attentions[0].shape[-3:])							,  [self.model_tester.num_attention_heads, seq_len, seq_len]							,  )
           a_       		=len(_SCREAMING_SNAKE_CASE)

           # Check attention is always last and order is fine
           a_       		=True
           a_       		=True
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           model.to(_SCREAMING_SNAKE_CASE)
           model.eval()
           with torch.no_grad():
                a_       		=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE))

           a_       		=1
           self.assertEqual(out_len + added_hidden_states							,  len(_SCREAMING_SNAKE_CASE))

           a_       		=outputs.attentions

           self.assertEqual(len(_SCREAMING_SNAKE_CASE)							,  self.model_tester.num_hidden_layers)
           self.assertListEqual(
               list(self_attentions[0].shape[-3:])							,  [self.model_tester.num_attention_heads, seq_len, seq_len]							,  )




 def       lowercase_  (   self) ->      str:



      """simple docstring"""







      def check_hidden_states_output(lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_):
           a_       		=model_class(_SCREAMING_SNAKE_CASE)
           model.to(_SCREAMING_SNAKE_CASE)
           model.eval()

           with torch.no_grad():
                a_       		=model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE))

           a_       		=outputs.hidden_states

           a_       		=getattr(
               self.model_tester							,  "expected_num_hidden_layers"							,  self.model_tester.num_hidden_layers + 1)
           self.assertEqual(len(_SCREAMING_SNAKE_CASE)							,  _SCREAMING_SNAKE_CASE)

           # YOLOS has a different seq_length
           a_       		=self.model_tester.expected_seq_len

           self.assertListEqual(
               list(hidden_states[0].shape[-2:])							,  [seq_length, self.model_tester.hidden_size]							,  )

      a_		,						a_       		=self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           a_       		=True
           check_hidden_states_output(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           a_       		=True

           check_hidden_states_output(_SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE							,  _SCREAMING_SNAKE_CASE)




 def       lowercase_  (   self) ->      str:



      """simple docstring"""







      a_       		=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_object_detection(*_SCREAMING_SNAKE_CASE)




 @slow
 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      for model_name in YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           a_       		=YolosModel.from_pretrained(_SCREAMING_SNAKE_CASE)
           self.assertIsNotNone(_SCREAMING_SNAKE_CASE)






def  UpperCAmelCase_       (		)     ->   List[Any]:


     '''simple docstring'''







     a_       		=Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
     return image







@require_torch
@require_vision
class 	UpperCAmelCase	(		unittest.TestCase):


 '''simple docstring'''




 @cached_property
 def       lowercase_  (   self) ->      int:



      """simple docstring"""







      return AutoImageProcessor.from_pretrained("hustvl/yolos-small") if is_vision_available() else None




 @slow
 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      a_       		=YolosForObjectDetection.from_pretrained("hustvl/yolos-small").to(_SCREAMING_SNAKE_CASE)

      a_       		=self.default_image_processor
      a_       		=prepare_img()
      a_       		=image_processor(images=_SCREAMING_SNAKE_CASE							,  return_tensors="pt").to(_SCREAMING_SNAKE_CASE)

      # forward pass
      with torch.no_grad():
           a_       		=model(inputs.pixel_values)

      # verify outputs
      a_       		=torch.Size((1, 1_0_0, 9_2))
      self.assertEqual(outputs.logits.shape							,  _SCREAMING_SNAKE_CASE)

      a_       		=torch.tensor(
          [[-2_4.0_2_4_8, -1_0.3_0_2_4, -1_4.8_2_9_0], [-4_2.0_3_9_2, -1_6.8_2_0_0, -2_7.4_3_3_4], [-2_7.2_7_4_3, -1_1.8_1_5_4, -1_8.7_1_4_8]]							,  device=_SCREAMING_SNAKE_CASE							,  )
      a_       		=torch.tensor(
          [[0.2_5_5_9, 0.5_4_5_5, 0.4_7_0_6], [0.2_9_8_9, 0.7_2_7_9, 0.1_8_7_5], [0.7_7_3_2, 0.4_0_1_7, 0.4_4_6_2]]							,  device=_SCREAMING_SNAKE_CASE)
      self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]							,  _SCREAMING_SNAKE_CASE							,  atol=1e-4))
      self.assertTrue(torch.allclose(outputs.pred_boxes[0, :3, :3]							,  _SCREAMING_SNAKE_CASE							,  atol=1e-4))

      # verify postprocessing
      a_       		=image_processor.post_process_object_detection(
          _SCREAMING_SNAKE_CASE							,  threshold=0.3							,  target_sizes=[image.size[::-1]])[0]
      a_       		=torch.tensor([0.9_9_9_4, 0.9_7_9_0, 0.9_9_6_4, 0.9_9_7_2, 0.9_8_6_1]).to(_SCREAMING_SNAKE_CASE)
      a_       		=[7_5, 7_5, 1_7, 6_3, 1_7]
      a_       		=torch.tensor([3_3_5.0_6_0_9, 7_9.3_8_4_8, 3_7_5.4_2_1_6, 1_8_7.2_4_9_5]).to(_SCREAMING_SNAKE_CASE)

      self.assertEqual(len(results["scores"])							,  5)
      self.assertTrue(torch.allclose(results["scores"]							,  _SCREAMING_SNAKE_CASE							,  atol=1e-4))
      self.assertSequenceEqual(results["labels"].tolist()							,  _SCREAMING_SNAKE_CASE)
      self.assertTrue(torch.allclose(results["boxes"][0, :]							,  _SCREAMING_SNAKE_CASE))







'''simple docstring'''


from collections.abc import Generator






def  UpperCAmelCase_       (		):


     '''simple docstring'''







     a_		,						a_       		=0, 1
     while True:
          a_		,						a_       		=b, a + b
          yield b






def  UpperCAmelCase_       (		lowercase__ = 1_0_0_0       ):


     '''simple docstring'''







     a_       		=1
     a_       		=fibonacci_generator()
     while len(str(next(lowercase__       )       )       ) < n:
          answer += 1
     return answer + 1


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


