




'''simple docstring'''





import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
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, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch
   from torch import nn

   from transformers import (
       MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
       VideoMAEForPreTraining,
       VideoMAEForVideoClassification,
       VideoMAEModel,
   )
   from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from transformers import VideoMAEImageProcessor

class   _a							:






     def __init__(					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE=13   ,_SCREAMING_SNAKE_CASE=10   ,_SCREAMING_SNAKE_CASE=3   ,_SCREAMING_SNAKE_CASE=2   ,_SCREAMING_SNAKE_CASE=2   ,_SCREAMING_SNAKE_CASE=2   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=32   ,_SCREAMING_SNAKE_CASE=5   ,_SCREAMING_SNAKE_CASE=4   ,_SCREAMING_SNAKE_CASE=37   ,_SCREAMING_SNAKE_CASE="gelu"   ,_SCREAMING_SNAKE_CASE=0.1   ,_SCREAMING_SNAKE_CASE=0.1   ,_SCREAMING_SNAKE_CASE=10   ,_SCREAMING_SNAKE_CASE=0.0_2   ,_SCREAMING_SNAKE_CASE=0.9   ,_SCREAMING_SNAKE_CASE=None   ,)				->     List[Any]:
          _snake_case				= parent
          _snake_case				= batch_size
          _snake_case				= image_size
          _snake_case				= num_channels
          _snake_case				= patch_size
          _snake_case				= tubelet_size
          _snake_case				= num_frames
          _snake_case				= is_training
          _snake_case				= use_labels
          _snake_case				= hidden_size
          _snake_case				= num_hidden_layers
          _snake_case				= num_attention_heads
          _snake_case				= intermediate_size
          _snake_case				= hidden_act
          _snake_case				= hidden_dropout_prob
          _snake_case				= attention_probs_dropout_prob
          _snake_case				= type_sequence_label_size
          _snake_case				= initializer_range
          _snake_case				= mask_ratio
          _snake_case				= scope

          # in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
          _snake_case				= (image_size // patch_size) ** 2
          _snake_case				= (num_frames // tubelet_size) * self.num_patches_per_frame

          # use this variable to define bool_masked_pos
          _snake_case				= int(mask_ratio * self.seq_length       )






     def 							_lowercase      (					self       )				->     List[Any]:
          _snake_case				= floats_tensor(
              [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]       )

          _snake_case				= None
          if self.use_labels:
               _snake_case				= ids_tensor([self.batch_size]   ,self.type_sequence_label_size       )

          _snake_case				= self.get_config()

          return config, pixel_values, labels






     def 							_lowercase      (					self       )				->     str:
          return VideoMAEConfig(
              image_size=self.image_size   ,patch_size=self.patch_size   ,num_channels=self.num_channels   ,num_frames=self.num_frames   ,tubelet_size=self.tubelet_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   ,is_decoder=_SCREAMING_SNAKE_CASE   ,initializer_range=self.initializer_range   ,)






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )				->     str:
          _snake_case				= VideoMAEModel(config=_SCREAMING_SNAKE_CASE       )
          model.to(_SCREAMING_SNAKE_CASE       )
          model.eval()
          _snake_case				= model(_SCREAMING_SNAKE_CASE       )
          self.parent.assertEqual(result.last_hidden_state.shape   ,(self.batch_size, self.seq_length, self.hidden_size)       )






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )				->     str:
          _snake_case				= VideoMAEForPreTraining(_SCREAMING_SNAKE_CASE       )
          model.to(_SCREAMING_SNAKE_CASE       )
          model.eval()
          # important: each video needs to have the same number of masked patches
          # hence we define a single mask, which we then repeat for each example in the batch
          _snake_case				= torch.ones((self.num_masks,)       )
          _snake_case				= torch.cat([mask, torch.zeros(self.seq_length - mask.size(0       )       )]       )
          _snake_case				= mask.expand(self.batch_size   ,-1       ).bool()

          _snake_case				= model(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )
          # model only returns predictions for masked patches
          _snake_case				= mask.sum().item()
          _snake_case				= 3 * self.tubelet_size * self.patch_size**2
          self.parent.assertEqual(result.logits.shape   ,(self.batch_size, num_masked_patches, decoder_num_labels)       )






     def 							_lowercase      (					self       )				->     Optional[int]:
          _snake_case				= self.prepare_config_and_inputs()
          _snake_case				,   _snake_case				,   _snake_case				= config_and_inputs
          _snake_case				= {"pixel_values": pixel_values}
          return config, inputs_dict







