






"""simple docstring"""





from PIL import Image







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	Image:
    """simple docstring"""

    UpperCamelCase__       ,						UpperCamelCase__         =    image.size
    UpperCamelCase__         =    0
    UpperCamelCase__         =    image.load()
    for i in range(SCREAMING_SNAKE_CASE					):
        for j in range(SCREAMING_SNAKE_CASE					):
            UpperCamelCase__         =    pixels[j, i]
            mean += pixel
    mean //= width * height

    for j in range(SCREAMING_SNAKE_CASE					):
        for i in range(SCREAMING_SNAKE_CASE					):
            UpperCamelCase__         =    2_55 if pixels[i, j] > mean else 0
    return image


if __name__ == "__main__":
  A__					: List[str]=	mean_threshold(Image.open("""path_to_image""").convert("""L"""))
  image.save("""output_image_path""")












"""simple docstring"""





from collections import defaultdict
from math import ceil, sqrt







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE = 1_00_00_00 ,	SCREAMING_SNAKE_CASE = 10					)					->	int:
    """simple docstring"""

    UpperCamelCase__         =    defaultdict(SCREAMING_SNAKE_CASE					)

    for outer_width in range(3 ,	(t_limit // 4) + 2					):
        if outer_width * outer_width > t_limit:
            UpperCamelCase__         =    max(
                ceil(sqrt(outer_width * outer_width - t_limit					)					) ,	1					)
        else:
            UpperCamelCase__         =    1

        hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

        for hole_width in range(SCREAMING_SNAKE_CASE ,	outer_width - 1 ,	2					):
            count[outer_width * outer_width - hole_width * hole_width] += 1

    return sum(1 for n in count.values() if 1 <= n <= 10					)


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




