





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


_a									=				False






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

			'''simple docstring'''







			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







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





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







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

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

				lowerCamelCase__        =		torch.manual_seed(0							)
				lowerCamelCase__        =		pipe(
				    prompt='''first prompt'''	,  image=__lowerCAmelCase	,  text_to_image_strength=0.75	,  generator=__lowerCAmelCase	,  guidance_scale=7.5	,  num_inference_steps=2	,  output_type='''numpy'''	,  ).images

				with tempfile.TemporaryDirectory() as tmpdirname:
					pipe.save_pretrained(__lowerCAmelCase							)
					lowerCamelCase__        =		VersatileDiffusionDualGuidedPipeline.from_pretrained(__lowerCAmelCase							)

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

				lowerCamelCase__        =		generator.manual_seed(0							)
				lowerCamelCase__        =		pipe(
				    prompt='''first prompt'''	,  image=__lowerCAmelCase	,  text_to_image_strength=0.75	,  generator=__lowerCAmelCase	,  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 		__lowerCamelCase    (   self							):



				'''simple docstring'''







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

				lowerCamelCase__        =		'''cyberpunk 2077'''
				lowerCamelCase__        =		load_image(
				    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''							)
				lowerCamelCase__        =		torch.manual_seed(0							)
				lowerCamelCase__        =		pipe(
				    prompt=__lowerCAmelCase	,  image=__lowerCAmelCase	,  text_to_image_strength=0.75	,  generator=__lowerCAmelCase	,  guidance_scale=7.5	,  num_inference_steps=5_0	,  output_type='''numpy'''	,  ).images

				lowerCamelCase__        =		image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

				assert image.shape == (1, 5_1_2, 5_1_2, 3)
				lowerCamelCase__        =		np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]							)

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










import os





def lowerCAmelCase__()    ->				Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__        =		os.path.dirname(os.path.realpath(__snake_case							)							)
	lowerCamelCase__        =		os.path.join(__snake_case	,'''triangle.txt'''							)

	with open(__snake_case							) as f:
		lowerCamelCase__        =		f.readlines()

	lowerCamelCase__        =		[[int(__snake_case							) for y in x.rstrip('''\r\n'''							).split(''' '''							)] for x in triangle]

	for i in range(1	,len(__snake_case							)							):
		for j in range(len(a[i]							)							):
			lowerCamelCase__        =		a[i - 1][j] if j != len(a[i - 1]							) else 0
			lowerCamelCase__        =		a[i - 1][j - 1] if j > 0 else 0
			a[i][j] += max(__snake_case	,__snake_case							)
	return max(a[-1]							)


if __name__ == "__main__":
			print(solution())



