


'''simple docstring'''



import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VivitConfig
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


if is_torch_available():
       import torch
       from torch import nn

       from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VivitForVideoClassification, VivitModel
       from transformers.models.vivit.modeling_vivit import VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from transformers import VivitImageProcessor





class        UpperCAmelCase_  :





    """simple docstring"""






    def __init__(							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_=2      ,					SCREAMING_SNAKE_CASE_=True      ,					SCREAMING_SNAKE_CASE_=True      ,					SCREAMING_SNAKE_CASE_=10      ,					SCREAMING_SNAKE_CASE_=10      ,					SCREAMING_SNAKE_CASE_=8      ,					SCREAMING_SNAKE_CASE_=[2, 4, 4]      ,					SCREAMING_SNAKE_CASE_=3      ,					SCREAMING_SNAKE_CASE_=7_68      ,					SCREAMING_SNAKE_CASE_=5      ,					SCREAMING_SNAKE_CASE_=4      ,					SCREAMING_SNAKE_CASE_=37      ,					SCREAMING_SNAKE_CASE_="gelu_fast"      ,					SCREAMING_SNAKE_CASE_=0.0      ,					SCREAMING_SNAKE_CASE_=0.0      ,					SCREAMING_SNAKE_CASE_=0.0_2      ,					SCREAMING_SNAKE_CASE_=1E-06      ,					SCREAMING_SNAKE_CASE_=True      ,					SCREAMING_SNAKE_CASE_=None      ,					)    ->					List[str]:
         __lowerCamelCase       :     List[Any]        =		parent
         __lowerCamelCase       :     List[str]        =		batch_size
         __lowerCamelCase       :     Optional[Any]        =		is_training
         __lowerCamelCase       :     Dict        =		use_labels
         __lowerCamelCase       :     Union[str, Any]        =		num_labels
         __lowerCamelCase       :     Tuple        =		image_size
         __lowerCamelCase       :     Any        =		num_frames
         __lowerCamelCase       :     List[str]        =		tubelet_size
         __lowerCamelCase       :     int        =		num_channels
         __lowerCamelCase       :     Dict        =		hidden_size
         __lowerCamelCase       :     Optional[Any]        =		num_hidden_layers
         __lowerCamelCase       :     Optional[Any]        =		num_attention_heads
         __lowerCamelCase       :     int        =		intermediate_size
         __lowerCamelCase       :     Optional[int]        =		hidden_act
         __lowerCamelCase       :     int        =		hidden_dropout_prob
         __lowerCamelCase       :     str        =		attention_probs_dropout_prob
         __lowerCamelCase       :     Union[str, Any]        =		initializer_range
         __lowerCamelCase       :     Any        =		layer_norm_eps
         __lowerCamelCase       :     Any        =		qkv_bias
         __lowerCamelCase       :     Optional[Any]        =		scope

         __lowerCamelCase       :     str        =		(
             (self.image_size // self.tubelet_size[2])
             * (self.image_size // self.tubelet_size[1])
             * (self.num_frames // self.tubelet_size[0])
         ) + 1  # CLS token







    def 				lowercase_    (							self     )    ->					List[str]:
         __lowerCamelCase       :     Optional[int]        =		floats_tensor(
             [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]     )

         __lowerCamelCase       :     List[str]        =		None
         if self.use_labels:
              __lowerCamelCase       :     Union[str, Any]        =		ids_tensor([self.batch_size]      ,					self.num_labels     )

         __lowerCamelCase       :     Dict        =		self.get_config()

         return config, pixel_values, labels







    def 				lowercase_    (							self     )    ->					Union[str, Any]:
         __lowerCamelCase       :     Optional[Any]        =		VivitConfig(
             num_frames=self.num_frames      ,					image_size=self.image_size      ,					tubelet_size=self.tubelet_size      ,					num_channels=self.num_channels      ,					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      ,					initializer_range=self.initializer_range      ,					layer_norm_eps=self.layer_norm_eps      ,					qkv_bias=self.qkv_bias      ,					)
         __lowerCamelCase       :     Union[str, Any]        =		self.num_labels
         return config







    def 				lowercase_    (							self      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_     )    ->					Dict:
         __lowerCamelCase       :     Tuple        =		VivitModel(config=__SCREAMING_SNAKE_CASE     )
         model.to(__SCREAMING_SNAKE_CASE     )
         model.eval()
         __lowerCamelCase       :     List[Any]        =		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_     )    ->					Tuple:
         __lowerCamelCase       :     int        =		VivitForVideoClassification(__SCREAMING_SNAKE_CASE     )
         model.to(__SCREAMING_SNAKE_CASE     )
         model.eval()

         __lowerCamelCase       :     Any        =		model(__SCREAMING_SNAKE_CASE     )

         # verify the logits shape
         __lowerCamelCase       :     Dict        =		torch.Size((self.batch_size, self.num_labels)     )
         self.parent.assertEqual(result.logits.shape      ,					__SCREAMING_SNAKE_CASE     )







    def 				lowercase_    (							self     )    ->					Optional[int]:
         __lowerCamelCase       :     Optional[Any]        =		self.prepare_config_and_inputs()
         __lowerCamelCase    ,	__lowerCamelCase    ,	__lowerCamelCase       :     Dict        =		config_and_inputs
         __lowerCamelCase       :     Tuple        =		{'pixel_values': pixel_values}
         return config, inputs_dict







@require_torch
class        UpperCAmelCase_  (UpperCamelCase_ ,		unittest.TestCase  ):





    """simple docstring"""






    lowerCamelCase  : Tuple												=      (VivitModel, VivitForVideoClassification) if is_torch_available() else ()

    lowerCamelCase  : Any												=      False
    lowerCamelCase  : Union[str, Any]												=      False
    lowerCamelCase  : List[Any]												=      False
    lowerCamelCase  : Dict												=      False







    def 				lowercase_    (							self     )    ->					Any:
         __lowerCamelCase       :     Any        =		VivitModelTester(self     )
         __lowerCamelCase       :     List[Any]        =		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     )    ->					Optional[Any]:
         __lowerCamelCase       :     int        =		copy.deepcopy(__SCREAMING_SNAKE_CASE     )

         if return_labels:
              if model_class in get_values(__SCREAMING_SNAKE_CASE     ):
                   __lowerCamelCase       :     List[Any]        =		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='Vivit does not use inputs_embeds'     )
    def 				lowercase_    (							self     )    ->					Tuple:
         pass







    def 				lowercase_    (							self     )    ->					Tuple:
         __lowerCamelCase    ,	__lowerCamelCase       :     int        =		self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              __lowerCamelCase       :     List[str]        =		model_class(__SCREAMING_SNAKE_CASE     )
              self.assertIsInstance(model.get_input_embeddings()      ,					(nn.Module)     )
              __lowerCamelCase       :     Optional[int]        =		model.get_output_embeddings()
              self.assertTrue(x is None or isinstance(__SCREAMING_SNAKE_CASE      ,					nn.Linear     )     )







    def 				lowercase_    (							self     )    ->					Tuple:
         __lowerCamelCase    ,	__lowerCamelCase       :     Optional[Any]        =		self.model_tester.prepare_config_and_inputs_for_common()

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

              __lowerCamelCase       :     List[Any]        =		['pixel_values', 'head_mask']
              self.assertListEqual(arg_names[:2]      ,					__SCREAMING_SNAKE_CASE     )







    def 				lowercase_    (							self     )    ->					int:
         __lowerCamelCase       :     str        =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE     )







    def 				lowercase_    (							self     )    ->					Union[str, Any]:
         __lowerCamelCase       :     Optional[Any]        =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_video_classification(*__SCREAMING_SNAKE_CASE     )







    @slow
    def 				lowercase_    (							self     )    ->					Union[str, Any]:
         for model_name in VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              __lowerCamelCase       :     Any        =		VivitModel.from_pretrained(__SCREAMING_SNAKE_CASE     )
              self.assertIsNotNone(__SCREAMING_SNAKE_CASE     )







    def 				lowercase_    (							self     )    ->					int:
         __lowerCamelCase    ,	__lowerCamelCase       :     Optional[Any]        =		self.model_tester.prepare_config_and_inputs_for_common()
         __lowerCamelCase       :     int        =		True

         for model_class in self.all_model_classes:
              __lowerCamelCase       :     Optional[Any]        =		self.model_tester.seq_length

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

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

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

              __lowerCamelCase       :     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 				lowercase_    (							self     )    ->					Optional[Any]:
         def check_hidden_states_output(SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_      ,					SCREAMING_SNAKE_CASE_     ):
              __lowerCamelCase       :     int        =		model_class(__SCREAMING_SNAKE_CASE     )
              model.to(__SCREAMING_SNAKE_CASE     )
              model.eval()

              with torch.no_grad():
                   __lowerCamelCase       :     Tuple        =		model(**self._prepare_for_class(__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE     )     )

              __lowerCamelCase       :     Optional[int]        =		outputs.hidden_states
              __lowerCamelCase       :     str        =		self.model_tester.num_hidden_layers + 1
              self.assertEqual(len(__SCREAMING_SNAKE_CASE     )      ,					__SCREAMING_SNAKE_CASE     )

              __lowerCamelCase       :     Any        =		self.model_tester.seq_length

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

         __lowerCamelCase    ,	__lowerCamelCase       :     List[str]        =		self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              __lowerCamelCase       :     Tuple        =		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"]
              __lowerCamelCase       :     Optional[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 				lowercase_    (							self     )    ->					Optional[int]:
         pass







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





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





    """simple docstring"""






    @cached_property
    def 				lowercase_    (							self     )    ->					Any:
         return VivitImageProcessor() if is_vision_available() else None







    @slow
    def 				lowercase_    (							self     )    ->					Dict:
         __lowerCamelCase       :     Union[str, Any]        =		VivitForVideoClassification.from_pretrained('google/vivit-b-16x2-kinetics400'     ).to(__SCREAMING_SNAKE_CASE     )

         __lowerCamelCase       :     List[str]        =		self.default_image_processor
         __lowerCamelCase       :     List[str]        =		prepare_video()
         __lowerCamelCase       :     Any        =		image_processor(__SCREAMING_SNAKE_CASE      ,					return_tensors='pt'     ).to(__SCREAMING_SNAKE_CASE     )

         # forward pass
         with torch.no_grad():
              __lowerCamelCase       :     Any        =		model(**__SCREAMING_SNAKE_CASE     )

         # verify the logits
         __lowerCamelCase       :     str        =		torch.Size((1, 4_00)     )
         self.assertEqual(outputs.logits.shape      ,					__SCREAMING_SNAKE_CASE     )

         # taken from original model
         __lowerCamelCase       :     Tuple        =		torch.tensor([-1.0_5_4_3, 2.0_7_6_4, -0.2_1_0_4, 0.4_4_3_9, -0.9_6_5_8]     ).to(__SCREAMING_SNAKE_CASE     )

         self.assertTrue(torch.allclose(outputs.logits[0, :5]      ,					__SCREAMING_SNAKE_CASE      ,					atol=1E-4     )     )










'''simple docstring'''



import math
from itertools import permutations



def       UpperCAmelCase__ (     UpperCAmelCase_   :    int							)					->		bool:

     if 1 < number < 4:
          # 2 and 3 are primes
          return True
     elif number < 2 or number % 2 == 0 or number % 3 == 0:
          # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
          return False

     # All primes number are in format of 6k +/- 1
     for i in range(5				,   int(math.sqrt(UpperCAmelCase_							) + 1							)				,   6							):
          if number % i == 0 or number % (i + 2) == 0:
               return False
     return True



def       UpperCAmelCase__ (     UpperCAmelCase_   :    int				,   UpperCAmelCase_   :    list							)					->		bool:
     __lowerCamelCase    ,	__lowerCamelCase       :     str        =		0, len(UpperCAmelCase_							) - 1
     while left <= right:
          __lowerCamelCase       :     Optional[Any]        =		(left + right) // 2
          if prime_list[middle] == target:
               return True
          elif prime_list[middle] < target:
               __lowerCamelCase       :     Union[str, Any]        =		middle + 1
          else:
               __lowerCamelCase       :     Union[str, Any]        =		middle - 1

     return False



def       UpperCAmelCase__ (     )					->		List[str]:
     __lowerCamelCase       :     Tuple        =		[n for n in range(10_01				,   1_00_00				,   2							) if is_prime(UpperCAmelCase_							)]
     __lowerCamelCase       :     Any        =		[]

     for number in prime_list:
          __lowerCamelCase       :     Optional[int]        =		[]

          for prime_member in permutations(list(str(UpperCAmelCase_							)							)							):
               __lowerCamelCase       :     int        =		int(''.join(UpperCAmelCase_							)							)

               if prime % 2 == 0:
                    continue

               if search(UpperCAmelCase_				,   UpperCAmelCase_							):
                    tmp_numbers.append(UpperCAmelCase_							)

          tmp_numbers.sort()
          if len(UpperCAmelCase_							) >= 3:
               candidates.append(UpperCAmelCase_							)

     __lowerCamelCase       :     int        =		[]
     for candidate in candidates:
          __lowerCamelCase       :     Union[str, Any]        =		len(UpperCAmelCase_							)
          __lowerCamelCase       :     Optional[Any]        =		False

          for i in range(UpperCAmelCase_							):
               for j in range(i + 1				,   UpperCAmelCase_							):
                    for k in range(j + 1				,   UpperCAmelCase_							):
                         if (
                             abs(candidate[i] - candidate[j]							)
                             == abs(candidate[j] - candidate[k]							)
                             and len({candidate[i], candidate[j], candidate[k]}							) == 3
                         ):
                              passed.append(
                                  sorted([candidate[i], candidate[j], candidate[k]]							)							)
                              __lowerCamelCase       :     List[str]        =		True

                         if found:
                              break
                    if found:
                         break
               if found:
                    break

     __lowerCamelCase       :     List[Any]        =		set()
     for seq in passed:
          answer.add(''.join([str(UpperCAmelCase_							) for i in seq]							)							)

     return max(int(UpperCAmelCase_							) for x in answer							)


if __name__ == "__main__":
      print(solution())






