



from __future__ import annotations






def  lowerCamelCase_	(      lowerCAmelCase__	:	str			,	lowerCAmelCase__	:	str				)       ->							bool:

							'''simple docstring'''






							A      						=    get_failure_array(lowerCAmelCase__				)

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

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






def  lowerCamelCase_	(      lowerCAmelCase__	:	str				)       ->							list[int]:

							'''simple docstring'''






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


if __name__ == "__main__":
				# Test 1)
				__snake_case     :Optional[Any]			       ='abc1abc12'
				__snake_case     :Any			       ='alskfjaldsabc1abc1abc12k23adsfabcabc'
				__snake_case     :Optional[int]			       ='alskfjaldsk23adsfabcabc'
				assert kmp(pattern, texta) and not kmp(pattern, texta)

				# Test 2)
				__snake_case     :Any			       ='ABABX'
				__snake_case     :List[Any]			       ='ABABZABABYABABX'
				assert kmp(pattern, text)

				# Test 3)
				__snake_case     :Any			       ='AAAB'
				__snake_case     :str			       ='ABAAAAAB'
				assert kmp(pattern, text)

				# Test 4)
				__snake_case     :Optional[int]			       ='abcdabcy'
				__snake_case     :Optional[Any]			       ='abcxabcdabxabcdabcdabcy'
				assert kmp(pattern, text)

				# Test 5)
				__snake_case     :int			       ='aabaabaaa'
				assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]




__snake_case     :Any			       =256
# Modulus to hash a string
__snake_case     :Optional[int]			       =1000003






def  lowerCamelCase_	(      lowerCAmelCase__	:	str			,	lowerCAmelCase__	:	str				)       ->							bool:

							'''simple docstring'''






							A      						=    len(lowerCAmelCase__				)
							A      						=    len(lowerCAmelCase__				)
							if p_len > t_len:
														return False

							A      						=    0
							A      						=    0
							A      						=    1

							# Calculating the hash of pattern and substring of text
							for i in range(lowerCAmelCase__				):
														A      						=    (ord(pattern[i]				) + p_hash * alphabet_size) % modulus
														A      						=    (ord(text[i]				) + text_hash * alphabet_size) % modulus
														if i == p_len - 1:
																					continue
														A      						=    (modulus_power * alphabet_size) % modulus

							for i in range(0			,	t_len - p_len + 1				):
														if text_hash == p_hash and text[i : i + p_len] == pattern:
																					return True
														if i == t_len - p_len:
																					continue
														# Calculate the https://en.wikipedia.org/wiki/Rolling_hash
														A      						=    (
														    (text_hash - ord(text[i]				) * modulus_power) * alphabet_size
														    + ord(text[i + p_len]				)
														) % modulus
							return False






def  lowerCamelCase_	(      )       ->							None:

							'''simple docstring'''






							A      						=    'abc1abc12'
							A      						=    'alskfjaldsabc1abc1abc12k23adsfabcabc'
							A      						=    'alskfjaldsk23adsfabcabc'
							assert rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				) and not rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)

							# Test 2)
							A      						=    'ABABX'
							A      						=    'ABABZABABYABABX'
							assert rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)

							# Test 3)
							A      						=    'AAAB'
							A      						=    'ABAAAAAB'
							assert rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)

							# Test 4)
							A      						=    'abcdabcy'
							A      						=    'abcxabcdabxabcdabcdabcy'
							assert rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)

							# Test 5)
							A      						=    'Lü'
							A      						=    'Lüsai'
							assert rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)
							A      						=    'Lue'
							assert not rabin_karp(lowerCAmelCase__			,	lowerCAmelCase__				)
							print('Success.'				)


if __name__ == "__main__":
				test_rabin_karp()