



'''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			:			List[Any],       __UpperCAmelCase			:			Any,       __UpperCAmelCase			:			Optional[Any]=13,       __UpperCAmelCase			:			Optional[Any]=10,       __UpperCAmelCase			:			int=3,       __UpperCAmelCase			:			int=2,       __UpperCAmelCase			:			Optional[Any]=2,       __UpperCAmelCase			:			Dict=2,       __UpperCAmelCase			:			str=True,       __UpperCAmelCase			:			List[str]=True,       __UpperCAmelCase			:			List[Any]=32,       __UpperCAmelCase			:			Tuple=5,       __UpperCAmelCase			:			Optional[int]=4,       __UpperCAmelCase			:			List[str]=37,       __UpperCAmelCase			:			Any="gelu",       __UpperCAmelCase			:			Optional[int]=0.1,       __UpperCAmelCase			:			Any=0.1,       __UpperCAmelCase			:			str=10,       __UpperCAmelCase			:			Any=0.02,       __UpperCAmelCase			:			Optional[Any]=0.9,       __UpperCAmelCase			:			List[str]=None,       )  ->      Tuple:

					"""simple docstring"""

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

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

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


	def 					lowercase__	(self			:			Optional[Any]   )  ->      int:

					"""simple docstring"""

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

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

					SCREAMING_SNAKE_CASE	:    str          =			self.get_config()

					return config, pixel_values, labels


	def 					lowercase__	(self			:			Any   )  ->      Optional[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=lowerCamelCase_,       initializer_range=self.initializer_range,       )


	def 					lowercase__	(self			:			int,       __UpperCAmelCase			:			Optional[Any],       __UpperCAmelCase			:			Dict,       __UpperCAmelCase			:			Optional[Any]   )  ->      Optional[int]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    str          =			VideoMAEModel(config=lowerCamelCase_   )
					model.to(lowerCamelCase_   )
					model.eval()
					SCREAMING_SNAKE_CASE	:    Dict          =			model(lowerCamelCase_   )
					self.parent.assertEqual(result.last_hidden_state.shape,       (self.batch_size, self.seq_length, self.hidden_size)   )


	def 					lowercase__	(self			:			List[str],       __UpperCAmelCase			:			str,       __UpperCAmelCase			:			List[Any],       __UpperCAmelCase			:			Any   )  ->      str:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    int          =			VideoMAEForPreTraining(lowerCamelCase_   )
					model.to(lowerCamelCase_   )
					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
					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			torch.ones((self.num_masks,)   )
					SCREAMING_SNAKE_CASE	:    List[str]          =			torch.cat([mask, torch.zeros(self.seq_length - mask.size(0   )   )]   )
					SCREAMING_SNAKE_CASE	:    List[Any]          =			mask.expand(self.batch_size,       -1   ).bool()

					SCREAMING_SNAKE_CASE	:    str          =			model(lowerCamelCase_,       lowerCamelCase_   )
					# model only returns predictions for masked patches
					SCREAMING_SNAKE_CASE	:    Dict          =			mask.sum().item()
					SCREAMING_SNAKE_CASE	:    Dict          =			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			:			Tuple   )  ->      Union[str, Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    Any          =			self.prepare_config_and_inputs()
					SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE	:    Any          =			config_and_inputs
					SCREAMING_SNAKE_CASE	:    List[str]          =			{'''pixel_values''': pixel_values}
					return config, inputs_dict



@require_torch
class 						a__  (					a__,      a__,      unittest.TestCase						):
	__magic_name__		:     List[Any]						     =  (
	    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
	)
	__magic_name__		:     Tuple						     =  (
	    {"feature-extraction": VideoMAEModel, "video-classification": VideoMAEForVideoClassification}
	    if is_torch_available()
	    else {}
	)

	__magic_name__		:     Optional[Any]						     =  False
	__magic_name__		:     str						     =  False
	__magic_name__		:     Any						     =  False
	__magic_name__		:     Dict						     =  False


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

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    int          =			VideoMAEModelTester(self   )
					SCREAMING_SNAKE_CASE	:    int          =			ConfigTester(self,       config_class=lowerCamelCase_,       has_text_modality=lowerCamelCase_,       hidden_size=37   )


	def 					lowercase__	(self			:			List[str],       __UpperCAmelCase			:			Optional[Any],       __UpperCAmelCase			:			List[str],       __UpperCAmelCase			:			Any=False   )  ->      List[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			copy.deepcopy(lowerCamelCase_   )

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

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

					return inputs_dict


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

					"""simple docstring"""

					self.config_tester.run_common_tests()


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

					"""simple docstring"""

					pass


	def 					lowercase__	(self			:			str   )  ->      Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE	:    Optional[int]          =			self.model_tester.prepare_config_and_inputs_for_common()

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


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

					"""simple docstring"""

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

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

									SCREAMING_SNAKE_CASE	:    int          =			['''pixel_values''']
									self.assertListEqual(arg_names[:1],       lowerCamelCase_   )


	def 					lowercase__	(self			:			Dict   )  ->      str:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCamelCase_   )


	def 					lowercase__	(self			:			int   )  ->      int:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    List[str]          =			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*lowerCamelCase_   )


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

					"""simple docstring"""

					for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE	:    List[str]          =			VideoMAEModel.from_pretrained(lowerCamelCase_   )
									self.assertIsNotNone(lowerCamelCase_   )


	def 					lowercase__	(self			:			Dict   )  ->      Tuple:

					"""simple docstring"""

					if not self.has_attentions:
									pass

					else:
									SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE	:    Tuple          =			self.model_tester.prepare_config_and_inputs_for_common()
									SCREAMING_SNAKE_CASE	:    List[str]          =			True

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

													SCREAMING_SNAKE_CASE	:    Dict          =			True
													SCREAMING_SNAKE_CASE	:    List[Any]          =			False
													SCREAMING_SNAKE_CASE	:    str          =			True
													SCREAMING_SNAKE_CASE	:    List[Any]          =			model_class(lowerCamelCase_   )
													model.to(lowerCamelCase_   )
													model.eval()
													with torch.no_grad():
																	SCREAMING_SNAKE_CASE	:    Optional[int]          =			model(**self._prepare_for_class(lowerCamelCase_,       lowerCamelCase_   )   )
													SCREAMING_SNAKE_CASE	:    Any          =			outputs.attentions
													self.assertEqual(len(lowerCamelCase_   ),       self.model_tester.num_hidden_layers   )

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

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

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

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

													SCREAMING_SNAKE_CASE	:    List[Any]          =			outputs.attentions

													self.assertEqual(len(lowerCamelCase_   ),       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			:			Dict   )  ->      Dict:

					"""simple docstring"""

					def check_hidden_states_output(__UpperCAmelCase			:			Tuple,       __UpperCAmelCase			:			List[str],       __UpperCAmelCase			:			List[str]   ):
									SCREAMING_SNAKE_CASE	:    List[str]          =			model_class(lowerCamelCase_   )
									model.to(lowerCamelCase_   )
									model.eval()

									with torch.no_grad():
													SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			model(**self._prepare_for_class(lowerCamelCase_,       lowerCamelCase_   )   )

									SCREAMING_SNAKE_CASE	:    Any          =			outputs.hidden_states
									SCREAMING_SNAKE_CASE	:    Tuple          =			self.model_tester.num_hidden_layers + 1
									self.assertEqual(len(lowerCamelCase_   ),       lowerCamelCase_   )

									SCREAMING_SNAKE_CASE	:    Optional[int]          =			self.model_tester.seq_length - self.model_tester.num_masks
									SCREAMING_SNAKE_CASE	:    Tuple          =			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],       )

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

					for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE	:    List[Any]          =			True
									check_hidden_states_output(lowerCamelCase_,       lowerCamelCase_,       lowerCamelCase_   )

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			True

									check_hidden_states_output(lowerCamelCase_,       lowerCamelCase_,       lowerCamelCase_   )






	@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''   )
	def 					lowercase__	(self			:			int   )  ->      int:

					"""simple docstring"""

					pass






def    __lowercase	():
				SCREAMING_SNAKE_CASE	:    List[str]          =			hf_hub_download(
				    repo_id='''hf-internal-testing/spaghetti-video'''     ,						filename='''eating_spaghetti.npy'''     ,						repo_type='''dataset'''							)
				SCREAMING_SNAKE_CASE	:    Any          =			np.load(_SCREAMING_SNAKE_CASE							)
				return list(_SCREAMING_SNAKE_CASE							)




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


	@cached_property
	def 					lowercase__	(self			:			Union[str, Any]   )  ->      Optional[int]:

					"""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 					lowercase__	(self			:			Tuple   )  ->      Dict:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    str          =			VideoMAEForVideoClassification.from_pretrained('''MCG-NJU/videomae-base-finetuned-kinetics'''   ).to(
					    lowerCamelCase_   )

					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			self.default_image_processor
					SCREAMING_SNAKE_CASE	:    str          =			prepare_video()
					SCREAMING_SNAKE_CASE	:    Optional[int]          =			image_processor(lowerCamelCase_,       return_tensors='''pt'''   ).to(lowerCamelCase_   )

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

					# verify the logits
					SCREAMING_SNAKE_CASE	:    int          =			torch.Size((1, 400)   )
					self.assertEqual(outputs.logits.shape,       lowerCamelCase_   )

					SCREAMING_SNAKE_CASE	:    Any          =			torch.tensor([0.3669, -0.0688, -0.2421]   ).to(lowerCamelCase_   )

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






	@slow
	def 					lowercase__	(self			:			Dict   )  ->      str:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short'''   ).to(lowerCamelCase_   )

					SCREAMING_SNAKE_CASE	:    List[Any]          =			self.default_image_processor
					SCREAMING_SNAKE_CASE	:    Tuple          =			prepare_video()
					SCREAMING_SNAKE_CASE	:    int          =			image_processor(lowerCamelCase_,       return_tensors='''pt'''   ).to(lowerCamelCase_   )

					# add boolean mask, indicating which patches to mask
					SCREAMING_SNAKE_CASE	:    int          =			hf_hub_download(repo_id='''hf-internal-testing/bool-masked-pos''',       filename='''bool_masked_pos.pt'''   )
					SCREAMING_SNAKE_CASE	:    List[Any]          =			torch.load(lowerCamelCase_   )

					# forward pass
					with torch.no_grad():
									SCREAMING_SNAKE_CASE	:    Optional[Any]          =			model(**lowerCamelCase_   )

					# verify the logits
					SCREAMING_SNAKE_CASE	:    Dict          =			torch.Size([1, 1408, 1536]   )
					SCREAMING_SNAKE_CASE	:    List[Any]          =			torch.tensor(
					    [[0.7994, 0.9612, 0.8508], [0.7401, 0.8958, 0.8302], [0.5862, 0.7468, 0.7325]],       device=lowerCamelCase_   )
					self.assertEqual(outputs.logits.shape,       lowerCamelCase_   )
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3],       lowerCamelCase_,       atol=1e-4   )   )

					# verify the loss (`config.norm_pix_loss` = `True`)
					SCREAMING_SNAKE_CASE	:    Dict          =			torch.tensor([0.5142],       device=lowerCamelCase_   )
					self.assertTrue(torch.allclose(outputs.loss,       lowerCamelCase_,       atol=1e-4   )   )

					# verify the loss (`config.norm_pix_loss` = `False`)
					SCREAMING_SNAKE_CASE	:    List[str]          =			VideoMAEForPreTraining.from_pretrained('''MCG-NJU/videomae-base-short''',       norm_pix_loss=lowerCamelCase_   ).to(
					    lowerCamelCase_   )

					with torch.no_grad():
									SCREAMING_SNAKE_CASE	:    List[str]          =			model(**lowerCamelCase_   )

					SCREAMING_SNAKE_CASE	:    Any          =			torch.tensor(torch.tensor([0.6469]   ),       device=lowerCamelCase_   )
					self.assertTrue(torch.allclose(outputs.loss,       lowerCamelCase_,       atol=1e-4   )   )








'''simple docstring'''






def    _snake_case  (	A			)		->       int:
							if n == 1 or not isinstance(A					,       A			):
														return 0
							elif n == 2:
														return 1
							else:
														lowerCAmelCase__			  =      [0, 1]
														for i in range(2					,       n + 1			):
																					sequence.append(sequence[i - 1] + sequence[i - 2]			)

														return sequence[n]


def    _snake_case  (	A			)		->       int:
							lowerCAmelCase__			  =      0
							lowerCAmelCase__			  =      2

							while digits < n:
														index += 1
														lowerCAmelCase__			  =      len(str(fibonacci(A			)			)			)

							return index


def    _snake_case  (	A = 1000			)		->       int:
							return fibonacci_digits_index(A			)


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