

SCREAMING_SNAKE_CASE_            = 256
# Modulus to hash a string
SCREAMING_SNAKE_CASE_            = 1000003

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					str					, lowerCAmelCase:					str	)				->    bool:
				_UpperCAmelCase    :						Optional[int]							=      len(lowerCAmelCase	)
				_UpperCAmelCase    :						List[str]							=      len(lowerCAmelCase	)
				if p_len > t_len:
								return False

				_UpperCAmelCase    :						List[str]							=      0
				_UpperCAmelCase    :						Union[str, Any]							=      0
				_UpperCAmelCase    :						Optional[int]							=      1

				# Calculating the hash of pattern and substring of text
				for i in range(lowerCAmelCase	):
								_UpperCAmelCase    :						int							=      (ord(pattern[i]	) + p_hash * alphabet_size) % modulus
								_UpperCAmelCase    :						Optional[Any]							=      (ord(text[i]	) + text_hash * alphabet_size) % modulus
								if i == p_len - 1:
												continue
								_UpperCAmelCase    :						Optional[Any]							=      (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
								_UpperCAmelCase    :						str							=      (
								    (text_hash - ord(text[i]	) * modulus_power) * alphabet_size
								    + ord(text[i + p_len]	)
								) % modulus
				return False

def 							__SCREAMING_SNAKE_CASE							(			)				->    None:
				_UpperCAmelCase    :						Tuple							=      "abc1abc12"
				_UpperCAmelCase    :						int							=      "alskfjaldsabc1abc1abc12k23adsfabcabc"
				_UpperCAmelCase    :						List[Any]							=      "alskfjaldsk23adsfabcabc"
				assert rabin_karp(lowerCAmelCase					, lowerCAmelCase	) and not rabin_karp(lowerCAmelCase					, lowerCAmelCase	)

				# Test 2)
				_UpperCAmelCase    :						Tuple							=      "ABABX"
				_UpperCAmelCase    :						int							=      "ABABZABABYABABX"
				assert rabin_karp(lowerCAmelCase					, lowerCAmelCase	)

				# Test 3)
				_UpperCAmelCase    :						List[Any]							=      "AAAB"
				_UpperCAmelCase    :						Dict							=      "ABAAAAAB"
				assert rabin_karp(lowerCAmelCase					, lowerCAmelCase	)

				# Test 4)
				_UpperCAmelCase    :						Union[str, Any]							=      "abcdabcy"
				_UpperCAmelCase    :						Dict							=      "abcxabcdabxabcdabcdabcy"
				assert rabin_karp(lowerCAmelCase					, lowerCAmelCase	)

				# Test 5)
				_UpperCAmelCase    :						Optional[Any]							=      "Lü"
				_UpperCAmelCase    :						Dict							=      "Lüsai"
				assert rabin_karp(lowerCAmelCase					, lowerCAmelCase	)
				_UpperCAmelCase    :						List[Any]							=      "Lue"
				assert not rabin_karp(lowerCAmelCase					, lowerCAmelCase	)
				print("Success."	)


if __name__ == "__main__":
					test_rabin_karp()





from __future__ import annotations

from decimal import Decimal
from math import *  # noqa: F403

from sympy import diff

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					str					, lowerCAmelCase:					float | Decimal					, lowerCAmelCase:					float = 10**-10	)				->    float:
				_UpperCAmelCase    :						Optional[int]							=      a
				while True:
								_UpperCAmelCase    :						Tuple							=      Decimal(lowerCAmelCase	) - (
								    Decimal(eval(lowerCAmelCase	)	) / Decimal(eval(str(diff(lowerCAmelCase	)	)	)	)  # noqa: S307
								)
								# This number dictates the accuracy of the answer
								if abs(eval(lowerCAmelCase	)	) < precision:  # noqa: S307
												return float(lowerCAmelCase	)


# Let's Execute
if __name__ == "__main__":
					# Find root of trigonometric function
					# Find value of pi
					print(F'''The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}''')
					# Find root of polynomial
					print(F'''The root of x**2 - 5*x + 2 = 0 is {newton_raphson("x**2 - 5*x + 2", 0.4)}''')
					# Find Square Root of 5
					print(F'''The root of log(x) - 1 = 0 is {newton_raphson("log(x) - 1", 2)}''')
					# Exponential Roots
					print(F'''The root of exp(x) - 1 = 0 is {newton_raphson("exp(x) - 1", 0)}''')