@require_torch
class   _a							(		__lowerCAmelCase   ,   __lowerCAmelCase   ,   unittest.TestCase				):
     SCREAMING_SNAKE_CASE_				:       List[str]       							=		(
         (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
     )
     SCREAMING_SNAKE_CASE_				:       List[str]       							=		(
         {"""feature-extraction""": VideoMAEModel, """video-classification""": VideoMAEForVideoClassification}
         if is_torch_available()
         else {}
     )

     SCREAMING_SNAKE_CASE_				:       Tuple       							=		False
     SCREAMING_SNAKE_CASE_				:       Union[str, Any]       							=		False
     SCREAMING_SNAKE_CASE_				:       int       							=		False
     SCREAMING_SNAKE_CASE_				:       Any       							=		False






     def 							_lowercase      (					self       )				->     Tuple:
          _snake_case				= VideoMAEModelTester(self       )
          _snake_case				= ConfigTester(self   ,config_class=_SCREAMING_SNAKE_CASE   ,has_text_modality=_SCREAMING_SNAKE_CASE   ,hidden_size=37       )






     def 							_lowercase      (					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE=False       )				->     Any:
          _snake_case				= copy.deepcopy(_SCREAMING_SNAKE_CASE       )

          if model_class == VideoMAEForPreTraining:
               # important: each video needs to have the same number of masked patches
               # hence we define a single mask, which we then repeat for each example in the batch
               _snake_case				= torch.ones((self.model_tester.num_masks,)       )
               _snake_case				= torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0       )       )]       )
               _snake_case				= mask.expand(self.model_tester.batch_size   ,-1       ).bool()
               _snake_case				= bool_masked_pos.to(_SCREAMING_SNAKE_CASE       )

          if return_labels:
               if model_class in [
                   *get_values(_SCREAMING_SNAKE_CASE       ),
               ]:
                    _snake_case				= torch.zeros(
                        self.model_tester.batch_size   ,dtype=torch.long   ,device=_SCREAMING_SNAKE_CASE       )

          return inputs_dict






     def 							_lowercase      (					self       )				->     Optional[int]:
          self.config_tester.run_common_tests()






     @unittest.skip(reason="VideoMAE does not use inputs_embeds"       )
     def 							_lowercase      (					self       )				->     Any:
          pass






     def 							_lowercase      (					self       )				->     Optional[Any]:
          _snake_case				,   _snake_case				= self.model_tester.prepare_config_and_inputs_for_common()

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






     def 							_lowercase      (					self       )				->     Tuple:
          _snake_case				,   _snake_case				= self.model_tester.prepare_config_and_inputs_for_common()

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

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






     def 							_lowercase      (					self       )				->     Dict:
          _snake_case				= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE       )






     def 							_lowercase      (					self       )				->     List[Any]:
          _snake_case				= self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE       )






     @slow
     def 							_lowercase      (					self       )				->     List[str]:
          for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               _snake_case				= VideoMAEModel.from_pretrained(_SCREAMING_SNAKE_CASE       )
               self.assertIsNotNone(_SCREAMING_SNAKE_CASE       )






     def 							_lowercase      (					self       )				->     Union[str, Any]:
          if not self.has_attentions:
               pass

          else:
               _snake_case				,   _snake_case				= self.model_tester.prepare_config_and_inputs_for_common()
               _snake_case				= True

               for model_class in self.all_model_classes:
                    _snake_case				= self.model_tester.seq_length - self.model_tester.num_masks
                    _snake_case				= (
                        num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
                    )

                    _snake_case				= True
                    _snake_case				= False
                    _snake_case				= True
                    _snake_case				= model_class(_SCREAMING_SNAKE_CASE       )
                    model.to(_SCREAMING_SNAKE_CASE       )
                    model.eval()
                    with torch.no_grad():
                         _snake_case				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )       )
                    _snake_case				= 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"]
                    _snake_case				= True
                    _snake_case				= model_class(_SCREAMING_SNAKE_CASE       )
                    model.to(_SCREAMING_SNAKE_CASE       )
                    model.eval()
                    with torch.no_grad():
                         _snake_case				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )       )
                    _snake_case				= 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]   ,)
                    _snake_case				= len(_SCREAMING_SNAKE_CASE       )

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

                    self.assertEqual(out_len + 1   ,len(_SCREAMING_SNAKE_CASE       )       )

                    _snake_case				= 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       )				->     List[str]:
          def check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       ):
               _snake_case				= model_class(_SCREAMING_SNAKE_CASE       )
               model.to(_SCREAMING_SNAKE_CASE       )
               model.eval()

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

               _snake_case				= outputs.hidden_states
               _snake_case				= self.model_tester.num_hidden_layers + 1
               self.assertEqual(len(_SCREAMING_SNAKE_CASE       )   ,_SCREAMING_SNAKE_CASE       )

               _snake_case				= self.model_tester.seq_length - self.model_tester.num_masks
               _snake_case				= num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

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

          _snake_case				,   _snake_case				= self.model_tester.prepare_config_and_inputs_for_common()

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

               check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE       )






     @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."       )
     def 							_lowercase      (					self       )				->     Union[str, Any]:
          pass







