



"""simple docstring"""






import gc
import unittest

import numpy as np
import torch
import torch.nn.functional as F
from transformers import (
    ClapTextConfig,
    ClapTextModelWithProjection,
    RobertaTokenizer,
    SpeechTaHifiGan,
    SpeechTaHifiGanConfig,
)

from diffusers import (
    AudioLDMPipeline,
    AutoencoderKL,
    DDIMScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()



class 			A__   (  __SCREAMING_SNAKE_CASE  ,		unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	AudioLDMPipeline
	SCREAMING_SNAKE_CASE          =	TEXT_TO_AUDIO_PARAMS
	SCREAMING_SNAKE_CASE          =	TEXT_TO_AUDIO_BATCH_PARAMS
	SCREAMING_SNAKE_CASE          =	frozenset(
	    [
	        'num_inference_steps',
	        'num_waveforms_per_prompt',
	        'generator',
	        'latents',
	        'output_type',
	        'return_dict',
	        'callback',
	        'callback_steps',
	    ]							)

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

				"""simple docstring"""

				torch.manual_seed(0)
				__lowerCAmelCase      :  Optional[int]												=       UNetaDConditionModel(
				    block_out_channels=(32, 64)       ,			layers_per_block=2       ,			sample_size=32       ,			in_channels=4       ,			out_channels=4       ,			down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")       ,			up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")       ,			cross_attention_dim=(32, 64)       ,			class_embed_type="simple_projection"       ,			projection_class_embeddings_input_dim=32       ,			class_embeddings_concat=_SCREAMING_SNAKE_CASE       ,			)
				__lowerCAmelCase      :  List[Any]												=       DDIMScheduler(
				    beta_start=0.0_0085       ,			beta_end=0.012       ,			beta_schedule="scaled_linear"       ,			clip_sample=_SCREAMING_SNAKE_CASE       ,			set_alpha_to_one=_SCREAMING_SNAKE_CASE       ,			)
				torch.manual_seed(0)
				__lowerCAmelCase      :  int												=       AutoencoderKL(
				    block_out_channels=[32, 64]       ,			in_channels=1       ,			out_channels=1       ,			down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]       ,			up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]       ,			latent_channels=4       ,			)
				torch.manual_seed(0)
				__lowerCAmelCase      :  List[str]												=       ClapTextConfig(
				    bos_token_id=0       ,			eos_token_id=2       ,			hidden_size=32       ,			intermediate_size=37       ,			layer_norm_eps=1e-05       ,			num_attention_heads=4       ,			num_hidden_layers=5       ,			pad_token_id=1       ,			vocab_size=1000       ,			projection_dim=32       ,			)
				__lowerCAmelCase      :  List[Any]												=       ClapTextModelWithProjection(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       RobertaTokenizer.from_pretrained("hf-internal-testing/tiny-random-roberta"       ,			model_max_length=77)

				__lowerCAmelCase      :  Union[str, Any]												=       SpeechTaHifiGanConfig(
				    model_in_dim=8       ,			sampling_rate=1_6000       ,			upsample_initial_channel=16       ,			upsample_rates=[2, 2]       ,			upsample_kernel_sizes=[4, 4]       ,			resblock_kernel_sizes=[3, 7]       ,			resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5]]       ,			normalize_before=_SCREAMING_SNAKE_CASE       ,			)

				__lowerCAmelCase      :  Dict												=       SpeechTaHifiGan(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  int												=       {
				    "unet": unet,
				    "scheduler": scheduler,
				    "vae": vae,
				    "text_encoder": text_encoder,
				    "tokenizer": tokenizer,
				    "vocoder": vocoder,
				}
				return components

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=0)				->       Optional[int]:

				"""simple docstring"""

				if str(_SCREAMING_SNAKE_CASE).startswith("mps"):
							__lowerCAmelCase      :  Optional[int]												=       torch.manual_seed(_SCREAMING_SNAKE_CASE)
				else:
							__lowerCAmelCase      :  Dict												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       {
				    "prompt": "A hammer hitting a wooden surface",
				    "generator": generator,
				    "num_inference_steps": 2,
				    "guidance_scale": 6.0,
				}
				return inputs

	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       Any:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       "cpu"  # ensure determinism for the device-dependent torch.Generator

				__lowerCAmelCase      :  Tuple												=       self.get_dummy_components()
				__lowerCAmelCase      :  Optional[int]												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Tuple												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Any												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       output.audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) == 256

				__lowerCAmelCase      :  List[Any]												=       audio[:10]
				__lowerCAmelCase      :  Union[str, Any]												=       np.array(
				    [-0.0050, 0.0050, -0.0060, 0.0033, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0033])

				assert np.abs(audio_slice - expected_slice).max() < 1e-2

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[Any]												=       self.get_dummy_components()
				__lowerCAmelCase      :  str												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[int]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Dict												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       3 * [inputs["prompt"]]

				# forward
				__lowerCAmelCase      :  str												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       output.audios[0]

				__lowerCAmelCase      :  List[Any]												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       3 * [inputs.pop("prompt")]

				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe.tokenizer(
				    _SCREAMING_SNAKE_CASE       ,			padding="max_length"       ,			max_length=audioldm_pipe.tokenizer.model_max_length       ,			truncation=_SCREAMING_SNAKE_CASE       ,			return_tensors="pt"       ,			)
				__lowerCAmelCase      :  Optional[int]												=       text_inputs["input_ids"].to(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[str]												=       audioldm_pipe.text_encoder(
				    _SCREAMING_SNAKE_CASE       ,			)
				__lowerCAmelCase      :  Union[str, Any]												=       prompt_embeds.text_embeds
				# additional L_2 normalization over each hidden-state
				__lowerCAmelCase      :  Dict												=       F.normalize(_SCREAMING_SNAKE_CASE       ,			dim=-1)

				__lowerCAmelCase      :  Union[str, Any]												=       prompt_embeds

				# forward
				__lowerCAmelCase      :  Union[str, Any]												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       output.audios[0]

				assert np.abs(audio_a - audio_a).max() < 1e-2

	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Any												=       self.get_dummy_components()
				__lowerCAmelCase      :  Optional[int]												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Optional[int]												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[int]												=       3 * ["this is a negative prompt"]
				__lowerCAmelCase      :  int												=       negative_prompt
				__lowerCAmelCase      :  Optional[Any]												=       3 * [inputs["prompt"]]

				# forward
				__lowerCAmelCase      :  Any												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Any												=       output.audios[0]

				__lowerCAmelCase      :  str												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       3 * [inputs.pop("prompt")]

				__lowerCAmelCase      :  Any												=       []
				for p in [prompt, negative_prompt]:
							__lowerCAmelCase      :  Optional[int]												=       audioldm_pipe.tokenizer(
							    _SCREAMING_SNAKE_CASE       ,			padding="max_length"       ,			max_length=audioldm_pipe.tokenizer.model_max_length       ,			truncation=_SCREAMING_SNAKE_CASE       ,			return_tensors="pt"       ,			)
							__lowerCAmelCase      :  Optional[int]												=       text_inputs["input_ids"].to(_SCREAMING_SNAKE_CASE)

							__lowerCAmelCase      :  Dict												=       audioldm_pipe.text_encoder(
							    _SCREAMING_SNAKE_CASE       ,			)
							__lowerCAmelCase      :  List[Any]												=       text_embeds.text_embeds
							# additional L_2 normalization over each hidden-state
							__lowerCAmelCase      :  Tuple												=       F.normalize(_SCREAMING_SNAKE_CASE       ,			dim=-1)

							embeds.append(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase						,	__lowerCAmelCase      :  int												=       embeds

				# forward
				__lowerCAmelCase      :  int												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       output.audios[0]

				assert np.abs(audio_a - audio_a).max() < 1e-2

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

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       "cpu"  # ensure determinism for the device-dependent torch.Generator
				__lowerCAmelCase      :  Optional[Any]												=       self.get_dummy_components()
				__lowerCAmelCase      :  Union[str, Any]												=       PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Tuple												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       "egg cracking"
				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE       ,			negative_prompt=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Union[str, Any]												=       output.audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) == 256

				__lowerCAmelCase      :  Any												=       audio[:10]
				__lowerCAmelCase      :  Tuple												=       np.array(
				    [-0.0051, 0.0050, -0.0060, 0.0034, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0032])

				assert np.abs(audio_slice - expected_slice).max() < 1e-2

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       "cpu"  # ensure determinism for the device-dependent torch.Generator
				__lowerCAmelCase      :  Any												=       self.get_dummy_components()
				__lowerCAmelCase      :  Optional[int]												=       PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[str]												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Optional[int]												=       "A hammer hitting a wooden surface"

				# test num_waveforms_per_prompt=1 (default)
				__lowerCAmelCase      :  Any												=       audioldm_pipe(_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2).audios

				assert audios.shape == (1, 256)

				# test num_waveforms_per_prompt=1 (default) for batch of prompts
				__lowerCAmelCase      :  Optional[Any]												=       2
				__lowerCAmelCase      :  Dict												=       audioldm_pipe([prompt] * batch_size       ,			num_inference_steps=2).audios

				assert audios.shape == (batch_size, 256)

				# test num_waveforms_per_prompt for single prompt
				__lowerCAmelCase      :  List[str]												=       2
				__lowerCAmelCase      :  str												=       audioldm_pipe(_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2       ,			num_waveforms_per_prompt=_SCREAMING_SNAKE_CASE).audios

				assert audios.shape == (num_waveforms_per_prompt, 256)

				# test num_waveforms_per_prompt for batch of prompts
				__lowerCAmelCase      :  int												=       2
				__lowerCAmelCase      :  Optional[int]												=       audioldm_pipe(
				    [prompt] * batch_size       ,			num_inference_steps=2       ,			num_waveforms_per_prompt=_SCREAMING_SNAKE_CASE).audios

				assert audios.shape == (batch_size * num_waveforms_per_prompt, 256)

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[str])				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       "cpu"  # ensure determinism for the device-dependent torch.Generator
				__lowerCAmelCase      :  Union[str, Any]												=       self.get_dummy_components()
				__lowerCAmelCase      :  str												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       audioldm_pipe.vocoder.config.sampling_rate

				__lowerCAmelCase      :  Optional[int]												=       self.get_dummy_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       audioldm_pipe(audio_length_in_s=0.016       ,			**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       output.audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) / vocoder_sampling_rate == 0.016

				__lowerCAmelCase      :  int												=       audioldm_pipe(audio_length_in_s=0.032       ,			**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Any												=       output.audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) / vocoder_sampling_rate == 0.032

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.get_dummy_components()
				__lowerCAmelCase      :  Optional[Any]												=       AudioLDMPipeline(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       ["hey"]

				__lowerCAmelCase      :  List[Any]												=       audioldm_pipe(_SCREAMING_SNAKE_CASE       ,			num_inference_steps=1)
				__lowerCAmelCase      :  List[Any]												=       output.audios.shape
				assert audio_shape == (1, 256)

				__lowerCAmelCase      :  Tuple												=       audioldm_pipe.vocoder.config
				config.model_in_dim *= 2
				__lowerCAmelCase      :  int												=       SpeechTaHifiGan(_SCREAMING_SNAKE_CASE).to(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       audioldm_pipe(_SCREAMING_SNAKE_CASE       ,			num_inference_steps=1)
				__lowerCAmelCase      :  Optional[Any]												=       output.audios.shape
				# waveform shape is unchanged, we just have 2x the number of mel channels in the spectrogram
				assert audio_shape == (1, 256)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       List[Any]:

				"""simple docstring"""

				self._test_attention_slicing_forward_pass(test_mean_pixel_difference=_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       List[Any]:

				"""simple docstring"""

				self._test_inference_batch_single_identical(test_mean_pixel_difference=_SCREAMING_SNAKE_CASE)







	@unittest.skipIf(
	    torch_device != "cuda" or not is_xformers_available()       ,			reason="XFormers attention is only available with CUDA and `xformers` installed"       ,			)
	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       Optional[int]:

				"""simple docstring"""

				self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=_SCREAMING_SNAKE_CASE)






@slow
class 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       int:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		Any="cpu"       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=torch.floataa       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=0)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       np.random.RandomState(_SCREAMING_SNAKE_CASE).standard_normal((1, 8, 128, 16))
				__lowerCAmelCase      :  Tuple												=       torch.from_numpy(_SCREAMING_SNAKE_CASE).to(device=_SCREAMING_SNAKE_CASE       ,			dtype=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       {
				    "prompt": "A hammer hitting a wooden surface",
				    "latents": latents,
				    "generator": generator,
				    "num_inference_steps": 3,
				    "guidance_scale": 2.5,
				}
				return inputs

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       AudioLDMPipeline.from_pretrained("cvssp/audioldm")
				__lowerCAmelCase      :  Dict												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       self.get_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[Any]												=       25
				__lowerCAmelCase      :  Any												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE).audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) == 8_1920

				__lowerCAmelCase      :  Dict												=       audio[7_7230:7_7240]
				__lowerCAmelCase      :  List[str]												=       np.array(
				    [-0.4884, -0.4607, 0.0023, 0.5007, 0.5896, 0.5151, 0.3813, -0.0208, -0.3687, -0.4315])
				__lowerCAmelCase      :  List[Any]												=       np.abs(expected_slice - audio_slice).max()
				assert max_diff < 1e-2







	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       AudioLDMPipeline.from_pretrained("cvssp/audioldm")
				__lowerCAmelCase      :  List[str]												=       LMSDiscreteScheduler.from_config(audioldm_pipe.scheduler.config)
				__lowerCAmelCase      :  Dict												=       audioldm_pipe.to(_SCREAMING_SNAKE_CASE)
				audioldm_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[Any]												=       self.get_inputs(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Optional[int]												=       audioldm_pipe(**_SCREAMING_SNAKE_CASE).audios[0]

				assert audio.ndim == 1
				assert len(_SCREAMING_SNAKE_CASE) == 8_1920

				__lowerCAmelCase      :  int												=       audio[2_7780:2_7790]
				__lowerCAmelCase      :  Optional[int]												=       np.array([-0.2131, -0.0873, -0.0124, -0.0189, 0.0569, 0.1373, 0.1883, 0.2886, 0.3297, 0.2212])
				__lowerCAmelCase      :  Dict												=       np.abs(expected_slice - audio_slice).max()
				assert max_diff < 3e-2




"""simple docstring"""






def 			_lowercase				(  )						->   int:
			return 1


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else two_pence(x - 2	) + one_pence()


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else five_pence(x - 5	) + two_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else ten_pence(x - 10	) + five_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else twenty_pence(x - 20	) + ten_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else fifty_pence(x - 50	) + twenty_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else one_pound(x - 100	) + fifty_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else two_pound(x - 200	) + one_pound(__snake_case	)


def 			_lowercase				(  __snake_case = 200	)						->   int:
			return two_pound(__snake_case	)


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