
import itertools




def 						A_			(				snake_case				: int = 1000000			)   ->     int:



						'''simple docstring'''

						__UpperCamelCase  	=      [1]

						for i in itertools.count(len(snake_case			)			):
												__UpperCamelCase  	=      0
												for j in itertools.count(1			):
																		__UpperCamelCase  	=      -1 if j % 2 == 0 else +1
																		__UpperCamelCase  	=      (j * j * 3 - j) // 2
																		if index > i:
																								break
																		item += partitions[i - index] * sign
																		item %= number
																		index += j
																		if index > i:
																								break
																		item += partitions[i - index] * sign
																		item %= number

												if item == 0:
																		return i
												partitions.append(snake_case			)

						return 0


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				print(F"{solution() = }")






import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


lowercase__				:				List[str]						=      False






@nightly
@require_torch_gpu
class 							SCREAMING_SNAKE_CASE__     (				unittest.TestCase     ):

							"""simple docstring"""






							def      A__		(	self      )-> List[Any]:





													'''simple docstring'''






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



							def      A__		(	self      )-> Dict:





													'''simple docstring'''






													__UpperCamelCase  	=      VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''      )
													# remove text_unet
													pipe.remove_unused_weights()
													pipe.to(SCREAMING_SNAKE_CASE_      )
													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_      )

													__UpperCamelCase  	=      load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''      )

													__UpperCamelCase  	=      torch.manual_seed(0      )
													__UpperCamelCase  	=      pipe(
													    prompt='''first prompt'''  ,						image=SCREAMING_SNAKE_CASE_  ,						text_to_image_strength=0.7_5  ,						generator=SCREAMING_SNAKE_CASE_  ,						guidance_scale=7.5  ,						num_inference_steps=2  ,						output_type='''numpy'''  ,						).images

													with tempfile.TemporaryDirectory() as tmpdirname:
																			pipe.save_pretrained(SCREAMING_SNAKE_CASE_      )
																			__UpperCamelCase  	=      VersatileDiffusionDualGuidedPipeline.from_pretrained(SCREAMING_SNAKE_CASE_      )

													pipe.to(SCREAMING_SNAKE_CASE_      )
													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_      )

													__UpperCamelCase  	=      generator.manual_seed(0      )
													__UpperCamelCase  	=      pipe(
													    prompt='''first prompt'''  ,						image=SCREAMING_SNAKE_CASE_  ,						text_to_image_strength=0.7_5  ,						generator=SCREAMING_SNAKE_CASE_  ,						guidance_scale=7.5  ,						num_inference_steps=2  ,						output_type='''numpy'''  ,						).images

													assert np.abs(image - new_image      ).sum() < 1E-5, "Models don't have the same forward pass"



							def      A__		(	self      )-> int:





													'''simple docstring'''






													__UpperCamelCase  	=      VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''      )
													pipe.remove_unused_weights()
													pipe.to(SCREAMING_SNAKE_CASE_      )
													pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_      )

													__UpperCamelCase  	=      '''cyberpunk 2077'''
													__UpperCamelCase  	=      load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''      )
													__UpperCamelCase  	=      torch.manual_seed(0      )
													__UpperCamelCase  	=      pipe(
													    prompt=SCREAMING_SNAKE_CASE_  ,						image=SCREAMING_SNAKE_CASE_  ,						text_to_image_strength=0.7_5  ,						generator=SCREAMING_SNAKE_CASE_  ,						guidance_scale=7.5  ,						num_inference_steps=50  ,						output_type='''numpy'''  ,						).images

													__UpperCamelCase  	=      image[0, 253:256, 253:256, -1]

													assert image.shape == (1, 512, 512, 3)
													__UpperCamelCase  	=      np.array([0.0_7_8_7, 0.0_8_4_9, 0.0_8_2_6, 0.0_8_1_2, 0.0_8_0_7, 0.0_7_9_5, 0.0_8_1_8, 0.0_7_9_8, 0.0_7_7_9]      )

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




