'''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 lowercase_       :







   """simple docstring"""

   def __init__(      self      :			Any, UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			Tuple=13, UpperCamelCase__      :			Optional[int]=10, UpperCamelCase__      :			Union[str, Any]=3, UpperCamelCase__      :			Optional[Any]=2, UpperCamelCase__      :			Optional[int]=2, UpperCamelCase__      :			int=2, UpperCamelCase__      :			Optional[Any]=True, UpperCamelCase__      :			int=True, UpperCamelCase__      :			Union[str, Any]=32, UpperCamelCase__      :			Dict=5, UpperCamelCase__      :			Union[str, Any]=4, UpperCamelCase__      :			int=37, UpperCamelCase__      :			List[Any]="gelu", UpperCamelCase__      :			List[str]=0.1, UpperCamelCase__      :			int=0.1, UpperCamelCase__      :			Union[str, Any]=10, UpperCamelCase__      :			Dict=0.02, UpperCamelCase__      :			Any=0.9, UpperCamelCase__      :			Dict=None, )  ->			Dict:
        _A    		=  parent
        _A    		=  batch_size
        _A    		=  image_size
        _A    		=  num_channels
        _A    		=  patch_size
        _A    		=  tubelet_size
        _A    		=  num_frames
        _A    		=  is_training
        _A    		=  use_labels
        _A    		=  hidden_size
        _A    		=  num_hidden_layers
        _A    		=  num_attention_heads
        _A    		=  intermediate_size
        _A    		=  hidden_act
        _A    		=  hidden_dropout_prob
        _A    		=  attention_probs_dropout_prob
        _A    		=  type_sequence_label_size
        _A    		=  initializer_range
        _A    		=  mask_ratio
        _A    		=  scope

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

        # use this variable to define bool_masked_pos
        _A    		=  int(mask_ratio * self.seq_length     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			int:
        _A    		=  floats_tensor(
            [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]     )

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

        _A    		=  self.get_config()

        return config, pixel_values, labels
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			List[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=UpperCamelCase__, initializer_range=self.initializer_range, )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			str     )  ->			str:
        _A    		=  VideoMAEModel(config=UpperCamelCase__     )
        model.to(UpperCamelCase__     )
        model.eval()
        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.last_hidden_state.shape, (self.batch_size, self.seq_length, self.hidden_size)     )
   def 	__UpperCAmelCase   (      self      :			Optional[int], UpperCamelCase__      :			str, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Any     )  ->			Union[str, Any]:
        _A    		=  VideoMAEForPreTraining(UpperCamelCase__     )
        model.to(UpperCamelCase__     )
        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
        _A    		=  torch.ones((self.num_masks,)     )
        _A    		=  torch.cat([mask, torch.zeros(self.seq_length - mask.size(0     )     )]     )
        _A    		=  mask.expand(self.batch_size, -1     ).bool()

        _A    		=  model(UpperCamelCase__, UpperCamelCase__     )
        # model only returns predictions for masked patches
        _A    		=  mask.sum().item()
        _A    		=  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      :			str     )  ->			Tuple:
        _A    		=  self.prepare_config_and_inputs()
        _A		,       _A		,       _A    		=  config_and_inputs
        _A    		=  {'pixel_values': pixel_values}
        return config, inputs_dict







@require_torch
class lowercase_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    unittest.TestCase			):







   """simple docstring"""

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

   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Any:
        _A    		=  VideoMAEModelTester(self     )
        _A    		=  ConfigTester(self, config_class=UpperCamelCase__, has_text_modality=UpperCamelCase__, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any], UpperCamelCase__      :			Any, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			str=False     )  ->			List[Any]:
        _A    		=  copy.deepcopy(UpperCamelCase__     )

        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
             _A    		=  torch.ones((self.model_tester.num_masks,)     )
             _A    		=  torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0     )     )]     )
             _A    		=  mask.expand(self.model_tester.batch_size, -1     ).bool()
             _A    		=  bool_masked_pos.to(UpperCamelCase__     )

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

        return inputs_dict
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			int:
        self.config_tester.run_common_tests()
   @unittest.skip(reason='VideoMAE does not use inputs_embeds'     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Tuple:
        pass
   def 	__UpperCAmelCase   (      self      :			str     )  ->			str:
        _A		,       _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             _A    		=  model_class(UpperCamelCase__     )
             self.assertIsInstance(model.get_input_embeddings(), (nn.Module)     )
             _A    		=  model.get_output_embeddings()
             self.assertTrue(x is None or isinstance(UpperCamelCase__, nn.Linear     )     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			List[Any]:
        _A		,       _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

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

             _A    		=  ['pixel_values']
             self.assertListEqual(arg_names[:1], UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			int:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			int:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__     )
   @slow
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Optional[Any]:
        for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _A    		=  VideoMAEModel.from_pretrained(UpperCamelCase__     )
             self.assertIsNotNone(UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Optional[Any]:
        if not self.has_attentions:
             pass

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

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

                  _A    		=  True
                  _A    		=  False
                  _A    		=  True
                  _A    		=  model_class(UpperCamelCase__     )
                  model.to(UpperCamelCase__     )
                  model.eval()
                  with torch.no_grad():
                       _A    		=  model(**self._prepare_for_class(UpperCamelCase__, UpperCamelCase__     )     )
                  _A    		=  outputs.attentions
                  self.assertEqual(len(UpperCamelCase__     ), self.model_tester.num_hidden_layers     )

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

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

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

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

                  _A    		=  outputs.attentions

                  self.assertEqual(len(UpperCamelCase__     ), 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      :			int     )  ->			Dict:
        def check_hidden_states_output(UpperCamelCase__      :			str, UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			str     ):
             _A    		=  model_class(UpperCamelCase__     )
             model.to(UpperCamelCase__     )
             model.eval()

             with torch.no_grad():
                  _A    		=  model(**self._prepare_for_class(UpperCamelCase__, UpperCamelCase__     )     )

             _A    		=  outputs.hidden_states
             _A    		=  self.model_tester.num_hidden_layers + 1
             self.assertEqual(len(UpperCamelCase__     ), UpperCamelCase__     )

             _A    		=  self.model_tester.seq_length - self.model_tester.num_masks
             _A    		=  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], )

        _A		,       _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             _A    		=  True
             check_hidden_states_output(UpperCamelCase__, UpperCamelCase__, UpperCamelCase__     )

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             _A    		=  True

             check_hidden_states_output(UpperCamelCase__, UpperCamelCase__, UpperCamelCase__     )

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






def  _SCREAMING_SNAKE_CASE		(      ):
     _A    		=  hf_hub_download(
         repo_id='hf-internal-testing/spaghetti-video'   ,		filename='eating_spaghetti.npy'   ,		repo_type='dataset'				)
     _A    		=  np.load(__snake_case				)
     return list(__snake_case				)







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







   """simple docstring"""

   @cached_property
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			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 	__UpperCAmelCase   (      self      :			Any     )  ->			Optional[int]:
        _A    		=  VideoMAEForVideoClassification.from_pretrained('MCG-NJU/videomae-base-finetuned-kinetics'     ).to(
            UpperCamelCase__     )

        _A    		=  self.default_image_processor
        _A    		=  prepare_video()
        _A    		=  image_processor(UpperCamelCase__, return_tensors='pt'     ).to(UpperCamelCase__     )

        # forward pass
        with torch.no_grad():
             _A    		=  model(**UpperCamelCase__     )

        # verify the logits
        _A    		=  torch.Size((1, 4_00)     )
        self.assertEqual(outputs.logits.shape, UpperCamelCase__     )

        _A    		=  torch.tensor([0.3_669, -0.0_688, -0.2_421]     ).to(UpperCamelCase__     )

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

   @slow
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			List[Any]:
        _A    		=  VideoMAEForPreTraining.from_pretrained('MCG-NJU/videomae-base-short'     ).to(UpperCamelCase__     )

        _A    		=  self.default_image_processor
        _A    		=  prepare_video()
        _A    		=  image_processor(UpperCamelCase__, return_tensors='pt'     ).to(UpperCamelCase__     )

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

        # forward pass
        with torch.no_grad():
             _A    		=  model(**UpperCamelCase__     )

        # verify the logits
        _A    		=  torch.Size([1, 14_08, 15_36]     )
        _A    		=  torch.tensor(
            [[0.7_994, 0.9_612, 0.8_508], [0.7_401, 0.8_958, 0.8_302], [0.5_862, 0.7_468, 0.7_325]], device=UpperCamelCase__     )
        self.assertEqual(outputs.logits.shape, UpperCamelCase__     )
        self.assertTrue(torch.allclose(outputs.logits[0, :3, :3], UpperCamelCase__, atol=1e-4     )     )

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

        # verify the loss (`config.norm_pix_loss` = `False`)
        _A    		=  VideoMAEForPreTraining.from_pretrained('MCG-NJU/videomae-base-short', norm_pix_loss=UpperCamelCase__     ).to(
            UpperCamelCase__     )

        with torch.no_grad():
             _A    		=  model(**UpperCamelCase__     )

        _A    		=  torch.tensor(torch.tensor([0.6_469]     ), device=UpperCamelCase__     )
        self.assertTrue(torch.allclose(outputs.loss, UpperCamelCase__, atol=1e-4     )     )




'''simple docstring'''






from __future__ import annotations





def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			int | str				):
     _A    		=  str(__snake_case				)
     return n == n[::-1]





def  _SCREAMING_SNAKE_CASE		(      __snake_case							:			int = 1_0_0_0_0_0_0				):
     _A    		=  0

     for i in range(1   ,		__snake_case				):
          if is_palindrome(__snake_case				) and is_palindrome(bin(__snake_case				).split('b'				)[1]				):
               total += i
     return total


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



