





import inspect
import unittest

from transformers import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
     import torch

     from transformers import MODEL_MAPPING, PoolFormerConfig, PoolFormerForImageClassification, PoolFormerModel
     from transformers.models.poolformer.modeling_poolformer import POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
     from PIL import Image

     from transformers import PoolFormerImageProcessor



class 				_UpperCamelCase       (						lowerCAmelCase_  ):

       def lowercase			(		self:			List[str]		)							->			int:




              """simple docstring"""


              UpperCamelCase_ 							=	self.config_class(**self.inputs_dict		)
              self.parent.assertTrue(hasattr(_SCREAMING_SNAKE_CASE       , "hidden_sizes"		)		)
              self.parent.assertTrue(hasattr(_SCREAMING_SNAKE_CASE       , "num_encoder_blocks"		)		)



class 				_UpperCamelCase       :

       def __init__(		self:			Dict       , _SCREAMING_SNAKE_CASE:			Optional[int]       , _SCREAMING_SNAKE_CASE:			List[str]=13       , _SCREAMING_SNAKE_CASE:			List[Any]=64       , _SCREAMING_SNAKE_CASE:			Any=3       , _SCREAMING_SNAKE_CASE:			Optional[Any]=4       , _SCREAMING_SNAKE_CASE:			Dict=[2, 2, 2, 2]       , _SCREAMING_SNAKE_CASE:			Optional[int]=[8, 4, 2, 1]       , _SCREAMING_SNAKE_CASE:			Optional[Any]=[16, 32, 64, 128]       , _SCREAMING_SNAKE_CASE:			Union[str, Any]=[1, 4, 8, 16]       , _SCREAMING_SNAKE_CASE:			int=False       , _SCREAMING_SNAKE_CASE:			List[Any]=True       , _SCREAMING_SNAKE_CASE:			Dict="gelu"       , _SCREAMING_SNAKE_CASE:			Optional[Any]=0.1       , _SCREAMING_SNAKE_CASE:			str=0.02       , _SCREAMING_SNAKE_CASE:			List[Any]=3       , _SCREAMING_SNAKE_CASE:			List[str]=None       , )							->			Optional[int]:




              """simple docstring"""


              UpperCamelCase_ 							=	parent
              UpperCamelCase_ 							=	batch_size
              UpperCamelCase_ 							=	image_size
              UpperCamelCase_ 							=	num_channels
              UpperCamelCase_ 							=	num_encoder_blocks
              UpperCamelCase_ 							=	sr_ratios
              UpperCamelCase_ 							=	depths
              UpperCamelCase_ 							=	hidden_sizes
              UpperCamelCase_ 							=	downsampling_rates
              UpperCamelCase_ 							=	is_training
              UpperCamelCase_ 							=	use_labels
              UpperCamelCase_ 							=	hidden_act
              UpperCamelCase_ 							=	hidden_dropout_prob
              UpperCamelCase_ 							=	initializer_range
              UpperCamelCase_ 							=	num_labels
              UpperCamelCase_ 							=	scope

       def lowercase			(		self:			Dict		)							->			Dict:




              """simple docstring"""


              UpperCamelCase_ 							=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

              UpperCamelCase_ 							=	None
              if self.use_labels:
                     UpperCamelCase_ 							=	ids_tensor([self.batch_size, self.image_size, self.image_size]       , self.num_labels		)

              UpperCamelCase_ 							=	PoolFormerConfig(
                  image_size=self.image_size       , num_channels=self.num_channels       , num_encoder_blocks=self.num_encoder_blocks       , depths=self.depths       , hidden_sizes=self.hidden_sizes       , hidden_act=self.hidden_act       , hidden_dropout_prob=self.hidden_dropout_prob       , initializer_range=self.initializer_range       , )

              return config, pixel_values, labels

       def lowercase			(		self:			List[Any]       , _SCREAMING_SNAKE_CASE:			Dict       , _SCREAMING_SNAKE_CASE:			Optional[Any]       , _SCREAMING_SNAKE_CASE:			Union[str, Any]		)							->			Any:




              """simple docstring"""


              UpperCamelCase_ 							=	PoolFormerModel(config=_SCREAMING_SNAKE_CASE		)
              model.to(_SCREAMING_SNAKE_CASE		)
              model.eval()
              UpperCamelCase_ 							=	model(_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_ 							=	UpperCamelCase_ 							=	self.image_size // 32.0
              self.parent.assertEqual(
                  result.last_hidden_state.shape       , (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)		)



       def lowercase			(		self:			str		)							->			int:




              """simple docstring"""


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



@require_torch
class 				_UpperCamelCase       (						lowerCAmelCase_	,    lowerCAmelCase_	,    unittest.TestCase  ):
       _UpperCamelCase					:       List[str]       = (PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
       _UpperCamelCase					:       Optional[Any]       = (
           {'''feature-extraction''': PoolFormerModel, '''image-classification''': PoolFormerForImageClassification}
           if is_torch_available()
           else {}
       )

       _UpperCamelCase					:       int       = False
       _UpperCamelCase					:       int       = False
       _UpperCamelCase					:       Optional[Any]       = False
       _UpperCamelCase					:       Union[str, Any]       = False
       _UpperCamelCase					:       int       = False

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




              """simple docstring"""


              UpperCamelCase_ 							=	PoolFormerModelTester(self		)
              UpperCamelCase_ 							=	PoolFormerConfigTester(self       , config_class=_SCREAMING_SNAKE_CASE		)

       def lowercase			(		self:			List[Any]		)							->			Optional[Any]:




              """simple docstring"""


              self.config_tester.run_common_tests()

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




              """simple docstring"""


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

       @unittest.skip("PoolFormer does not use inputs_embeds"		)
       def lowercase			(		self:			Optional[int]		)							->			List[Any]:




              """simple docstring"""


              pass

       @unittest.skip("PoolFormer does not have get_input_embeddings method and get_output_embeddings methods"		)
       def lowercase			(		self:			Optional[Any]		)							->			Any:




              """simple docstring"""


              pass

       def lowercase			(		self:			List[Any]		)							->			Dict:




              """simple docstring"""


              def check_hidden_states_output(_SCREAMING_SNAKE_CASE:			Any       , _SCREAMING_SNAKE_CASE:			int       , _SCREAMING_SNAKE_CASE:			str		):
                     UpperCamelCase_ 							=	model_class(_SCREAMING_SNAKE_CASE		)
                     model.to(_SCREAMING_SNAKE_CASE		)
                     model.eval()

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

                     UpperCamelCase_ 							=	outputs.hidden_states

                     UpperCamelCase_ 							=	self.model_tester.num_encoder_blocks
                     self.assertEqual(len(_SCREAMING_SNAKE_CASE		)       , _SCREAMING_SNAKE_CASE		)

                     # verify the first hidden states (first block)
                     self.assertListEqual(
                         list(hidden_states[0].shape[-3:]		)       , [
                             self.model_tester.hidden_sizes[0],
                             self.model_tester.image_size // 4,
                             self.model_tester.image_size // 4,
                         ]       , )

              UpperCamelCase_							,			UpperCamelCase_ 							=	self.model_tester.prepare_config_and_inputs_for_common()

              for model_class in self.all_model_classes:
                     UpperCamelCase_ 							=	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"]
                     UpperCamelCase_ 							=	True

                     check_hidden_states_output(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE		)

       def lowercase			(		self:			List[str]		)							->			int:




              """simple docstring"""


              if not self.model_tester.is_training:
                     return

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

              for model_class in self.all_model_classes:
                     if model_class in get_values(_SCREAMING_SNAKE_CASE		):
                            continue
                     UpperCamelCase_ 							=	model_class(_SCREAMING_SNAKE_CASE		)
                     model.to(_SCREAMING_SNAKE_CASE		)
                     model.train()
                     UpperCamelCase_ 							=	self._prepare_for_class(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE       , return_labels=_SCREAMING_SNAKE_CASE		)
                     UpperCamelCase_ 							=	model(**_SCREAMING_SNAKE_CASE		).loss
                     loss.backward()

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




              """simple docstring"""


              UpperCamelCase_							,			UpperCamelCase_ 							=	self.model_tester.prepare_config_and_inputs_for_common()

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

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



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




              """simple docstring"""


              for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     UpperCamelCase_ 							=	PoolFormerModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
                     self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)




def 			lowerCAmelCase_			(				)  ->		Optional[Any]:
       UpperCamelCase_ 							=	Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
       return image







@require_torch
class 				_UpperCamelCase       (						unittest.TestCase  ):

       @slow
       def lowercase			(		self:			str		)							->			str:




              """simple docstring"""


              UpperCamelCase_ 							=	PoolFormerImageProcessor()
              UpperCamelCase_ 							=	PoolFormerForImageClassification.from_pretrained("sail/poolformer_s12"		).to(_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_ 							=	image_processor(images=prepare_img()       , return_tensors="pt"		).to(_SCREAMING_SNAKE_CASE		)

              # forward pass
              with torch.no_grad():
                     UpperCamelCase_ 							=	model(**_SCREAMING_SNAKE_CASE		)

              # verify the logits
              UpperCamelCase_ 							=	torch.Size((1, 1000)		)
              self.assertEqual(outputs.logits.shape       , _SCREAMING_SNAKE_CASE		)

              UpperCamelCase_ 							=	torch.tensor([-0.61_13, 0.16_85, -0.04_92]		).to(_SCREAMING_SNAKE_CASE		)
              self.assertTrue(torch.allclose(outputs.logits[0, :3]       , _SCREAMING_SNAKE_CASE       , atol=1e-4		)		)








def     lowerCamelCase__  (  UpperCamelCase__      :							int = 100    )      ->			int:



					'''simple docstring'''




					_snake_case						=					1
					_snake_case						=					0
					for i in range(1							,     num + 1    ):
										fact *= i

					for j in str(UpperCamelCase__    ):
										result += int(UpperCamelCase__    )

					return result


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



