






'''simple docstring'''




import unittest

import numpy as np
import requests

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
    import torch

    from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
    lowerCamelCase_												=					False

if is_vision_available():
    from PIL import Image

    from transformers import PixaStructImageProcessor

class    _UpperCAmelCase			(     unittest.TestCase						):




   """simple docstring"""

   def __init__(		self :	Any      ,      __UpperCAmelCase :	Union[str, Any]      ,      __UpperCAmelCase :	Dict=7      ,      __UpperCAmelCase :	Union[str, Any]=3      ,      __UpperCAmelCase :	Dict=18      ,      __UpperCAmelCase :	str=30      ,      __UpperCAmelCase :	Dict=400      ,      __UpperCAmelCase :	Optional[Any]=None      ,      __UpperCAmelCase :	Optional[Any]=True      ,      __UpperCAmelCase :	List[Any]=True      ,      __UpperCAmelCase :	Tuple=None      ,      ):





         '''simple docstring'''





         _A			     =	size if size is not None else {"height": 20, "width": 20}
         _A			     =	parent
         _A			     =	batch_size
         _A			     =	num_channels
         _A			     =	image_size
         _A			     =	min_resolution
         _A			     =	max_resolution
         _A			     =	size
         _A			     =	do_normalize
         _A			     =	do_convert_rgb
         _A			     =	[512, 1024, 2048, 4096]
         _A			     =	patch_size if patch_size is not None else {"height": 16, "width": 16}

   def 						lowerCAmelCase (		self :	Tuple		):





         '''simple docstring'''





         return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}

   def 						lowerCAmelCase (		self :	str		):





         '''simple docstring'''





         _A			     =	"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg"
         _A			     =	Image.open(requests.get(__UpperCAmelCase      ,      stream=__UpperCAmelCase		).raw		).convert("RGB"		)
         return raw_image





