
import gc
import unittest

import numpy as np
import torch

from diffusers import RePaintPipeline, RePaintScheduler, UNetaDModel
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    load_image,
    load_numpy,
    nightly,
    require_torch_gpu,
    skip_mps,
    torch_device,
)

from ..pipeline_params import IMAGE_INPAINTING_BATCH_PARAMS, IMAGE_INPAINTING_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


class 						__magic_name__      (  __SCREAMING_SNAKE_CASE, unittest.TestCase			):
		_lowerCAmelCase						=		RePaintPipeline
		_lowerCAmelCase						=		IMAGE_INPAINTING_PARAMS - {"width", "height", "guidance_scale"}
		_lowerCAmelCase						=		PipelineTesterMixin.required_optional_params - {
		    "latents",
		    "num_images_per_prompt",
		    "callback",
		    "callback_steps",
		}
		_lowerCAmelCase						=		IMAGE_INPAINTING_BATCH_PARAMS
		_lowerCAmelCase						=		False





		def 					_A							(							self			:		Optional[Any] ):
							torch.manual_seed(0 )
							torch.manual_seed(0 )
							lowerCAmelCase						:    Union[str, Any]     		=   UNetaDModel(
							    block_out_channels=(3_2, 6_4)  ,     layers_per_block=2  ,     sample_size=3_2  ,     in_channels=3  ,     out_channels=3  ,     down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')  ,     up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')  ,     )
							lowerCAmelCase						:    Optional[int]     		=   RePaintScheduler()
							lowerCAmelCase						:    List[Any]     		=   {"unet": unet, "scheduler": scheduler}
							return components





		def 					_A							(							self			:		int  ,     lowerCamelCase__			:		List[str]  ,     lowerCamelCase__			:		Optional[Any]=0 ):
							if str(_snake_case ).startswith('''mps''' ):
												lowerCAmelCase						:    Optional[Any]     		=   torch.manual_seed(_snake_case )
							else:
												lowerCAmelCase						:    Union[str, Any]     		=   torch.Generator(device=_snake_case ).manual_seed(_snake_case )
							lowerCAmelCase						:    List[str]     		=   np.random.RandomState(_snake_case ).standard_normal((1, 3, 3_2, 3_2) )
							lowerCAmelCase						:    str     		=   torch.from_numpy(_snake_case ).to(device=_snake_case  ,     dtype=torch.floataa )
							lowerCAmelCase						:    str     		=   (image > 0).to(device=_snake_case  ,     dtype=torch.floataa )
							lowerCAmelCase						:    str     		=   {
							    "image": image,
							    "mask_image": mask,
							    "generator": generator,
							    "num_inference_steps": 5,
							    "eta": 0.0,
							    "jump_length": 2,
							    "jump_n_sample": 2,
							    "output_type": "numpy",
							}
							return inputs





		def 					_A							(							self			:		List[str] ):
							lowerCAmelCase						:    Union[str, Any]     		=   "cpu"  # ensure determinism for the device-dependent torch.Generator
							lowerCAmelCase						:    List[Any]     		=   self.get_dummy_components()
							lowerCAmelCase						:    Union[str, Any]     		=   RePaintPipeline(**_snake_case )
							lowerCAmelCase						:    Dict     		=   sd_pipe.to(_snake_case )
							sd_pipe.set_progress_bar_config(disable=_snake_case )

							lowerCAmelCase						:    Union[str, Any]     		=   self.get_dummy_inputs(_snake_case )
							lowerCAmelCase						:    Union[str, Any]     		=   sd_pipe(**_snake_case ).images
							lowerCAmelCase						:    Dict     		=   image[0, -3:, -3:, -1]

							assert image.shape == (1, 3_2, 3_2, 3)
							lowerCAmelCase						:    List[Any]     		=   np.array([1.0_0_0_0, 0.5_4_2_6, 0.5_4_9_7, 0.2_2_0_0, 1.0_0_0_0, 1.0_0_0_0, 0.5_6_2_3, 1.0_0_0_0, 0.6_2_7_4] )

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





		@skip_mps
		def 					_A							(							self			:		Optional[Any] ):
							return super().test_save_load_local()





		@unittest.skip('''non-deterministic pipeline''' )
		def 					_A							(							self			:		Union[str, Any] ):
							return super().test_inference_batch_single_identical()





		@skip_mps
		def 					_A							(							self			:		Tuple ):
							return super().test_dict_tuple_outputs_equivalent()





		@skip_mps
		def 					_A							(							self			:		str ):
							return super().test_save_load_optional_components()





		@skip_mps
		def 					_A							(							self			:		List[str] ):
							return super().test_attention_slicing_forward_pass()



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





		def 					_A							(							self			:		Union[str, Any] ):
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()





		def 					_A							(							self			:		List[Any] ):
							lowerCAmelCase						:    Union[str, Any]     		=   load_image(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/'''
							    '''repaint/celeba_hq_256.png''' )
							lowerCAmelCase						:    Any     		=   load_image(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/mask_256.png''' )
							lowerCAmelCase						:    str     		=   load_numpy(
							    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/'''
							    '''repaint/celeba_hq_256_result.npy''' )

							lowerCAmelCase						:    Optional[Any]     		=   "google/ddpm-ema-celebahq-256"
							lowerCAmelCase						:    Optional[int]     		=   UNetaDModel.from_pretrained(_snake_case )
							lowerCAmelCase						:    Optional[int]     		=   RePaintScheduler.from_pretrained(_snake_case )

							lowerCAmelCase						:    Union[str, Any]     		=   RePaintPipeline(unet=_snake_case  ,     scheduler=_snake_case ).to(_snake_case )
							repaint.set_progress_bar_config(disable=_snake_case )
							repaint.enable_attention_slicing()

							lowerCAmelCase						:    Any     		=   torch.manual_seed(0 )
							lowerCAmelCase						:    Union[str, Any]     		=   repaint(
							    _snake_case  ,     _snake_case  ,     num_inference_steps=2_5_0  ,     eta=0.0  ,     jump_length=1_0  ,     jump_n_sample=1_0  ,     generator=_snake_case  ,     output_type='''np'''  ,     )
							lowerCAmelCase						:    Union[str, Any]     		=   output.images[0]

							assert image.shape == (2_5_6, 2_5_6, 3)
							assert np.abs(expected_image - image ).mean() < 1E-2



'''simple docstring'''
import math
from itertools import permutations


def       a__    (  _SCREAMING_SNAKE_CASE					:    int							)			-> bool:


	"""simple docstring"""





	if 1 < number < 4:
		# 2 and 3 are primes
		return True
	elif number < 2 or number % 2 == 0 or number % 3 == 0:
		# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
		return False

	# All primes number are in format of 6k +/- 1
	for i in range(5     ,							int(math.sqrt(_SCREAMING_SNAKE_CASE							) + 1							)     ,							6							):
		if number % i == 0 or number % (i + 2) == 0:
			return False
	return True


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    list							)			-> bool:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_			:	Any      =   0, len(_SCREAMING_SNAKE_CASE							) - 1
	while left <= right:
		UpperCAmelCase_			:	List[str]      =   (left + right) // 2
		if prime_list[middle] == target:
			return True
		elif prime_list[middle] < target:
			UpperCAmelCase_			:	Dict      =   middle + 1
		else:
			UpperCAmelCase_			:	int      =   middle - 1

	return False


def       a__    (  )			-> Tuple:


	"""simple docstring"""





	UpperCAmelCase_			:	Dict      =   [n for n in range(10_01     ,							1_00_00     ,							2							) if is_prime(_SCREAMING_SNAKE_CASE							)]
	UpperCAmelCase_			:	Optional[int]      =   []

	for number in prime_list:
		UpperCAmelCase_			:	Optional[Any]      =   []

		for prime_member in permutations(list(str(_SCREAMING_SNAKE_CASE							)							)							):
			UpperCAmelCase_			:	List[Any]      =   int("".join(_SCREAMING_SNAKE_CASE							)							)

			if prime % 2 == 0:
				continue

			if search(_SCREAMING_SNAKE_CASE     ,							_SCREAMING_SNAKE_CASE							):
				tmp_numbers.append(_SCREAMING_SNAKE_CASE							)

		tmp_numbers.sort()
		if len(_SCREAMING_SNAKE_CASE							) >= 3:
			candidates.append(_SCREAMING_SNAKE_CASE							)

	UpperCAmelCase_			:	Tuple      =   []
	for candidate in candidates:
		UpperCAmelCase_			:	Union[str, Any]      =   len(_SCREAMING_SNAKE_CASE							)
		UpperCAmelCase_			:	Any      =   False

		for i in range(_SCREAMING_SNAKE_CASE							):
			for j in range(i + 1     ,							_SCREAMING_SNAKE_CASE							):
				for k in range(j + 1     ,							_SCREAMING_SNAKE_CASE							):
					if (
					    abs(candidate[i] - candidate[j]							)
					    == abs(candidate[j] - candidate[k]							)
					    and len({candidate[i], candidate[j], candidate[k]}							) == 3
					):
						passed.append(
						    sorted([candidate[i], candidate[j], candidate[k]]							)							)
						UpperCAmelCase_			:	Optional[Any]      =   True

					if found:
						break
				if found:
					break
			if found:
				break

	UpperCAmelCase_			:	Any      =   set()
	for seq in passed:
		answer.add("".join([str(_SCREAMING_SNAKE_CASE							) for i in seq]							)							)

	return max(int(_SCREAMING_SNAKE_CASE							) for x in answer							)


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




