


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

		"""simple docstring"""





		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[str]:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	parent
					_UpperCamelCase					:Any					     =	batch_size
					_UpperCamelCase					:Tuple					     =	image_size
					_UpperCamelCase					:Dict					     =	num_channels
					_UpperCamelCase					:Dict					     =	patch_size
					_UpperCamelCase					:Optional[Any]					     =	tubelet_size
					_UpperCamelCase					:int					     =	num_frames
					_UpperCamelCase					:int					     =	is_training
					_UpperCamelCase					:Dict					     =	use_labels
					_UpperCamelCase					:int					     =	hidden_size
					_UpperCamelCase					:List[Any]					     =	num_hidden_layers
					_UpperCamelCase					:Optional[Any]					     =	num_attention_heads
					_UpperCamelCase					:str					     =	intermediate_size
					_UpperCamelCase					:Optional[Any]					     =	hidden_act
					_UpperCamelCase					:Optional[Any]					     =	hidden_dropout_prob
					_UpperCamelCase					:int					     =	attention_probs_dropout_prob
					_UpperCamelCase					:Union[str, Any]					     =	type_sequence_label_size
					_UpperCamelCase					:int					     =	initializer_range
					_UpperCamelCase					:Any					     =	mask_ratio
					_UpperCamelCase					:List[str]					     =	scope

					# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
					_UpperCamelCase					:Union[str, Any]					     =	(image_size // patch_size) ** 2
					_UpperCamelCase					:List[str]					     =	(num_frames // tubelet_size) * self.num_patches_per_frame

					# use this variable to define bool_masked_pos
					_UpperCamelCase					:Optional[int]					     =	int(mask_ratio * self.seq_length   )
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	floats_tensor(
					    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]   )

					_UpperCamelCase					:Tuple					     =	None
					if self.use_labels:
								_UpperCamelCase					:List[Any]					     =	ids_tensor([self.batch_size]					,				self.type_sequence_label_size   )

					_UpperCamelCase					:str					     =	self.get_config()

					return config, pixel_values, labels
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					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   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	Optional[int]:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	VideoMAEModel(config=SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:Dict					     =	model(SCREAMING_SNAKE_CASE__   )
					self.parent.assertEqual(result.last_hidden_state.shape					,				(self.batch_size, self.seq_length, self.hidden_size)   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	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
					_UpperCamelCase					:Optional[Any]					     =	torch.ones((self.num_masks,)   )
					_UpperCamelCase					:str					     =	torch.cat([mask, torch.zeros(self.seq_length - mask.size(0   )   )]   )
					_UpperCamelCase					:Dict					     =	mask.expand(self.batch_size					,				-1   ).bool()

					_UpperCamelCase					:Optional[Any]					     =	model(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
					# model only returns predictions for masked patches
					_UpperCamelCase					:Optional[Any]					     =	mask.sum().item()
					_UpperCamelCase					:str					     =	3 * self.tubelet_size * self.patch_size**2
					self.parent.assertEqual(result.logits.shape					,				(self.batch_size, num_masked_patches, decoder_num_labels)   )





		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.prepare_config_and_inputs()
					_UpperCamelCase     ,      _UpperCamelCase     ,      _UpperCamelCase					:Optional[int]					     =	config_and_inputs
					_UpperCamelCase					:List[str]					     =	{'''pixel_values''': pixel_values}
					return config, inputs_dict






@require_torch
class      A(  lowerCamelCase__				,							lowerCamelCase__				,							unittest.TestCase		):

		"""simple docstring"""





		A    =							(
		    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
		)
		A    =							(
		    {"feature-extraction": VideoMAEModel, "video-classification": VideoMAEForVideoClassification}
		    if is_torch_available()
		    else {}
		)

		A    =							False
		A    =							False
		A    =							False
		A    =							False
		def   _UpperCamelCase( self   )      ->	Optional[int]:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	VideoMAEModelTester(self   )
					_UpperCamelCase					:Any					     =	ConfigTester(self					,				config_class=SCREAMING_SNAKE_CASE__					,				has_text_modality=SCREAMING_SNAKE_CASE__					,				hidden_size=37   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=False   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	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
								_UpperCamelCase					:Union[str, Any]					     =	torch.ones((self.model_tester.num_masks,)   )
								_UpperCamelCase					:Optional[Any]					     =	torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0   )   )]   )
								_UpperCamelCase					:Any					     =	mask.expand(self.model_tester.batch_size					,				-1   ).bool()
								_UpperCamelCase					:List[str]					     =	bool_masked_pos.to(SCREAMING_SNAKE_CASE__   )

					if return_labels:
								if model_class in [
								    *get_values(SCREAMING_SNAKE_CASE__   ),
								]:
											_UpperCamelCase					:List[str]					     =	torch.zeros(
											    self.model_tester.batch_size					,				dtype=torch.long					,				device=SCREAMING_SNAKE_CASE__   )

					return inputs_dict
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					self.config_tester.run_common_tests()
		@unittest.skip(reason='''VideoMAE does not use inputs_embeds'''   )
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					pass
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:str					     =	self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Dict					     =	model_class(SCREAMING_SNAKE_CASE__   )
								self.assertIsInstance(model.get_input_embeddings()					,				(nn.Module)   )
								_UpperCamelCase					:Union[str, Any]					     =	model.get_output_embeddings()
								self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__					,				nn.Linear   )   )
		def   _UpperCamelCase( self   )      ->	Optional[int]:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:Tuple					     =	self.model_tester.prepare_config_and_inputs_for_common()

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

								_UpperCamelCase					:int					     =	['''pixel_values''']
								self.assertListEqual(arg_names[:1]					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE__   )
		@slow
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_UpperCamelCase					:Tuple					     =	VideoMAEModel.from_pretrained(SCREAMING_SNAKE_CASE__   )
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					if not self.has_attentions:
								pass

					else:
								_UpperCamelCase     ,      _UpperCamelCase					:List[str]					     =	self.model_tester.prepare_config_and_inputs_for_common()
								_UpperCamelCase					:Any					     =	True

								for model_class in self.all_model_classes:
											_UpperCamelCase					:Optional[Any]					     =	self.model_tester.seq_length - self.model_tester.num_masks
											_UpperCamelCase					:str					     =	(
											    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
											)

											_UpperCamelCase					:int					     =	True
											_UpperCamelCase					:Union[str, Any]					     =	False
											_UpperCamelCase					:Any					     =	True
											_UpperCamelCase					:Tuple					     =	model_class(SCREAMING_SNAKE_CASE__   )
											model.to(SCREAMING_SNAKE_CASE__   )
											model.eval()
											with torch.no_grad():
														_UpperCamelCase					:Tuple					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )
											_UpperCamelCase					:List[str]					     =	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"]
											_UpperCamelCase					:Dict					     =	True
											_UpperCamelCase					:int					     =	model_class(SCREAMING_SNAKE_CASE__   )
											model.to(SCREAMING_SNAKE_CASE__   )
											model.eval()
											with torch.no_grad():
														_UpperCamelCase					:Dict					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )
											_UpperCamelCase					:Any					     =	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]					,				)
											_UpperCamelCase					:int					     =	len(SCREAMING_SNAKE_CASE__   )

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

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

											_UpperCamelCase					:Optional[Any]					     =	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   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					def check_hidden_states_output(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					:Tuple					     =	model_class(SCREAMING_SNAKE_CASE__   )
								model.to(SCREAMING_SNAKE_CASE__   )
								model.eval()

								with torch.no_grad():
											_UpperCamelCase					:str					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )

								_UpperCamelCase					:Tuple					     =	outputs.hidden_states
								_UpperCamelCase					:List[Any]					     =	self.model_tester.num_hidden_layers + 1
								self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

								_UpperCamelCase					:List[str]					     =	self.model_tester.seq_length - self.model_tester.num_masks
								_UpperCamelCase					:Any					     =	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]					,				)

					_UpperCamelCase     ,      _UpperCamelCase					:str					     =	self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Any					     =	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					:int					     =	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   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					pass





