


_UpperCAmelCase      :	List[str]  ={
    '''0''': 1,
    '''1''': 1,
    '''2''': 2,
    '''3''': 6,
    '''4''': 24,
    '''5''': 120,
    '''6''': 720,
    '''7''': 5040,
    '''8''': 4_0320,
    '''9''': 36_2880,
}

_UpperCAmelCase      :	Union[str, Any]  ={145: 145}

_UpperCAmelCase      :	Dict  ={
    145: 0,
    169: 3,
    3_6301: 3,
    1454: 3,
    871: 2,
    4_5361: 2,
    872: 2,
}



def       lowerCAmelCase			(		lowerCAmelCase_			)->			int:
				if n in CACHE_SUM_DIGIT_FACTORIALS:
								return CACHE_SUM_DIGIT_FACTORIALS[n]
				lowerCAmelCase_			:   Tuple     					=					sum(DIGIT_FACTORIALS[let] for let in str(__UpperCAmelCase			)			)
				lowerCAmelCase_			:   Optional[Any]     					=					ret
				return ret



def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_ = None			)->			int:
				lowerCAmelCase_			:   Union[str, Any]     					=					previous or set()
				if n in CHAIN_LENGTH_CACHE:
								return CHAIN_LENGTH_CACHE[n]
				lowerCAmelCase_			:   str     					=					sum_digit_factorials(__UpperCAmelCase			)
				if next_number in previous:
								lowerCAmelCase_			:   int     					=					0
								return 0
				else:
								previous.add(__UpperCAmelCase			)
								lowerCAmelCase_			:   Optional[int]     					=					1 + chain_length(__UpperCAmelCase			, __UpperCAmelCase			)
								lowerCAmelCase_			:   Union[str, Any]     					=					ret
								return ret



def       lowerCAmelCase			(		lowerCAmelCase_ = 60			, lowerCAmelCase_ = 1_000_000			)->			int:
				return sum(1 for i in range(1			, __UpperCAmelCase			) if chain_length(__UpperCAmelCase			) == num_terms			)


if __name__ == "__main__":
						print(f"""{solution() = }""")
'''simple docstring'''
import numpy as np
from PIL import Image







def 				__UpperCamelCase (					__UpperCAmelCase  :					np.array			)							->	np.array:
  lowercase				,      lowercase				,      lowercase				:							Dict									=   rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
  return 0.2989 * r + 0.5870 * g + 0.1140 * b







def 				__UpperCamelCase (					__UpperCAmelCase  :					np.array			)							->	np.array:
  return (gray > 127) & (gray <= 255)







def 				__UpperCamelCase (					__UpperCAmelCase  :					np.array ,   __UpperCAmelCase  :					np.array			)							->	np.array:
  lowercase				:							str									=   np.zeros_like(__UpperCAmelCase			)
  lowercase				:							Tuple									=   np.zeros(
      (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)			)

  # Copy image to padded image
  lowercase				:							int									=   image

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


# kernel to be applied
_A		:      Union[str, Any]						   =np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])

if __name__ == "__main__":
 # read original image
 _A		:      Optional[int]						   =np.array(Image.open(r'''..\image_data\lena.jpg'''))
 # Apply erosion operation to a binary image
 _A		:      Optional[int]						   =erosion(grayabinary(rgbagray(image)), structuring_element)
 # Save the output image
 _A		:      int						   =Image.fromarray(output).convert('''RGB''')
 pil_img.save('''result_erosion.png''')