'''simple docstring'''






import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
   import jax

   from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel







class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   def __init__(      self      :			str, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Union[str, Any]=13, UpperCamelCase__      :			Tuple=30, UpperCamelCase__      :			Union[str, Any]=2, UpperCamelCase__      :			List[Any]=3, UpperCamelCase__      :			Dict=True, UpperCamelCase__      :			Optional[int]=True, UpperCamelCase__      :			List[Any]=32, UpperCamelCase__      :			Any=5, UpperCamelCase__      :			List[Any]=4, UpperCamelCase__      :			str=37, UpperCamelCase__      :			List[Any]="gelu", UpperCamelCase__      :			Union[str, Any]=0.1, UpperCamelCase__      :			List[str]=0.1, UpperCamelCase__      :			List[str]=10, UpperCamelCase__      :			List[str]=0.02, )  ->			Optional[Any]:
        _A    		=  parent
        _A    		=  batch_size
        _A    		=  image_size
        _A    		=  patch_size
        _A    		=  num_channels
        _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

        # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
        _A    		=  (image_size // patch_size) ** 2
        _A    		=  num_patches + 1
   def 	__UpperCAmelCase   (      self      :			str     )  ->			List[str]:
        _A    		=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

        _A    		=  ViTConfig(
            image_size=self.image_size, patch_size=self.patch_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, is_decoder=lowerCamelCase_, initializer_range=self.initializer_range, )

        return config, pixel_values
   def 	__UpperCAmelCase   (      self      :			List[str], UpperCamelCase__      :			Dict, UpperCamelCase__      :			Optional[Any]     )  ->			List[Any]:
        _A    		=  FlaxViTModel(config=lowerCamelCase_     )
        _A    		=  model(lowerCamelCase_     )
        # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
        _A    		=  (self.image_size, self.image_size)
        _A    		=  (self.patch_size, self.patch_size)
        _A    		=  (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
        self.parent.assertEqual(result.last_hidden_state.shape, (self.batch_size, num_patches + 1, self.hidden_size)     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			str     )  ->			Dict:
        _A    		=  self.type_sequence_label_size
        _A    		=  FlaxViTForImageClassification(config=lowerCamelCase_     )
        _A    		=  model(lowerCamelCase_     )
        self.parent.assertEqual(result.logits.shape, (self.batch_size, self.type_sequence_label_size)     )

        # test greyscale images
        _A    		=  1
        _A    		=  FlaxViTForImageClassification(lowerCamelCase_     )

        _A    		=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
        _A    		=  model(lowerCamelCase_     )

   def 	__UpperCAmelCase   (      self      :			str     )  ->			List[Any]:
        _A    		=  self.prepare_config_and_inputs()
        (
            _A							
        )    		=  config_and_inputs
        _A    		=  {"""pixel_values""": pixel_values}
        return config, inputs_dict







@require_flax
class lowercase_       (		lowercase_    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   (FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			List[Any]:
        _A    		=  FlaxViTModelTester(self     )
        _A    		=  ConfigTester(self, config_class=lowerCamelCase_, has_text_modality=lowerCamelCase_, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Union[str, Any]:
        self.config_tester.run_common_tests()
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Tuple:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Tuple:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Optional[Any]:
        _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

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

             _A    		=  ["""pixel_values"""]
             self.assertListEqual(arg_names[:1], lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Any:
        _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             with self.subTest(model_class.__name__     ):
                  _A    		=  self._prepare_for_class(lowerCamelCase_, lowerCamelCase_     )
                  _A    		=  model_class(lowerCamelCase_     )

                  @jax.jit
                  def model_jitted(UpperCamelCase__      :			Any, **UpperCamelCase__      :			Optional[Any]     ):
                       return model(pixel_values=lowerCamelCase_, **lowerCamelCase_     )

                  with self.subTest('JIT Enabled'     ):
                       _A    		=  model_jitted(**lowerCamelCase_     ).to_tuple()

                  with self.subTest('JIT Disabled'     ):
                       with jax.disable_jit():
                            _A    		=  model_jitted(**lowerCamelCase_     ).to_tuple()

                  self.assertEqual(len(lowerCamelCase_     ), len(lowerCamelCase_     )     )
                  for jitted_output, output in zip(lowerCamelCase_, lowerCamelCase_     ):
                       self.assertEqual(jitted_output.shape, output.shape     )

   @slow
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			List[Any]:



        for model_class_name in self.all_model_classes:
             _A    		=  model_class_name.from_pretrained('google/vit-base-patch16-224'     )
             _A    		=  model(np.ones((1, 3, 2_24, 2_24)     )     )
             self.assertIsNotNone(lowerCamelCase_     )










'''simple docstring'''




def 		__A		(  lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				str		=			1  # To kept the Calculated Value
		# Since C(n, k) = C(n, n-k)
		if k > (n - k):
				SCREAMING_SNAKE_CASE :				Dict		=			n - k
		# Calculate C(n,k)
		for i in range(lowerCamelCase_	):
				result *= n - i
				result //= i + 1
		return result



def 		__A		(  lowerCamelCase_	):


		"""simple docstring"""



		return binomial_coefficient(2 * node_count			,			lowerCamelCase_	) // (node_count + 1)



def 		__A		(  lowerCamelCase_	):


		"""simple docstring"""



		if n < 0:
				raise ValueError("""factorial() not defined for negative values"""	)
		SCREAMING_SNAKE_CASE :				Dict		=			1
		for i in range(1			,			n + 1	):
				result *= i
		return result



def 		__A		(  lowerCamelCase_	):


		"""simple docstring"""



		return catalan_number(lowerCamelCase_	) * factorial(lowerCamelCase_	)


if __name__ == "__main__":
							__UpperCAmelCase            =       int(input("""Enter the number of nodes: """).strip() or 0)
							if node_count <= 0:
														raise ValueError("""We need some nodes to work with.""")
							print(
							    f'''Given {node_count} nodes, there are {binary_tree_count(node_count)} '''
							    f'''binary trees and {catalan_number(node_count)} binary search trees.'''
							)