@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11							,    reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''							,    )
@require_torch
@require_vision
class    _UpperCAmelCase			(     snake_case_							,    unittest.TestCase						):




   """simple docstring"""

   snake_case    				=						PixaStructImageProcessor if is_vision_available() else None

   def 						lowerCAmelCase (		self :	str		):





         '''simple docstring'''





         _A			     =	PixaStructImageProcessingTester(self		)

   @property
   def 						lowerCAmelCase (		self :	Union[str, Any]		):





         '''simple docstring'''





         return self.image_processor_tester.prepare_image_processor_dict()

   def 						lowerCAmelCase (		self :	Dict		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(__UpperCAmelCase      ,      "do_normalize"		)		)
         self.assertTrue(hasattr(__UpperCAmelCase      ,      "do_convert_rgb"		)		)

   def 						lowerCAmelCase (		self :	Any		):





         '''simple docstring'''





         _A			     =	self.image_processor_tester.prepare_dummy_image()

         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         _A			     =	2048

         _A			     =	image_processor(__UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		)
         self.assertTrue(torch.allclose(inputs.flattened_patches.mean()      ,      torch.tensor(0.0606		)      ,      atol=1E-3      ,      rtol=1E-3		)		)

   def 						lowerCAmelCase (		self :	Any		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _A			     =	prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__UpperCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase      ,      Image.Image		)

         # Test not batched input
         _A			     =	(
             (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
             * self.image_processor_tester.num_channels
         ) + 2

         for max_patch in self.image_processor_tester.max_patches:
               # Test not batched input
               _A			     =	image_processor(
                   image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (1, max_patch, expected_hidden_dim)      ,      )

               # Test batched
               _A			     =	image_processor(
                   __UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)      ,      )

   def 						lowerCAmelCase (		self :	Dict		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _A			     =	prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__UpperCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase      ,      Image.Image		)

         # Test not batched input
         _A			     =	(
             (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
             * self.image_processor_tester.num_channels
         ) + 2

         _A			     =	True

         for max_patch in self.image_processor_tester.max_patches:
               # Test not batched input
               with self.assertRaises(__UpperCAmelCase		):
                     _A			     =	image_processor(
                         image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches

               _A			     =	"Hello"

               _A			     =	image_processor(
                   image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase      ,      header_text=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (1, max_patch, expected_hidden_dim)      ,      )

               # Test batched
               _A			     =	image_processor(
                   __UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase      ,      header_text=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)      ,      )

   def 						lowerCAmelCase (		self :	List[Any]		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         # create random numpy tensors
         _A			     =	prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__UpperCAmelCase      ,      numpify=__UpperCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase      ,      np.ndarray		)

         _A			     =	(
             (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
             * self.image_processor_tester.num_channels
         ) + 2

         for max_patch in self.image_processor_tester.max_patches:
               # Test not batched input
               _A			     =	image_processor(
                   image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (1, max_patch, expected_hidden_dim)      ,      )

               # Test batched
               _A			     =	image_processor(
                   __UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)      ,      )

   def 						lowerCAmelCase (		self :	List[str]		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         # create random PyTorch tensors
         _A			     =	prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__UpperCAmelCase      ,      torchify=__UpperCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase      ,      torch.Tensor		)

         # Test not batched input
         _A			     =	(
             (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
             * self.image_processor_tester.num_channels
         ) + 2

         for max_patch in self.image_processor_tester.max_patches:
               # Test not batched input
               _A			     =	image_processor(
                   image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (1, max_patch, expected_hidden_dim)      ,      )

               # Test batched
               _A			     =	image_processor(
                   __UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)      ,      )





@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11							,    reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''							,    )
@require_torch
@require_vision
class    _UpperCAmelCase			(     snake_case_							,    unittest.TestCase						):




   """simple docstring"""

   snake_case    				=						PixaStructImageProcessor if is_vision_available() else None

   def 						lowerCAmelCase (		self :	str		):





         '''simple docstring'''





         _A			     =	PixaStructImageProcessingTester(self      ,      num_channels=4		)
         _A			     =	3

   @property
   def 						lowerCAmelCase (		self :	str		):





         '''simple docstring'''





         return self.image_processor_tester.prepare_image_processor_dict()

   def 						lowerCAmelCase (		self :	Optional[int]		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(__UpperCAmelCase      ,      "do_normalize"		)		)
         self.assertTrue(hasattr(__UpperCAmelCase      ,      "do_convert_rgb"		)		)

   def 						lowerCAmelCase (		self :	str		):





         '''simple docstring'''





         _A			     =	self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _A			     =	prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=__UpperCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase      ,      Image.Image		)

         # Test not batched input
         _A			     =	(
             (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
             * (self.image_processor_tester.num_channels - 1)
         ) + 2

         for max_patch in self.image_processor_tester.max_patches:
               # Test not batched input
               _A			     =	image_processor(
                   image_inputs[0]      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (1, max_patch, expected_hidden_dim)      ,      )

               # Test batched
               _A			     =	image_processor(
                   __UpperCAmelCase      ,      return_tensors="pt"      ,      max_patches=__UpperCAmelCase		).flattened_patches
               self.assertEqual(
                   encoded_images.shape      ,      (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)      ,      )






'''simple docstring'''




def 	UpperCamelCase_							(					_UpperCAmelCase  :      int			,	_UpperCAmelCase  :      int    )    ->    int:


       """simple docstring"""







       _UpperCAmelCase     :  List[str]							      =    1  # To kept the Calculated Value
       # Since C(n, k) = C(n, n-k)
       if k > (n - k):
              _UpperCAmelCase     :  Any							      =    n - k
       # Calculate C(n,k)
       for i in range(_UpperCAmelCase    ):
              result *= n - i
              result //= i + 1
       return result

def 	UpperCamelCase_							(					_UpperCAmelCase  :      int    )    ->    int:


       """simple docstring"""







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

def 	UpperCamelCase_							(					_UpperCAmelCase  :      int    )    ->    int:


       """simple docstring"""







       if n < 0:
              raise ValueError("factorial() not defined for negative values"    )
       _UpperCAmelCase     :  List[str]							      =    1
       for i in range(1			,	n + 1    ):
              result *= i
       return result

def 	UpperCamelCase_							(					_UpperCAmelCase  :      int    )    ->    int:


       """simple docstring"""







       return catalan_number(_UpperCAmelCase    ) * factorial(_UpperCAmelCase    )


if __name__ == "__main__":
  __SCREAMING_SNAKE_CASE       :     Dict     =  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.'
  )

