


"""simple docstring"""






import gc
import unittest

import numpy as np
import torch
from torch.backends.cuda import sdp_kernel

from diffusers import (
    CMStochasticIterativeScheduler,
    ConsistencyModelPipeline,
    UNetaDModel,
)
from diffusers.utils import randn_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_a, require_torch_gpu

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


class     __lowerCamelCase  (					a__  ,					unittest.TestCase				):

     '''simple docstring'''
     A_       :	str    =		ConsistencyModelPipeline
     A_       :	List[Any]    =		UNCONDITIONAL_IMAGE_GENERATION_PARAMS
     A_       :	Union[str, Any]    =		UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS

     # Override required_optional_params to remove num_images_per_prompt
     A_       :	Union[str, Any]    =		frozenset(
         [
             'num_inference_steps',
             'generator',
             'latents',
             'output_type',
             'return_dict',
             'callback',
             'callback_steps',
         ]				)


     @property
     def 							_UpperCAmelCase      (      self							)       ->							str:
          _a    	=				UNetaDModel.from_pretrained(
              '''diffusers/consistency-models-test'''    ,				subfolder='''test_unet'''    ,				)
          return unet


     @property
     def 							_UpperCAmelCase      (      self							)       ->							List[str]:
          _a    	=				UNetaDModel.from_pretrained(
              '''diffusers/consistency-models-test'''    ,				subfolder='''test_unet_class_cond'''    ,				)
          return unet


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase=False							)       ->							List[Any]:
          if class_cond:
               _a    	=				self.dummy_cond_unet
          else:
               _a    	=				self.dummy_uncond_unet

          # Default to CM multistep sampler
          _a    	=				CMStochasticIterativeScheduler(
              num_train_timesteps=40    ,				sigma_min=0.002    ,				sigma_max=80.0    ,				)

          _a    	=				{
              '''unet''': unet,
              '''scheduler''': scheduler,
          }

          return components


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=0							)       ->							Tuple:
          if str(__UpperCAmelCase							).startswith('''mps'''							):
               _a    	=				torch.manual_seed(__UpperCAmelCase							)
          else:
               _a    	=				torch.Generator(device=__UpperCAmelCase							).manual_seed(__UpperCAmelCase							)

          _a    	=				{
              '''batch_size''': 1,
              '''num_inference_steps''': None,
              '''timesteps''': [22, 0],
              '''generator''': generator,
              '''output_type''': '''np''',
          }

          return inputs


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator
          _a    	=				self.get_dummy_components()
          _a    	=				ConsistencyModelPipeline(**__UpperCAmelCase							)
          _a    	=				pipe.to(__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_dummy_inputs(__UpperCAmelCase							)
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 32, 32, 3)

          _a    	=				image[0, -3:, -3:, -1]
          _a    	=				np.array([0.3572, 0.6273, 0.4031, 0.3961, 0.4321, 0.5730, 0.5266, 0.4780, 0.5004]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3


     def 							_UpperCAmelCase      (      self							)       ->							Optional[int]:
          _a    	=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator
          _a    	=				self.get_dummy_components(class_cond=__UpperCAmelCase							)
          _a    	=				ConsistencyModelPipeline(**__UpperCAmelCase							)
          _a    	=				pipe.to(__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_dummy_inputs(__UpperCAmelCase							)
          _a    	=				0
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 32, 32, 3)

          _a    	=				image[0, -3:, -3:, -1]
          _a    	=				np.array([0.3572, 0.6273, 0.4031, 0.3961, 0.4321, 0.5730, 0.5266, 0.4780, 0.5004]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3


     def 							_UpperCAmelCase      (      self							)       ->							Tuple:
          _a    	=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator
          _a    	=				self.get_dummy_components()
          _a    	=				ConsistencyModelPipeline(**__UpperCAmelCase							)
          _a    	=				pipe.to(__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_dummy_inputs(__UpperCAmelCase							)
          _a    	=				1
          _a    	=				None
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 32, 32, 3)

          _a    	=				image[0, -3:, -3:, -1]
          _a    	=				np.array([0.5004, 0.5004, 0.4994, 0.5008, 0.4976, 0.5018, 0.4990, 0.4982, 0.4987]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3





     def 							_UpperCAmelCase      (      self							)       ->							int:
          _a    	=				'''cpu'''  # ensure determinism for the device-dependent torch.Generator
          _a    	=				self.get_dummy_components(class_cond=__UpperCAmelCase							)
          _a    	=				ConsistencyModelPipeline(**__UpperCAmelCase							)
          _a    	=				pipe.to(__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_dummy_inputs(__UpperCAmelCase							)
          _a    	=				1
          _a    	=				None
          _a    	=				0
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 32, 32, 3)

          _a    	=				image[0, -3:, -3:, -1]
          _a    	=				np.array([0.5004, 0.5004, 0.4994, 0.5008, 0.4976, 0.5018, 0.4990, 0.4982, 0.4987]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3







@slow
@require_torch_gpu
class     __lowerCamelCase  (					unittest.TestCase				):

     '''simple docstring'''


     def 							_UpperCAmelCase      (      self							)       ->							Union[str, Any]:
          super().tearDown()
          gc.collect()
          torch.cuda.empty_cache()


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase=0    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase="cpu"    ,				__UpperCAmelCase=torch.floataa    ,				__UpperCAmelCase=(1, 3, 64, 64)							)       ->							List[Any]:
          _a    	=				torch.manual_seed(__UpperCAmelCase							)

          _a    	=				{
              '''num_inference_steps''': None,
              '''timesteps''': [22, 0],
              '''class_labels''': 0,
              '''generator''': generator,
              '''output_type''': '''np''',
          }

          if get_fixed_latents:
               _a    	=				self.get_fixed_latents(seed=__UpperCAmelCase    ,				device=__UpperCAmelCase    ,				dtype=__UpperCAmelCase    ,				shape=__UpperCAmelCase							)
               _a    	=				latents

          return inputs


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase=0    ,				__UpperCAmelCase="cpu"    ,				__UpperCAmelCase=torch.floataa    ,				__UpperCAmelCase=(1, 3, 64, 64)							)       ->							List[str]:
          if type(__UpperCAmelCase							) == str:
               _a    	=				torch.device(__UpperCAmelCase							)
          _a    	=				torch.Generator(device=__UpperCAmelCase							).manual_seed(__UpperCAmelCase							)
          _a    	=				randn_tensor(__UpperCAmelCase    ,				generator=__UpperCAmelCase    ,				device=__UpperCAmelCase    ,				dtype=__UpperCAmelCase							)
          return latents


     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          _a    	=				UNetaDModel.from_pretrained('''diffusers/consistency_models'''    ,				subfolder='''diffusers_cd_imagenet64_l2'''							)
          _a    	=				CMStochasticIterativeScheduler(
              num_train_timesteps=40    ,				sigma_min=0.002    ,				sigma_max=80.0    ,				)
          _a    	=				ConsistencyModelPipeline(unet=__UpperCAmelCase    ,				scheduler=__UpperCAmelCase							)
          pipe.to(torch_device=__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_inputs()
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 64, 64, 3)

          _a    	=				image[0, -3:, -3:, -1]

          _a    	=				np.array([0.0888, 0.0881, 0.0666, 0.0479, 0.0292, 0.0195, 0.0201, 0.0163, 0.0254]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 2e-2


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				UNetaDModel.from_pretrained('''diffusers/consistency_models'''    ,				subfolder='''diffusers_cd_imagenet64_l2'''							)
          _a    	=				CMStochasticIterativeScheduler(
              num_train_timesteps=40    ,				sigma_min=0.002    ,				sigma_max=80.0    ,				)
          _a    	=				ConsistencyModelPipeline(unet=__UpperCAmelCase    ,				scheduler=__UpperCAmelCase							)
          pipe.to(torch_device=__UpperCAmelCase							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_inputs()
          _a    	=				1
          _a    	=				None
          _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 64, 64, 3)

          _a    	=				image[0, -3:, -3:, -1]

          _a    	=				np.array([0.0340, 0.0152, 0.0063, 0.0267, 0.0221, 0.0107, 0.0416, 0.0186, 0.0217]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 2e-2


     @require_torch_a
     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				UNetaDModel.from_pretrained('''diffusers/consistency_models'''    ,				subfolder='''diffusers_cd_imagenet64_l2'''							)
          _a    	=				CMStochasticIterativeScheduler(
              num_train_timesteps=40    ,				sigma_min=0.002    ,				sigma_max=80.0    ,				)
          _a    	=				ConsistencyModelPipeline(unet=__UpperCAmelCase    ,				scheduler=__UpperCAmelCase							)
          pipe.to(torch_device=__UpperCAmelCase    ,				torch_dtype=torch.floataa							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_inputs(get_fixed_latents=__UpperCAmelCase    ,				device=__UpperCAmelCase							)
          # Ensure usage of flash attention in torch 2.0
          with sdp_kernel(enable_flash=__UpperCAmelCase    ,				enable_math=__UpperCAmelCase    ,				enable_mem_efficient=__UpperCAmelCase							):
               _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 64, 64, 3)

          _a    	=				image[0, -3:, -3:, -1]

          _a    	=				np.array([0.1875, 0.1428, 0.1289, 0.2151, 0.2092, 0.1477, 0.1877, 0.1641, 0.1353]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3





     @require_torch_a
     def 							_UpperCAmelCase      (      self							)       ->							int:
          _a    	=				UNetaDModel.from_pretrained('''diffusers/consistency_models'''    ,				subfolder='''diffusers_cd_imagenet64_l2'''							)
          _a    	=				CMStochasticIterativeScheduler(
              num_train_timesteps=40    ,				sigma_min=0.002    ,				sigma_max=80.0    ,				)
          _a    	=				ConsistencyModelPipeline(unet=__UpperCAmelCase    ,				scheduler=__UpperCAmelCase							)
          pipe.to(torch_device=__UpperCAmelCase    ,				torch_dtype=torch.floataa							)
          pipe.set_progress_bar_config(disable=__UpperCAmelCase							)

          _a    	=				self.get_inputs(get_fixed_latents=__UpperCAmelCase    ,				device=__UpperCAmelCase							)
          _a    	=				1
          _a    	=				None
          # Ensure usage of flash attention in torch 2.0
          with sdp_kernel(enable_flash=__UpperCAmelCase    ,				enable_math=__UpperCAmelCase    ,				enable_mem_efficient=__UpperCAmelCase							):
               _a    	=				pipe(**__UpperCAmelCase							).images
          assert image.shape == (1, 64, 64, 3)

          _a    	=				image[0, -3:, -3:, -1]

          _a    	=				np.array([0.1663, 0.1948, 0.2275, 0.1680, 0.1204, 0.1245, 0.1858, 0.1338, 0.2095]							)

          assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-3



"""simple docstring"""






def       A_   (   _lowerCAmelCase     :					int = 10_00       ):






     """simple docstring"""

     _a	,      _a    	=				1, 1
     _a    	=				2
     while True:
          _a    	=				0
          _a    	=				fa + fa
          _a	,      _a    	=				fa, f
          index += 1
          for _ in str(_lowerCAmelCase       ):
               i += 1
          if i == n:
               break
     return index


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