
'''simple docstring'''

import gc
import tempfile
import unittest

import numpy as np
import torch

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


UpperCamelCase_        =							False


class 	a_	(unittest.TestCase     ):
       pass



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




       def 				__UpperCamelCase							(  self	):
         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()




       def 				__UpperCamelCase							(  self	):
         _lowerCAmelCase							:	Any 					=       VersatileDiffusionPipeline.from_pretrained("""shi-labs/versatile-diffusion""" , torch_dtype=torch.floataa	)
         pipe.to(__lowercase	)
         pipe.set_progress_bar_config(disable=__lowercase	)

         _lowerCAmelCase							:	Optional[Any] 					=       load_image(
             """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"""	)

         _lowerCAmelCase							:	Tuple 					=       torch.manual_seed(0	)
         _lowerCAmelCase							:	Tuple 					=       pipe.dual_guided(
             prompt="""first prompt""" , image=__lowercase , text_to_image_strength=0.75 , generator=__lowercase , guidance_scale=7.5 , num_inference_steps=2 , output_type="""numpy""" , ).images

         with tempfile.TemporaryDirectory() as tmpdirname:
           pipe.save_pretrained(__lowercase	)
           _lowerCAmelCase							:	Optional[Any] 					=       VersatileDiffusionPipeline.from_pretrained(__lowercase , torch_dtype=torch.floataa	)
         pipe.to(__lowercase	)
         pipe.set_progress_bar_config(disable=__lowercase	)

         _lowerCAmelCase							:	Tuple 					=       generator.manual_seed(0	)
         _lowerCAmelCase							:	str 					=       pipe.dual_guided(
             prompt="""first prompt""" , image=__lowercase , text_to_image_strength=0.75 , generator=__lowercase , 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 				__UpperCamelCase							(  self	):
         _lowerCAmelCase							:	List[Any] 					=       VersatileDiffusionPipeline.from_pretrained("""shi-labs/versatile-diffusion""" , torch_dtype=torch.floataa	)
         pipe.to(__lowercase	)
         pipe.set_progress_bar_config(disable=__lowercase	)

         _lowerCAmelCase							:	Tuple 					=       """cyberpunk 2077"""
         _lowerCAmelCase							:	Union[str, Any] 					=       load_image(
             """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"""	)
         _lowerCAmelCase							:	Optional[Any] 					=       torch.manual_seed(0	)
         _lowerCAmelCase							:	List[str] 					=       pipe.dual_guided(
             prompt=__lowercase , image=__lowercase , text_to_image_strength=0.75 , generator=__lowercase , guidance_scale=7.5 , num_inference_steps=5_0 , output_type="""numpy""" , ).images

         _lowerCAmelCase							:	int 					=       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							:	Optional[Any] 					=       np.array([0.1448, 0.1619, 0.1741, 0.1086, 0.1147, 0.1128, 0.1199, 0.1165, 0.1001]	)

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

         _lowerCAmelCase							:	Any 					=       """A painting of a squirrel eating a burger """
         _lowerCAmelCase							:	Union[str, Any] 					=       torch.manual_seed(0	)
         _lowerCAmelCase							:	str 					=       pipe.text_to_image(
             prompt=__lowercase , generator=__lowercase , guidance_scale=7.5 , num_inference_steps=5_0 , output_type="""numpy"""	).images

         _lowerCAmelCase							:	Union[str, Any] 					=       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							:	Tuple 					=       np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]	)

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

         _lowerCAmelCase							:	Tuple 					=       pipe.image_variation(__lowercase , generator=__lowercase , output_type="""numpy"""	).images

         _lowerCAmelCase							:	Optional[int] 					=       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							:	Optional[int] 					=       np.array([0.3076, 0.3123, 0.3284, 0.3782, 0.3770, 0.3894, 0.4297, 0.4331, 0.4456]	)

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





'''simple docstring'''

from collections import defaultdict
from math import gcd

def 					__UpperCamelCase				(						lowercase__    :	int = 1_50_00_00			):






     '''simple docstring'''





     __lowercase      		=defaultdict(lowercase__			)
     __lowercase      		=2
     while 2 * euclid_m * (euclid_m + 1) <= limit:
          for euclid_n in range((euclid_m % 2) + 1,       lowercase__,       2			):
               if gcd(lowercase__,       lowercase__			) > 1:
                    continue
               __lowercase      		=2 * euclid_m * (euclid_m + euclid_n)
               for perimeter in range(lowercase__,       limit + 1,       lowercase__			):
                    frequencies[perimeter] += 1
          euclid_m += 1
     return sum(1 for frequency in frequencies.values() if frequency == 1			)


if __name__ == "__main__":
       print(F'''{solution() = }''')


