





from __future__ import annotations





def   lowerCamelCase__       (       UpperCamelCase__     :    List[Any]    ,      UpperCamelCase__     :    Optional[Any]  )     ->	bool:



					'''simple docstring'''




					_snake_case													=			get_failure_array(UpperCamelCase__  )

					# 2) Step through text searching for pattern
					_snake_case							,       _snake_case													=			0, 0  # index into text, pattern
					while i < len(UpperCamelCase__  ):
										if pattern[j] == text[i]:
															if j == (len(UpperCamelCase__  ) - 1):
																				return True
															j += 1

										# if this is a prefix in our pattern
										# just go back far enough to continue
										elif j > 0:
															_snake_case													=			failure[j - 1]
															continue
										i += 1
					return False





def   lowerCamelCase__       (       UpperCamelCase__     :    List[str]  )     ->	list[int]:



					'''simple docstring'''




					_snake_case													=			[0]
					_snake_case													=			0
					_snake_case													=			1
					while j < len(UpperCamelCase__  ):
										if pattern[i] == pattern[j]:
															i += 1
										elif i > 0:
															_snake_case													=			failure[i - 1]
															continue
										j += 1
										failure.append(UpperCamelCase__  )
					return failure


if __name__ == "__main__":
					# Test 1)
					UpperCAmelCase_											=       """abc1abc12"""
					UpperCAmelCase_											=       """alskfjaldsabc1abc1abc12k23adsfabcabc"""
					UpperCAmelCase_											=       """alskfjaldsk23adsfabcabc"""
					assert kmp(pattern, texta) and not kmp(pattern, texta)

					# Test 2)
					UpperCAmelCase_											=       """ABABX"""
					UpperCAmelCase_											=       """ABABZABABYABABX"""
					assert kmp(pattern, text)

					# Test 3)
					UpperCAmelCase_											=       """AAAB"""
					UpperCAmelCase_											=       """ABAAAAAB"""
					assert kmp(pattern, text)

					# Test 4)
					UpperCAmelCase_											=       """abcdabcy"""
					UpperCAmelCase_											=       """abcxabcdabxabcdabcdabcy"""
					assert kmp(pattern, text)

					# Test 5)
					UpperCAmelCase_											=       """aabaabaaa"""
					assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]










from cva import destroyAllWindows, imread, imshow, waitKey





def   lowerCamelCase__       (       UpperCamelCase__     :    Dict  )     ->	Optional[Any]:



					'''simple docstring'''




					_snake_case							,       _snake_case													=			img.shape[0], img.shape[1]

					# converting each pixel's color to its negative
					for i in range(UpperCamelCase__  ):
										for j in range(UpperCamelCase__  ):
															_snake_case													=			[255, 255, 255] - img[i][j]

					return img


if __name__ == "__main__":
					# read original image
					UpperCAmelCase_ 							=       imread("""image_data/lena.jpg""", 1)

					# convert to its negative
					UpperCAmelCase_ 							=       convert_to_negative(img)

					# show result image
					imshow("""negative of original image""", img)
					waitKey(0)
					destroyAllWindows()



