




import gc
import random
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, DDPMScheduler, StableDiffusionUpscalePipeline, UNetaDConditionModel
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					)		->      str:
             # clean up the VRAM after each test
             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Union[str, Any]:
             a_ :		List[Any]							=  1
             a_ :		str							=  3
             a_ :		List[Any]							=  (3_2, 3_2)

             a_ :		str							=  floats_tensor((batch_size, num_channels) + sizes					,							rng=random.Random(0					)					).to(SCREAMING_SNAKE_CASE__					)
             return image
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					)		->      Union[str, Any]:
             torch.manual_seed(0					)
             a_ :		Any							=  UNetaDConditionModel(
                 block_out_channels=(3_2, 3_2, 6_4)					,							layers_per_block=2					,							sample_size=3_2					,							in_channels=7					,							out_channels=4					,							down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D', 'CrossAttnDownBlock2D')					,							up_block_types=('CrossAttnUpBlock2D', 'CrossAttnUpBlock2D', 'UpBlock2D')					,							cross_attention_dim=3_2					,							attention_head_dim=8					,							use_linear_projection=SCREAMING_SNAKE_CASE__					,							only_cross_attention=(True, True, False)					,							num_class_embeds=1_0_0					,							)
             return model
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      str:
             torch.manual_seed(0					)
             a_ :		List[Any]							=  AutoencoderKL(
                 block_out_channels=[3_2, 3_2, 6_4]					,							in_channels=3					,							out_channels=3					,							down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D']					,							up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D']					,							latent_channels=4					,							)
             return model
      @property
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      Dict:
             torch.manual_seed(0					)
             a_ :		Union[str, Any]							=  CLIPTextConfig(
                 bos_token_id=0					,							eos_token_id=2					,							hidden_size=3_2					,							intermediate_size=3_7					,							layer_norm_eps=1E-05					,							num_attention_heads=4					,							num_hidden_layers=5					,							pad_token_id=1					,							vocab_size=1_0_0_0					,							hidden_act='gelu'					,							projection_dim=5_1_2					,							)
             return CLIPTextModel(SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Optional[Any]:
             a_ :		Tuple							=  'cpu'  # ensure determinism for the device-dependent torch.Generator
             a_ :		int							=  self.dummy_cond_unet_upscale
             a_ :		Optional[int]							=  DDPMScheduler()
             a_ :		str							=  DDIMScheduler(prediction_type='v_prediction'					)
             a_ :		Dict							=  self.dummy_vae
             a_ :		Union[str, Any]							=  self.dummy_text_encoder
             a_ :		str							=  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

             a_ :		str							=  self.dummy_image.cpu().permute(0					,							2					,							3					,							1					)[0]
             a_ :		List[str]							=  Image.fromarray(np.uinta(SCREAMING_SNAKE_CASE__					)					).convert('RGB'					).resize((6_4, 6_4)					)

             # make sure here that pndm scheduler skips prk
             a_ :		List[Any]							=  StableDiffusionUpscalePipeline(
                 unet=SCREAMING_SNAKE_CASE__					,							low_res_scheduler=SCREAMING_SNAKE_CASE__					,							scheduler=SCREAMING_SNAKE_CASE__					,							vae=SCREAMING_SNAKE_CASE__					,							text_encoder=SCREAMING_SNAKE_CASE__					,							tokenizer=SCREAMING_SNAKE_CASE__					,							max_noise_level=3_5_0					,							)
             a_ :		Any							=  sd_pipe.to(SCREAMING_SNAKE_CASE__					)
             sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

             a_ :		str							=  'A painting of a squirrel eating a burger'
             a_ :		Optional[Any]							=  torch.Generator(device=SCREAMING_SNAKE_CASE__					).manual_seed(0					)
             a_ :		int							=  sd_pipe(
                 [prompt]					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							guidance_scale=6.0					,							noise_level=2_0					,							num_inference_steps=2					,							output_type='np'					,							)

             a_ :		List[str]							=  output.images

             a_ :		List[Any]							=  torch.Generator(device=SCREAMING_SNAKE_CASE__					).manual_seed(0					)
             a_ :		int							=  sd_pipe(
                 [prompt]					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							guidance_scale=6.0					,							noise_level=2_0					,							num_inference_steps=2					,							output_type='np'					,							return_dict=SCREAMING_SNAKE_CASE__					,							)[0]

             a_ :		Tuple							=  image[0, -3:, -3:, -1]
             a_ :		List[Any]							=  image_from_tuple[0, -3:, -3:, -1]

             a_ :		Dict							=  low_res_image.size[0] * 4
             assert image.shape == (1, expected_height_width, expected_height_width, 3)
             a_ :		Tuple							=  np.array([0.3113, 0.3910, 0.4272, 0.4859, 0.5061, 0.4652, 0.5362, 0.5715, 0.5661]					)

             assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
             assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 1E-2
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      List[str]:
             a_ :		List[str]							=  'cpu'  # ensure determinism for the device-dependent torch.Generator
             a_ :		str							=  self.dummy_cond_unet_upscale
             a_ :		int							=  DDPMScheduler()
             a_ :		List[str]							=  DDIMScheduler(prediction_type='v_prediction'					)
             a_ :		Tuple							=  self.dummy_vae
             a_ :		List[str]							=  self.dummy_text_encoder
             a_ :		Optional[int]							=  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

             a_ :		Optional[int]							=  self.dummy_image.cpu().permute(0					,							2					,							3					,							1					)[0]
             a_ :		Union[str, Any]							=  Image.fromarray(np.uinta(SCREAMING_SNAKE_CASE__					)					).convert('RGB'					).resize((6_4, 6_4)					)

             # make sure here that pndm scheduler skips prk
             a_ :		Dict							=  StableDiffusionUpscalePipeline(
                 unet=SCREAMING_SNAKE_CASE__					,							low_res_scheduler=SCREAMING_SNAKE_CASE__					,							scheduler=SCREAMING_SNAKE_CASE__					,							vae=SCREAMING_SNAKE_CASE__					,							text_encoder=SCREAMING_SNAKE_CASE__					,							tokenizer=SCREAMING_SNAKE_CASE__					,							max_noise_level=3_5_0					,							)
             a_ :		List[str]							=  sd_pipe.to(SCREAMING_SNAKE_CASE__					)
             sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

             a_ :		Tuple							=  'A painting of a squirrel eating a burger'
             a_ :		str							=  sd_pipe(
                 2 * [prompt]					,							image=2 * [low_res_image]					,							guidance_scale=6.0					,							noise_level=2_0					,							num_inference_steps=2					,							output_type='np'					,							)
             a_ :		Any							=  output.images
             assert image.shape[0] == 2

             a_ :		int							=  torch.Generator(device=SCREAMING_SNAKE_CASE__					).manual_seed(0					)
             a_ :		str							=  sd_pipe(
                 [prompt]					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							num_images_per_prompt=2					,							guidance_scale=6.0					,							noise_level=2_0					,							num_inference_steps=2					,							output_type='np'					,							)
             a_ :		Optional[int]							=  output.images
             assert image.shape[0] == 2

      @unittest.skipIf(torch_device != 'cuda'					,							'This test requires a GPU'					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Optional[Any]:
             a_ :		str							=  self.dummy_cond_unet_upscale
             a_ :		Optional[int]							=  DDPMScheduler()
             a_ :		int							=  DDIMScheduler(prediction_type='v_prediction'					)
             a_ :		int							=  self.dummy_vae
             a_ :		Any							=  self.dummy_text_encoder
             a_ :		Tuple							=  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

             a_ :		List[str]							=  self.dummy_image.cpu().permute(0					,							2					,							3					,							1					)[0]
             a_ :		Tuple							=  Image.fromarray(np.uinta(SCREAMING_SNAKE_CASE__					)					).convert('RGB'					).resize((6_4, 6_4)					)

             # put models in fp16, except vae as it overflows in fp16
             a_ :		List[str]							=  unet.half()
             a_ :		Optional[Any]							=  text_encoder.half()

             # make sure here that pndm scheduler skips prk
             a_ :		str							=  StableDiffusionUpscalePipeline(
                 unet=SCREAMING_SNAKE_CASE__					,							low_res_scheduler=SCREAMING_SNAKE_CASE__					,							scheduler=SCREAMING_SNAKE_CASE__					,							vae=SCREAMING_SNAKE_CASE__					,							text_encoder=SCREAMING_SNAKE_CASE__					,							tokenizer=SCREAMING_SNAKE_CASE__					,							max_noise_level=3_5_0					,							)
             a_ :		Union[str, Any]							=  sd_pipe.to(SCREAMING_SNAKE_CASE__					)
             sd_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

             a_ :		Any							=  'A painting of a squirrel eating a burger'
             a_ :		str							=  torch.manual_seed(0					)
             a_ :		Tuple							=  sd_pipe(
                 [prompt]					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							num_inference_steps=2					,							output_type='np'					,							).images

             a_ :		List[Any]							=  low_res_image.size[0] * 4
             assert image.shape == (1, expected_height_width, expected_height_width, 3)
@slow
@require_torch_gpu
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      List[str]:
             # clean up the VRAM after each test
             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      List[Any]:
             a_ :		int							=  load_image(
                 'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
                 '/sd2-upscale/low_res_cat.png'					)
             a_ :		int							=  load_numpy(
                 'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale'
                 '/upsampled_cat.npy'					)

             a_ :		List[Any]							=  'stabilityai/stable-diffusion-x4-upscaler'
             a_ :		str							=  StableDiffusionUpscalePipeline.from_pretrained(SCREAMING_SNAKE_CASE__					)
             pipe.to(SCREAMING_SNAKE_CASE__					)
             pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)
             pipe.enable_attention_slicing()

             a_ :		List[str]							=  'a cat sitting on a park bench'

             a_ :		List[str]							=  torch.manual_seed(0					)
             a_ :		int							=  pipe(
                 prompt=SCREAMING_SNAKE_CASE__					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							output_type='np'					,							)
             a_ :		List[Any]							=  output.images[0]

             assert image.shape == (5_1_2, 5_1_2, 3)
             assert np.abs(expected_image - image					).max() < 1E-3
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Optional[int]:
             a_ :		Optional[Any]							=  load_image(
                 'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
                 '/sd2-upscale/low_res_cat.png'					)
             a_ :		str							=  load_numpy(
                 'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale'
                 '/upsampled_cat_fp16.npy'					)

             a_ :		List[Any]							=  'stabilityai/stable-diffusion-x4-upscaler'
             a_ :		Union[str, Any]							=  StableDiffusionUpscalePipeline.from_pretrained(
                 SCREAMING_SNAKE_CASE__					,							torch_dtype=torch.floataa					,							)
             pipe.to(SCREAMING_SNAKE_CASE__					)
             pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)
             pipe.enable_attention_slicing()

             a_ :		Optional[int]							=  'a cat sitting on a park bench'

             a_ :		Optional[int]							=  torch.manual_seed(0					)
             a_ :		str							=  pipe(
                 prompt=SCREAMING_SNAKE_CASE__					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							output_type='np'					,							)
             a_ :		Optional[Any]							=  output.images[0]

             assert image.shape == (5_1_2, 5_1_2, 3)
             assert np.abs(expected_image - image					).max() < 5E-1

      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      str:
             torch.cuda.empty_cache()
             torch.cuda.reset_max_memory_allocated()
             torch.cuda.reset_peak_memory_stats()

             a_ :		List[Any]							=  load_image(
                 'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
                 '/sd2-upscale/low_res_cat.png'					)

             a_ :		List[Any]							=  'stabilityai/stable-diffusion-x4-upscaler'
             a_ :		Optional[Any]							=  StableDiffusionUpscalePipeline.from_pretrained(
                 SCREAMING_SNAKE_CASE__					,							torch_dtype=torch.floataa					,							)
             pipe.to(SCREAMING_SNAKE_CASE__					)
             pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)
             pipe.enable_attention_slicing(1					)
             pipe.enable_sequential_cpu_offload()

             a_ :		str							=  'a cat sitting on a park bench'

             a_ :		Dict							=  torch.manual_seed(0					)
             a_ :		Optional[Any]							=  pipe(
                 prompt=SCREAMING_SNAKE_CASE__					,							image=SCREAMING_SNAKE_CASE__					,							generator=SCREAMING_SNAKE_CASE__					,							num_inference_steps=5					,							output_type='np'					,							)

             a_ :		Optional[Any]							=  torch.cuda.max_memory_allocated()
             # make sure that less than 2.9 GB is allocated
             assert mem_bytes < 2.9 * 1_0**9






def 	SCREAMING_SNAKE_CASE_						(      __A			:      int    )     ->		int:

       """simple docstring"""

       if n == 1 or not isinstance(__A  ,   __A    ):
              return 0
       elif n == 2:
              return 1
       else:
              a_ :		int							=  [0, 1]
              for i in range(2  ,   n + 1    ):
                     sequence.append(sequence[i - 1] + sequence[i - 2]    )

              return sequence[n]







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int    )     ->		int:

       """simple docstring"""

       a_ :		Any							=  0
       a_ :		Optional[Any]							=  2

       while digits < n:
              index += 1
              a_ :		List[Any]							=  len(str(fibonacci(__A    )    )    )

       return index







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int = 10_00    )     ->		int:

       """simple docstring"""

       return fibonacci_digits_index(__A    )


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


