




import gc
import unittest

import numpy as np
import torch

from diffusers import (
    AudioDiffusionPipeline,
    AutoencoderKL,
    DDIMScheduler,
    DDPMScheduler,
    DiffusionPipeline,
    Mel,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()


class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple)		->Optional[Any]:





           '''simple docstring'''

           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Optional[Any]:





           '''simple docstring'''

           torch.manual_seed(0)
           A__   				=					UNetaDModel(
               sample_size=(32, 64)      ,				in_channels=1      ,				out_channels=1      ,				layers_per_block=2      ,				block_out_channels=(128, 128)      ,				down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')      ,				up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')      ,				)
           return model


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple)		->List[Any]:





           '''simple docstring'''

           torch.manual_seed(0)
           A__   				=					UNetaDConditionModel(
               sample_size=(64, 32)      ,				in_channels=1      ,				out_channels=1      ,				layers_per_block=2      ,				block_out_channels=(128, 128)      ,				down_block_types=('''CrossAttnDownBlock2D''', '''DownBlock2D''')      ,				up_block_types=('''UpBlock2D''', '''CrossAttnUpBlock2D''')      ,				cross_attention_dim=10      ,				)
           return model


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any])		->Tuple:





           '''simple docstring'''

           torch.manual_seed(0)
           A__   				=					AutoencoderKL(
               sample_size=(128, 64)      ,				in_channels=1      ,				out_channels=1      ,				latent_channels=1      ,				layers_per_block=2      ,				block_out_channels=(128, 128)      ,				down_block_types=('''DownEncoderBlock2D''', '''DownEncoderBlock2D''')      ,				up_block_types=('''UpDecoderBlock2D''', '''UpDecoderBlock2D''')      ,				)
           A__   				=					UNetaDModel(
               sample_size=(64, 32)      ,				in_channels=1      ,				out_channels=1      ,				layers_per_block=2      ,				block_out_channels=(128, 128)      ,				down_block_types=('''AttnDownBlock2D''', '''DownBlock2D''')      ,				up_block_types=('''UpBlock2D''', '''AttnUpBlock2D''')      ,				)
           return vqvae, unet





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Any:





           '''simple docstring'''

           A__   				=					'''cpu'''  # ensure determinism for the device-dependent torch.Generator
           A__   				=					Mel(
               x_res=self.dummy_unet.config.sample_size[1]      ,				y_res=self.dummy_unet.config.sample_size[0]      ,				)

           A__   				=					DDPMScheduler()
           A__   				=					AudioDiffusionPipeline(vqvae=UpperCAmelCase__      ,				unet=self.dummy_unet      ,				mel=UpperCAmelCase__      ,				scheduler=UpperCAmelCase__)
           A__   				=					pipe.to(UpperCAmelCase__)
           pipe.set_progress_bar_config(disable=UpperCAmelCase__)

           A__   				=					torch.Generator(device=UpperCAmelCase__).manual_seed(42)
           A__   				=					pipe(generator=UpperCAmelCase__      ,				steps=4)
           A__   				=					output.audios[0]
           A__   				=					output.images[0]

           A__   				=					torch.Generator(device=UpperCAmelCase__).manual_seed(42)
           A__   				=					pipe(generator=UpperCAmelCase__      ,				steps=4      ,				return_dict=UpperCAmelCase__)
           A__   				=					output[0][0]

           assert audio.shape == (1, (self.dummy_unet.config.sample_size[1] - 1) * mel.hop_length)
           assert (
               image.height == self.dummy_unet.config.sample_size[0]
               and image.width == self.dummy_unet.config.sample_size[1]
           )
           A__   				=					np.frombuffer(image.tobytes()      ,				dtype='''uint8''')[:10]
           A__   				=					np.frombuffer(image_from_tuple.tobytes()      ,				dtype='''uint8''')[:10]
           A__   				=					np.array([69, 255, 255, 255, 0, 0, 77, 181, 12, 127])

           assert np.abs(image_slice.flatten() - expected_slice).max() == 0
           assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() == 0

           A__   				=					Mel(
               x_res=self.dummy_vqvae_and_unet[0].config.sample_size[1]      ,				y_res=self.dummy_vqvae_and_unet[0].config.sample_size[0]      ,				)

           A__   				=					DDIMScheduler()
           A__   				=					self.dummy_vqvae_and_unet
           A__   				=					AudioDiffusionPipeline(
               vqvae=self.dummy_vqvae_and_unet[0]      ,				unet=dummy_vqvae_and_unet[1]      ,				mel=UpperCAmelCase__      ,				scheduler=UpperCAmelCase__)
           A__   				=					pipe.to(UpperCAmelCase__)
           pipe.set_progress_bar_config(disable=UpperCAmelCase__)

           np.random.seed(0)
           A__   				=					np.random.uniform(-1      ,				1      ,				((dummy_vqvae_and_unet[0].config.sample_size[1] - 1) * mel.hop_length,))
           A__   				=					torch.Generator(device=UpperCAmelCase__).manual_seed(42)
           A__   				=					pipe(raw_audio=UpperCAmelCase__      ,				generator=UpperCAmelCase__      ,				start_step=5      ,				steps=10)
           A__   				=					output.images[0]

           assert (
               image.height == self.dummy_vqvae_and_unet[0].config.sample_size[0]
               and image.width == self.dummy_vqvae_and_unet[0].config.sample_size[1]
           )
           A__   				=					np.frombuffer(image.tobytes()      ,				dtype='''uint8''')[:10]
           A__   				=					np.array([120, 117, 110, 109, 138, 167, 138, 148, 132, 121])

           assert np.abs(image_slice.flatten() - expected_slice).max() == 0

           A__   				=					self.dummy_unet_condition
           A__   				=					AudioDiffusionPipeline(
               vqvae=self.dummy_vqvae_and_unet[0]      ,				unet=UpperCAmelCase__      ,				mel=UpperCAmelCase__      ,				scheduler=UpperCAmelCase__)
           A__   				=					pipe.to(UpperCAmelCase__)
           pipe.set_progress_bar_config(disable=UpperCAmelCase__)

           np.random.seed(0)
           A__   				=					torch.rand((1, 1, 10))
           A__   				=					pipe(generator=UpperCAmelCase__      ,				encoding=UpperCAmelCase__)
           A__   				=					output.images[0]
           A__   				=					np.frombuffer(image.tobytes()      ,				dtype='''uint8''')[:10]
           A__   				=					np.array([107, 103, 120, 127, 142, 122, 113, 122, 97, 111])

           assert np.abs(image_slice.flatten() - expected_slice).max() == 0


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

    '''simple docstring'''






    def  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->Optional[int]:





           '''simple docstring'''

           super().tearDown()
           gc.collect()
           torch.cuda.empty_cache()





    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple)		->Dict:





           '''simple docstring'''

           A__   				=					torch_device

           A__   				=					DiffusionPipeline.from_pretrained('''teticio/audio-diffusion-ddim-256''')
           A__   				=					pipe.to(UpperCAmelCase__)
           pipe.set_progress_bar_config(disable=UpperCAmelCase__)

           A__   				=					torch.Generator(device=UpperCAmelCase__).manual_seed(42)
           A__   				=					pipe(generator=UpperCAmelCase__)
           A__   				=					output.audios[0]
           A__   				=					output.images[0]

           assert audio.shape == (1, (pipe.unet.config.sample_size[1] - 1) * pipe.mel.hop_length)
           assert image.height == pipe.unet.config.sample_size[0] and image.width == pipe.unet.config.sample_size[1]
           A__   				=					np.frombuffer(image.tobytes()      ,				dtype='''uint8''')[:10]
           A__   				=					np.array([151, 167, 154, 144, 122, 134, 121, 105, 70, 26])

           assert np.abs(image_slice.flatten() - expected_slice).max() == 0








def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					1
       for i in range(1				,       num + 1		):
              fact *= i
       return fact







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					0
       while number > 0:
              A__   				=					number % 10
              sum_of_digits += last_digit
              A__   				=					number // 10  # Removing the last_digit from the given number
       return sum_of_digits







def SCREAMING_SNAKE_CASE       ( lowercase_ = 100		)     -> int:



       """simple docstring"""

       A__   				=					factorial(lowercase_		)
       A__   				=					split_and_add(lowercase_		)
       return result


if __name__ == "__main__":
  print(solution(int(input("""Enter the Number: """).strip())))


