
'''simple docstring'''





from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt



def  UpperCamelCase					(							lowerCAmelCase__	):
					'''simple docstring'''
					lowercase					=		int(number**0.5	)
					return number == sq * sq



def  UpperCamelCase					(							lowerCAmelCase__				,    lowerCAmelCase__				,    lowerCAmelCase__				,    lowerCAmelCase__				,    lowerCAmelCase__				,    lowerCAmelCase__	):
					'''simple docstring'''
					lowercase					=		x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
					lowercase					=		x_den * y_den * z_den
					lowercase					=		gcd(__UpperCamelCase				,    __UpperCamelCase	)
					top //= hcf
					bottom //= hcf
					return top, bottom



def  UpperCamelCase					(							lowerCAmelCase__ = 35	):
					'''simple docstring'''
					lowercase					=		set()
					lowercase					=		42
					lowercase					=		Fraction(0	)
					lowercase					=		42

					for x_num in range(1				,    order + 1	):
										for x_den in range(x_num + 1				,    order + 1	):
															for y_num in range(1				,    order + 1	):
																				for y_den in range(y_num + 1				,    order + 1	):
																									# n=1
																									lowercase					=		x_num * y_den + x_den * y_num
																									lowercase					=		x_den * y_den
																									lowercase					=		gcd(__UpperCamelCase				,    __UpperCamelCase	)
																									z_num //= hcf
																									z_den //= hcf
																									if 0 < z_num < z_den <= order:
																														lowercase					=		add_three(
																														    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase	)
																														unique_s.add(__UpperCamelCase	)

																									# n=2
																									lowercase					=		(
																									    x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
																									)
																									lowercase					=		x_den * x_den * y_den * y_den
																									if is_sq(__UpperCamelCase	) and is_sq(__UpperCamelCase	):
																														lowercase					=		int(sqrt(__UpperCamelCase	)	)
																														lowercase					=		int(sqrt(__UpperCamelCase	)	)
																														lowercase					=		gcd(__UpperCamelCase				,    __UpperCamelCase	)
																														z_num //= hcf
																														z_den //= hcf
																														if 0 < z_num < z_den <= order:
																																			lowercase					=		add_three(
																																			    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase	)
																																			unique_s.add(__UpperCamelCase	)

                    # n=-1
																									lowercase					=		x_num * y_num
																									lowercase					=		x_den * y_num + x_num * y_den
																									lowercase					=		gcd(__UpperCamelCase				,    __UpperCamelCase	)
																									z_num //= hcf
																									z_den //= hcf
																									if 0 < z_num < z_den <= order:
																														lowercase					=		add_three(
																														    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase	)
																														unique_s.add(__UpperCamelCase	)

																									# n=2
																									lowercase					=		x_num * x_num * y_num * y_num
																									lowercase					=		(
																									    x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
																									)
																									if is_sq(__UpperCamelCase	) and is_sq(__UpperCamelCase	):
																														lowercase					=		int(sqrt(__UpperCamelCase	)	)
																														lowercase					=		int(sqrt(__UpperCamelCase	)	)
																														lowercase					=		gcd(__UpperCamelCase				,    __UpperCamelCase	)
																														z_num //= hcf
																														z_den //= hcf
																														if 0 < z_num < z_den <= order:
																																			lowercase					=		add_three(
																																			    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase				,    __UpperCamelCase	)
																																			unique_s.add(__UpperCamelCase	)

					for num, den in unique_s:
										total += Fraction(__UpperCamelCase				,    __UpperCamelCase	)

					return total.denominator + total.numerator


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






from pathlib import Path

import numpy as np
from PIL import Image



def  UpperCamelCase					(							lowerCAmelCase__	):
					'''simple docstring'''
					lowercase			,		lowercase			,		lowercase					=		rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
					return 0.29_89 * r + 0.58_70 * g + 0.11_40 * b



def  UpperCamelCase					(							lowerCAmelCase__	):
					'''simple docstring'''
					return (gray > 127) & (gray <= 255)



def  UpperCamelCase					(							lowerCAmelCase__				,    lowerCAmelCase__	):
					'''simple docstring'''
					lowercase					=		np.zeros_like(lowerCAmelCase__	)
					lowercase					=		np.zeros(
					    (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)	)

					# Copy image to padded image
					lowercase					=		image

					# Iterate over image & apply kernel
					for x in range(image.shape[1]	):
										for y in range(image.shape[0]	):
															lowercase					=		(
															    kernel * image_padded[y : y + kernel.shape[0], x : x + kernel.shape[1]]
															).sum()
															lowercase					=		int(summation > 0	)
					return output


if __name__ == "__main__":
							# read original image
							lowercase__	:str										=					Path(__file__).resolve().parent / "image_data" / "lena.jpg"
							lowercase__	:List[str]										=					np.array(Image.open(lena_path))
							# kernel to be applied
							lowercase__	:Union[str, Any]										=					np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
							lowercase__	:Optional[int]										=					dilation(gray_to_binary(rgb_to_gray(lena)), structuring_element)
							# Save the output image
							lowercase__	:str										=					Image.fromarray(output).convert("RGB")
							pil_img.save("result_dilation.png")




