"""simple docstring"""



from PIL import Image

def  _A(		lowerCAmelCase							):
							A__				,							A__       :     Optional[Any]								=			image.size
							A__       :     List[str]								=			0
							A__       :     List[str]								=			image.load()
							for i in range(lowerCAmelCase							):
														for j in range(lowerCAmelCase							):
																					A__       :     int								=			pixels[j, i]
																					mean += pixel
							mean //= width * height

							for j in range(lowerCAmelCase							):
														for i in range(lowerCAmelCase							):
																					A__       :     Tuple								=			255 if pixels[i, j] > mean else 0
							return image


if __name__ == "__main__":
				_UpperCamelCase								=		mean_threshold(Image.open("path_to_image").convert("L"))
				image.save("output_image_path")






"""simple docstring"""



def  _A(		lowerCAmelCase			,  lowerCAmelCase							):
							A__       :     List[Any]								=			[1]
							for i in range(2			,  lowerCAmelCase							):
														factorials.append(factorials[-1] * i							)
							assert 0 <= k < factorials[-1] * n, "k out of bounds"

							A__       :     Union[str, Any]								=			[]
							A__       :     int								=			list(range(lowerCAmelCase							)							)

							# Find permutation
							while factorials:
														A__       :     Optional[int]								=			factorials.pop()
														A__				,							A__       :     Union[str, Any]								=			divmod(lowerCAmelCase			,  lowerCAmelCase							)
														permutation.append(elements[number]							)
														elements.remove(elements[number]							)
							permutation.append(elements[0]							)

							return permutation


if __name__ == "__main__":
				import doctest

				doctest.testmod()