def       __a      (  )		->					Optional[Any]:

     """simple docstring"""




     _snake_case				= hf_hub_download(
         repo_id="hf-internal-testing/spaghetti-video"   ,		filename="eating_spaghetti.npy"   ,		repo_type="dataset"       )
     _snake_case				= np.load(_UpperCamelCase       )
     return list(_UpperCamelCase       )





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






     @cached_property
     def 							_lowercase      (					self       )				->     Optional[int]:
          # logits were tested with a different mean and std, so we use the same here
          return (
              VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]   ,image_std=[0.5, 0.5, 0.5]       )
              if is_vision_available()
              else None
          )






     @slow
     def 							_lowercase      (					self       )				->     Union[str, Any]:
          _snake_case				= VideoMAEForVideoClassification.from_pretrained("MCG-NJU/videomae-base-finetuned-kinetics"       ).to(
              _SCREAMING_SNAKE_CASE       )

          _snake_case				= self.default_image_processor
          _snake_case				= prepare_video()
          _snake_case				= image_processor(_SCREAMING_SNAKE_CASE   ,return_tensors="pt"       ).to(_SCREAMING_SNAKE_CASE       )

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

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

          _snake_case				= torch.tensor([0.3_6_6_9, -0.0_6_8_8, -0.2_4_2_1]       ).to(_SCREAMING_SNAKE_CASE       )

          self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,_SCREAMING_SNAKE_CASE   ,atol=1e-4       )       )






     @slow
     def 							_lowercase      (					self       )				->     Union[str, Any]:
          _snake_case				= VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short"       ).to(_SCREAMING_SNAKE_CASE       )

          _snake_case				= self.default_image_processor
          _snake_case				= prepare_video()
          _snake_case				= image_processor(_SCREAMING_SNAKE_CASE   ,return_tensors="pt"       ).to(_SCREAMING_SNAKE_CASE       )

          # add boolean mask, indicating which patches to mask
          _snake_case				= hf_hub_download(repo_id="hf-internal-testing/bool-masked-pos"   ,filename="bool_masked_pos.pt"       )
          _snake_case				= torch.load(_SCREAMING_SNAKE_CASE       )

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

          # verify the logits
          _snake_case				= torch.Size([1, 1_408, 1_536]       )
          _snake_case				= torch.tensor(
              [[0.7_9_9_4, 0.9_6_1_2, 0.8_5_0_8], [0.7_4_0_1, 0.8_9_5_8, 0.8_3_0_2], [0.5_8_6_2, 0.7_4_6_8, 0.7_3_2_5]]   ,device=_SCREAMING_SNAKE_CASE       )
          self.assertEqual(outputs.logits.shape   ,_SCREAMING_SNAKE_CASE       )
          self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]   ,_SCREAMING_SNAKE_CASE   ,atol=1e-4       )       )

          # verify the loss (`config.norm_pix_loss` = `True`)
          _snake_case				= torch.tensor([0.5_1_4_2]   ,device=_SCREAMING_SNAKE_CASE       )
          self.assertTrue(torch.allclose(outputs.loss   ,_SCREAMING_SNAKE_CASE   ,atol=1e-4       )       )

          # verify the loss (`config.norm_pix_loss` = `False`)
          _snake_case				= VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short"   ,norm_pix_loss=_SCREAMING_SNAKE_CASE       ).to(
              _SCREAMING_SNAKE_CASE       )

          with torch.no_grad():
               _snake_case				= model(**_SCREAMING_SNAKE_CASE       )

          _snake_case				= torch.tensor(torch.tensor([0.6_4_6_9]       )   ,device=_SCREAMING_SNAKE_CASE       )
          self.assertTrue(torch.allclose(outputs.loss   ,_SCREAMING_SNAKE_CASE   ,atol=1e-4       )       )








'''simple docstring'''





from math import factorial





def       __a      (  _UpperCamelCase:       int = 100       )		->					int:

     """simple docstring"""




     return sum(map(_UpperCamelCase   ,		str(factorial(_UpperCamelCase       )       )       )       )


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


