





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 	__lowerCAmelCase      :





   def __init__(			self       ,      snake_case       ,      snake_case=13       ,      snake_case=[30, 30]       ,      snake_case=2       ,      snake_case=3       ,      snake_case=True       ,      snake_case=True       ,      snake_case=32       ,      snake_case=5       ,      snake_case=4       ,      snake_case=37       ,      snake_case="gelu"       ,      snake_case=0.1       ,      snake_case=0.1       ,      snake_case=10       ,      snake_case=0.02       ,      snake_case=3       ,      snake_case=None       ,      snake_case=8       ,      snake_case=10       ,      )					->	Optional[int]:
      """simple docstring"""





      a__						:    List[Any]   		=	parent
      a__						:    List[Any]   		=	batch_size
      a__						:    Optional[Any]   		=	image_size
      a__						:    Tuple   		=	patch_size
      a__						:    int   		=	num_channels
      a__						:    Dict   		=	is_training
      a__						:    Any   		=	use_labels
      a__						:    List[Any]   		=	hidden_size
      a__						:    List[str]   		=	num_hidden_layers
      a__						:    List[Any]   		=	num_attention_heads
      a__						:    int   		=	intermediate_size
      a__						:    List[Any]   		=	hidden_act
      a__						:    List[str]   		=	hidden_dropout_prob
      a__						:    List[Any]   		=	attention_probs_dropout_prob
      a__						:    Dict   		=	type_sequence_label_size
      a__						:    str   		=	initializer_range
      a__						:    Dict   		=	num_labels
      a__						:    Optional[Any]   		=	scope
      a__						:    Optional[int]   		=	n_targets
      a__						:    Dict   		=	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__						:    Union[str, Any]   		=	(image_size[1] // patch_size) * (image_size[0] // patch_size)
      a__						:    Dict   		=	num_patches + 1 + self.num_detection_tokens





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      a__						:    str   		=	floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]]   )

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

      a__						:    int   		=	self.get_config()

      return config, pixel_values, labels





   def 						_snake_case			(			self   )					->	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=snake_case       ,      initializer_range=self.initializer_range       ,      num_detection_tokens=self.num_detection_tokens       ,      num_labels=self.num_labels       ,      )





   def 						_snake_case			(			self       ,      snake_case       ,      snake_case       ,      snake_case   )					->	str:
      """simple docstring"""





      a__						:    Any   		=	YolosModel(config=snake_case   )
      model.to(snake_case   )
      model.eval()
      a__						:    Optional[Any]   		=	model(snake_case   )
      self.parent.assertEqual(
          result.last_hidden_state.shape       ,      (self.batch_size, self.expected_seq_len, self.hidden_size)   )





   def 						_snake_case			(			self       ,      snake_case       ,      snake_case       ,      snake_case   )					->	List[Any]:
      """simple docstring"""





      a__						:    Tuple   		=	YolosForObjectDetection(snake_case   )
      model.to(snake_case   )
      model.eval()

      a__						:    int   		=	model(pixel_values=snake_case   )
      a__						:    List[Any]   		=	model(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__						:    Optional[int]   		=	model(pixel_values=snake_case       ,      labels=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 						_snake_case			(			self   )					->	Any:
      """simple docstring"""





      a__						:    Optional[Any]   		=	self.prepare_config_and_inputs()
      a__		,  a__		,  a__						:    Union[str, Any]   		=	config_and_inputs
      a__						:    List[str]   		=	{"pixel_values": pixel_values}
      return config, inputs_dict







@require_torch
class 	__lowerCAmelCase      (       _UpperCamelCase		,_UpperCamelCase		,unittest.TestCase	):
   _UpperCamelCase			:    int  		=					(YolosModel, YolosForObjectDetection) if is_torch_available() else ()
   _UpperCamelCase			:    int  		=					(
       {"""feature-extraction""": YolosModel, """object-detection""": YolosForObjectDetection} if is_torch_available() else {}
   )

   _UpperCamelCase			:    Optional[Any]  		=					False
   _UpperCamelCase			:    str  		=					False
   _UpperCamelCase			:    Dict  		=					False
   _UpperCamelCase			:    Optional[int]  		=					False





   def 						_snake_case			(			self       ,      snake_case       ,      snake_case       ,      snake_case=False   )					->	Dict:
      """simple docstring"""





      a__						:    List[Any]   		=	super()._prepare_for_class(snake_case       ,      snake_case       ,      return_labels=snake_case   )

      if return_labels:
         if model_class.__name__ == "YolosForObjectDetection":
            a__						:    Union[str, Any]   		=	[]
            for i in range(self.model_tester.batch_size   ):
               a__						:    Any   		=	{}
               a__						:    List[str]   		=	torch.ones(
                   size=(self.model_tester.n_targets,)       ,      device=snake_case       ,      dtype=torch.long   )
               a__						:    Optional[Any]   		=	torch.ones(
                   self.model_tester.n_targets       ,      4       ,      device=snake_case       ,      dtype=torch.float   )
               labels.append(snake_case   )
            a__						:    Union[str, Any]   		=	labels

      return inputs_dict





   def 						_snake_case			(			self   )					->	int:
      """simple docstring"""





      a__						:    int   		=	YolosModelTester(self   )
      a__						:    Optional[Any]   		=	ConfigTester(self       ,      config_class=snake_case       ,      has_text_modality=snake_case       ,      hidden_size=37   )





   def 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      self.config_tester.run_common_tests()





   def 						_snake_case			(			self   )					->	List[Any]:
      """simple docstring"""





      pass





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      a__		,  a__						:    Dict   		=	self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
         a__						:    List[str]   		=	model_class(snake_case   )
         self.assertIsInstance(model.get_input_embeddings()       ,      (nn.Module)   )
         a__						:    Optional[Any]   		=	model.get_output_embeddings()
         self.assertTrue(x is None or isinstance(snake_case       ,      nn.Linear   )   )





   def 						_snake_case			(			self   )					->	Any:
      """simple docstring"""





      a__		,  a__						:    Optional[Any]   		=	self.model_tester.prepare_config_and_inputs_for_common()

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

         a__						:    Dict   		=	["pixel_values"]
         self.assertListEqual(arg_names[:1]       ,      snake_case   )





   def 						_snake_case			(			self   )					->	Any:
      """simple docstring"""





      a__						:    int   		=	self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*snake_case   )





   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      a__		,  a__						:    int   		=	self.model_tester.prepare_config_and_inputs_for_common()
      a__						:    Any   		=	True

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

         # check that output_attentions also work using config
         del inputs_dict["output_attentions"]
         a__						:    Union[str, Any]   		=	True
         a__						:    List[Any]   		=	model_class(snake_case   )
         model.to(snake_case   )
         model.eval()
         with torch.no_grad():
            a__						:    Dict   		=	model(**self._prepare_for_class(snake_case       ,      snake_case   )   )
         a__						:    Union[str, Any]   		=	outputs.attentions
         self.assertEqual(len(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__						:    Optional[int]   		=	len(snake_case   )

         # Check attention is always last and order is fine
         a__						:    Union[str, Any]   		=	True
         a__						:    str   		=	True
         a__						:    List[Any]   		=	model_class(snake_case   )
         model.to(snake_case   )
         model.eval()
         with torch.no_grad():
            a__						:    int   		=	model(**self._prepare_for_class(snake_case       ,      snake_case   )   )

         a__						:    Any   		=	1
         self.assertEqual(out_len + added_hidden_states       ,      len(snake_case   )   )

         a__						:    Optional[Any]   		=	outputs.attentions

         self.assertEqual(len(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 						_snake_case			(			self   )					->	Optional[int]:
      """simple docstring"""





      def check_hidden_states_output(snake_case       ,      snake_case       ,      snake_case   ):
         a__						:    Any   		=	model_class(snake_case   )
         model.to(snake_case   )
         model.eval()

         with torch.no_grad():
            a__						:    str   		=	model(**self._prepare_for_class(snake_case       ,      snake_case   )   )

         a__						:    Union[str, Any]   		=	outputs.hidden_states

         a__						:    List[Any]   		=	getattr(
             self.model_tester       ,      "expected_num_hidden_layers"       ,      self.model_tester.num_hidden_layers + 1   )
         self.assertEqual(len(snake_case   )       ,      snake_case   )

         # YOLOS has a different seq_length
         a__						:    Dict   		=	self.model_tester.expected_seq_len

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

      a__		,  a__						:    Any   		=	self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
         a__						:    int   		=	True
         check_hidden_states_output(snake_case       ,      snake_case       ,      snake_case   )

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         a__						:    Optional[Any]   		=	True

         check_hidden_states_output(snake_case       ,      snake_case       ,      snake_case   )





   def 						_snake_case			(			self   )					->	str:
      """simple docstring"""





      a__						:    int   		=	self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_object_detection(*snake_case   )





   @slow
   def 						_snake_case			(			self   )					->	Tuple:
      """simple docstring"""





      for model_name in YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         a__						:    List[str]   		=	YolosModel.from_pretrained(snake_case   )
         self.assertIsNotNone(snake_case   )







def    _A	(   ):
   a__						:    List[Any]   		=	Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
   return image







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





   @cached_property
   def 						_snake_case			(			self   )					->	Union[str, Any]:
      """simple docstring"""





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





   @slow
   def 						_snake_case			(			self   )					->	Optional[Any]:
      """simple docstring"""





      a__						:    Optional[int]   		=	YolosForObjectDetection.from_pretrained("hustvl/yolos-small"   ).to(snake_case   )

      a__						:    Dict   		=	self.default_image_processor
      a__						:    List[Any]   		=	prepare_img()
      a__						:    List[str]   		=	image_processor(images=snake_case       ,      return_tensors="pt"   ).to(snake_case   )

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

      # verify outputs
      a__						:    Any   		=	torch.Size((1, 100, 92)   )
      self.assertEqual(outputs.logits.shape       ,      snake_case   )

      a__						:    str   		=	torch.tensor(
          [[-24.0_248, -10.3_024, -14.8_290], [-42.0_392, -16.8_200, -27.4_334], [-27.2_743, -11.8_154, -18.7_148]]       ,      device=snake_case       ,      )
      a__						:    List[Any]   		=	torch.tensor(
          [[0.2_559, 0.5_455, 0.4_706], [0.2_989, 0.7_279, 0.1_875], [0.7_732, 0.4_017, 0.4_462]]       ,      device=snake_case   )
      self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]       ,      snake_case       ,      atol=1E-4   )   )
      self.assertTrue(torch.allclose(outputs.pred_boxes[0, :3, :3]       ,      snake_case       ,      atol=1E-4   )   )

      # verify postprocessing
      a__						:    Optional[int]   		=	image_processor.post_process_object_detection(
          snake_case       ,      threshold=0.3       ,      target_sizes=[image.size[::-1]]   )[0]
      a__						:    Dict   		=	torch.tensor([0.9_994, 0.9_790, 0.9_964, 0.9_972, 0.9_861]   ).to(snake_case   )
      a__						:    str   		=	[75, 75, 17, 63, 17]
      a__						:    Optional[Any]   		=	torch.tensor([335.0_609, 79.3_848, 375.4_216, 187.2_495]   ).to(snake_case   )

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








def    _A	(   lowerCamelCase ):
   a__						:    Optional[Any]   		=	1
   for i in range(1				,			num + 1 ):
      fact *= i
   return fact






def    _A	(   lowerCamelCase ):
   a__						:    List[Any]   		=	0
   while number > 0:
      a__						:    str   		=	number % 10
      sum_of_digits += last_digit
      a__						:    Dict   		=	number // 10  # Removing the last_digit from the given number
   return sum_of_digits






def    _A	(   lowerCamelCase = 100 ):
   a__						:    Any   		=	factorial(lowerCamelCase )
   a__						:    Optional[Any]   		=	split_and_add(lowerCamelCase )
   return result


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