def 				A_       ( )					->  Union[str, Any]:
			_UpperCamelCase					:Union[str, Any]					     =	hf_hub_download(
			    repo_id='''hf-internal-testing/spaghetti-video'''       ,					filename='''eating_spaghetti.npy'''       ,					repo_type='''dataset'''		)
			_UpperCamelCase					:Union[str, Any]					     =	np.load(snake_case__		)
			return list(snake_case__		)






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

		"""simple docstring"""





		@cached_property
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					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   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	VideoMAEForVideoClassification.from_pretrained('''MCG-NJU/videomae-base-finetuned-kinetics'''   ).to(
					    SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:str					     =	self.default_image_processor
					_UpperCamelCase					:Tuple					     =	prepare_video()
					_UpperCamelCase					:Optional[Any]					     =	image_processor(SCREAMING_SNAKE_CASE__					,				return_tensors='''pt'''   ).to(SCREAMING_SNAKE_CASE__   )

					# forward pass
					with torch.no_grad():
								_UpperCamelCase					:Union[str, Any]					     =	model(**SCREAMING_SNAKE_CASE__   )

					# verify the logits
					_UpperCamelCase					:Union[str, Any]					     =	torch.Size((1, 4_00)   )
					self.assertEqual(outputs.logits.shape					,				SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:List[Any]					     =	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   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''   ).to(SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:Tuple					     =	self.default_image_processor
					_UpperCamelCase					:str					     =	prepare_video()
					_UpperCamelCase					:List[str]					     =	image_processor(SCREAMING_SNAKE_CASE__					,				return_tensors='''pt'''   ).to(SCREAMING_SNAKE_CASE__   )

					# add boolean mask, indicating which patches to mask
					_UpperCamelCase					:Dict					     =	hf_hub_download(repo_id='''hf-internal-testing/bool-masked-pos'''					,				filename='''bool_masked_pos.pt'''   )
					_UpperCamelCase					:Dict					     =	torch.load(SCREAMING_SNAKE_CASE__   )

					# forward pass
					with torch.no_grad():
								_UpperCamelCase					:List[Any]					     =	model(**SCREAMING_SNAKE_CASE__   )

					# verify the logits
					_UpperCamelCase					:Tuple					     =	torch.Size([1, 14_08, 15_36]   )
					_UpperCamelCase					:Optional[Any]					     =	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`)
					_UpperCamelCase					:Tuple					     =	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`)
					_UpperCamelCase					:Union[str, Any]					     =	VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''					,				norm_pix_loss=SCREAMING_SNAKE_CASE__   ).to(
					    SCREAMING_SNAKE_CASE__   )

					with torch.no_grad():
								_UpperCamelCase					:Optional[Any]					     =	model(**SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:Dict					     =	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"""






def 				A_       ( snake_case__		)					->  int:
			_UpperCamelCase					:Dict					     =	1
			for i in range(1       ,					num + 1		):
						fact *= i
			return fact





def 				A_       ( snake_case__		)					->  int:
			_UpperCamelCase					:Dict					     =	0
			while number > 0:
						_UpperCamelCase					:Tuple					     =	number % 10
						sum_of_digits += last_digit
						_UpperCamelCase					:str					     =	number // 10  # Removing the last_digit from the given number
			return sum_of_digits





def 				A_       ( snake_case__ = 1_00		)					->  int:
			_UpperCamelCase					:int					     =	factorial(snake_case__		)
			_UpperCamelCase					:Dict					     =	split_and_add(snake_case__		)
			return result


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

