'''simple docstring'''






import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest







class lowercase_       (		lowercase_			):







   """simple docstring"""

   __lowerCAmelCase         =   (DPMSolverSinglestepScheduler,)
   __lowerCAmelCase         =   (("num_inference_steps", 2_5),)
   def 	__UpperCAmelCase   (      self      :			Any, **UpperCamelCase__      :			List[Any]     )  ->			str:
        _A    		=  {
            """num_train_timesteps""": 10_00,
            """beta_start""": 0.0_001,
            """beta_end""": 0.02,
            """beta_schedule""": """linear""",
            """solver_order""": 2,
            """prediction_type""": """epsilon""",
            """thresholding""": False,
            """sample_max_value""": 1.0,
            """algorithm_type""": """dpmsolver++""",
            """solver_type""": """midpoint""",
            """lambda_min_clipped""": -float('inf'     ),
            """variance_type""": None,
        }

        config.update(**lowerCamelCase_     )
        return config
   def 	__UpperCAmelCase   (      self      :			Any, UpperCamelCase__      :			List[str]=0, **UpperCamelCase__      :			Optional[Any]     )  ->			Tuple:
        _A    		=  dict(self.forward_default_kwargs     )
        _A    		=  kwargs.pop('num_inference_steps', lowerCamelCase_     )
        _A    		=  self.dummy_sample
        _A    		=  0.1 * sample
        _A    		=  [residual + 0.2, residual + 0.15, residual + 0.10]

        for scheduler_class in self.scheduler_classes:
             _A    		=  self.get_scheduler_config(**lowerCamelCase_     )
             _A    		=  scheduler_class(**lowerCamelCase_     )
             scheduler.set_timesteps(lowerCamelCase_     )
             # copy over dummy past residuals
             _A    		=  dummy_past_residuals[: scheduler.config.solver_order]

             with tempfile.TemporaryDirectory() as tmpdirname:
                  scheduler.save_config(lowerCamelCase_     )
                  _A    		=  scheduler_class.from_pretrained(lowerCamelCase_     )
                  new_scheduler.set_timesteps(lowerCamelCase_     )
                  # copy over dummy past residuals
                  _A    		=  dummy_past_residuals[: new_scheduler.config.solver_order]

             _A    		=  sample, sample
             for t in range(lowerCamelCase_, time_step + scheduler.config.solver_order + 1     ):
                  _A    		=  scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_, **lowerCamelCase_     ).prev_sample
                  _A    		=  new_scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_, **lowerCamelCase_     ).prev_sample

                  assert torch.sum(torch.abs(output - new_output     )     ) < 1e-5, "Scheduler outputs are not identical"
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Tuple:
        pass
   def 	__UpperCAmelCase   (      self      :			str, UpperCamelCase__      :			Union[str, Any]=0, **UpperCamelCase__      :			Tuple     )  ->			Any:
        _A    		=  dict(self.forward_default_kwargs     )
        _A    		=  kwargs.pop('num_inference_steps', lowerCamelCase_     )
        _A    		=  self.dummy_sample
        _A    		=  0.1 * sample
        _A    		=  [residual + 0.2, residual + 0.15, residual + 0.10]

        for scheduler_class in self.scheduler_classes:
             _A    		=  self.get_scheduler_config()
             _A    		=  scheduler_class(**lowerCamelCase_     )
             scheduler.set_timesteps(lowerCamelCase_     )

             # copy over dummy past residuals (must be after setting timesteps)
             _A    		=  dummy_past_residuals[: scheduler.config.solver_order]

             with tempfile.TemporaryDirectory() as tmpdirname:
                  scheduler.save_config(lowerCamelCase_     )
                  _A    		=  scheduler_class.from_pretrained(lowerCamelCase_     )
                  # copy over dummy past residuals
                  new_scheduler.set_timesteps(lowerCamelCase_     )

                  # copy over dummy past residual (must be after setting timesteps)
                  _A    		=  dummy_past_residuals[: new_scheduler.config.solver_order]

             _A    		=  scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_, **lowerCamelCase_     ).prev_sample
             _A    		=  new_scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_, **lowerCamelCase_     ).prev_sample

             assert torch.sum(torch.abs(output - new_output     )     ) < 1e-5, "Scheduler outputs are not identical"
   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			int=None, **UpperCamelCase__      :			Union[str, Any]     )  ->			Optional[int]:



        if scheduler is None:
             _A    		=  self.scheduler_classes[0]
             _A    		=  self.get_scheduler_config(**lowerCamelCase_     )
             _A    		=  scheduler_class(**lowerCamelCase_     )

        _A    		=  self.scheduler_classes[0]
        _A    		=  self.get_scheduler_config(**lowerCamelCase_     )
        _A    		=  scheduler_class(**lowerCamelCase_     )

        _A    		=  10
        _A    		=  self.dummy_model()
        _A    		=  self.dummy_sample_deter
        scheduler.set_timesteps(lowerCamelCase_     )

        for i, t in enumerate(scheduler.timesteps     ):
             _A    		=  model(lowerCamelCase_, lowerCamelCase_     )
             _A    		=  scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_     ).prev_sample

        return sample
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Dict:
        _A    		=  DPMSolverSinglestepScheduler(**self.get_scheduler_config()     )
        _A    		=  50
        _A    		=  self.dummy_model()
        _A    		=  self.dummy_sample_deter
        scheduler.set_timesteps(lowerCamelCase_     )

        # make sure that the first t is uneven
        for i, t in enumerate(scheduler.timesteps[3:]     ):
             _A    		=  model(lowerCamelCase_, lowerCamelCase_     )
             _A    		=  scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_     ).prev_sample

        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.2_574     ) < 1e-3
   def 	__UpperCAmelCase   (      self      :			str     )  ->			int:



        for timesteps in [25, 50, 1_00, 9_99, 10_00]:
             self.check_over_configs(num_train_timesteps=lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Dict:
        _A    		=  DPMSolverSinglestepScheduler(**self.get_scheduler_config()     )
        _A    		=  self.full_loop(scheduler=lowerCamelCase_     )
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.2_791     ) < 1e-3

        _A    		=  DEISMultistepScheduler.from_config(scheduler.config     )
        _A    		=  DPMSolverMultistepScheduler.from_config(scheduler.config     )
        _A    		=  UniPCMultistepScheduler.from_config(scheduler.config     )
        _A    		=  DPMSolverSinglestepScheduler.from_config(scheduler.config     )

        _A    		=  self.full_loop(scheduler=lowerCamelCase_     )
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.2_791     ) < 1e-3
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Any:
        self.check_over_configs(thresholding=lowerCamelCase_     )
        for order in [1, 2, 3]:
             for solver_type in ["midpoint", "heun"]:
                  for threshold in [0.5, 1.0, 2.0]:
                       for prediction_type in ["epsilon", "sample"]:
                            self.check_over_configs(
                                thresholding=lowerCamelCase_, prediction_type=lowerCamelCase_, sample_max_value=lowerCamelCase_, algorithm_type='dpmsolver++', solver_order=lowerCamelCase_, solver_type=lowerCamelCase_, )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Any:



        for prediction_type in ["epsilon", "v_prediction"]:
             self.check_over_configs(prediction_type=lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Dict:



        for algorithm_type in ["dpmsolver", "dpmsolver++"]:
             for solver_type in ["midpoint", "heun"]:
                  for order in [1, 2, 3]:
                       for prediction_type in ["epsilon", "sample"]:
                            self.check_over_configs(
                                solver_order=lowerCamelCase_, solver_type=lowerCamelCase_, prediction_type=lowerCamelCase_, algorithm_type=lowerCamelCase_, )
                            _A    		=  self.full_loop(
                                solver_order=lowerCamelCase_, solver_type=lowerCamelCase_, prediction_type=lowerCamelCase_, algorithm_type=lowerCamelCase_, )
                            assert not torch.isnan(lowerCamelCase_     ).any(), "Samples have nan numbers"
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Tuple:
        self.check_over_configs(lower_order_final=lowerCamelCase_     )
        self.check_over_configs(lower_order_final=lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Tuple:
        self.check_over_configs(lambda_min_clipped=-float('inf'     )     )
        self.check_over_configs(lambda_min_clipped=-5.1     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			str:
        self.check_over_configs(variance_type=lowerCamelCase_     )
        self.check_over_configs(variance_type='learned_range'     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Optional[int]:



        for num_inference_steps in [1, 2, 3, 5, 10, 50, 1_00, 9_99, 10_00]:
             self.check_over_forward(num_inference_steps=lowerCamelCase_, time_step=0     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			List[Any]:
        _A    		=  self.full_loop()
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.2_791     ) < 1e-3
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Union[str, Any]:
        _A    		=  self.full_loop(use_karras_sigmas=lowerCamelCase_     )
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.2_248     ) < 1e-3
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			List[str]:
        _A    		=  self.full_loop(prediction_type='v_prediction'     )
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.1_453     ) < 1e-3
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Optional[int]:
        _A    		=  self.full_loop(prediction_type='v_prediction', use_karras_sigmas=lowerCamelCase_     )
        _A    		=  torch.mean(torch.abs(lowerCamelCase_     )     )

        assert abs(result_mean.item() - 0.0_649     ) < 1e-3

   def 	__UpperCAmelCase   (      self      :			str     )  ->			str:
        _A    		=  self.scheduler_classes[0]
        _A    		=  self.get_scheduler_config(thresholding=lowerCamelCase_, dynamic_thresholding_ratio=0     )
        _A    		=  scheduler_class(**lowerCamelCase_     )

        _A    		=  10
        _A    		=  self.dummy_model()
        _A    		=  self.dummy_sample_deter.half()
        scheduler.set_timesteps(lowerCamelCase_     )

        for i, t in enumerate(scheduler.timesteps     ):
             _A    		=  model(lowerCamelCase_, lowerCamelCase_     )
             _A    		=  scheduler.step(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_     ).prev_sample

        assert sample.dtype == torch.floataa










'''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.'''
							)



