
"""simple docstring"""


from __future__ import annotations

from collections.abc import Iterator
from typing import Any

class        A_      :



							"""simple docstring"""






							def __init__(    self    :str	,				lowerCamelCase_    :Union[str, Any]			):





										"""simple docstring"""

										lowerCamelCase__      :	Any						=data
										lowerCamelCase__      :	Node | None						=None






class        A_      :



							"""simple docstring"""






							def __init__(    self    :Union[str, Any]			):





										"""simple docstring"""

										lowerCamelCase__      :	List[str]						=None
										lowerCamelCase__      :	Union[str, Any]						=None





							def __iter__(    self    :Dict			):





										"""simple docstring"""

										lowerCamelCase__      :	Optional[int]						=self.head
										while self.head:
													yield node.data
													lowerCamelCase__      :	Dict						=node.next
													if node == self.head:
																break





							def __len__(    self    :Optional[int]			):





										"""simple docstring"""

										return sum(1 for _ in self			)





							def __repr__(    self    :Dict			):





										"""simple docstring"""

										return "->".join(str(a_			) for item in iter(self			)			)





							def  UpperCAmelCase__				(    self    :str	,				lowerCamelCase_    :Any			):





										"""simple docstring"""

										self.insert_nth(len(self			)	,				a_			)





							def  UpperCAmelCase__				(    self    :int	,				lowerCamelCase_    :Tuple			):





										"""simple docstring"""

										self.insert_nth(0	,				a_			)





							def  UpperCAmelCase__				(    self    :List[str]	,				lowerCamelCase_    :Dict	,				lowerCamelCase_    :int			):





										"""simple docstring"""

										if index < 0 or index > len(self			):
													raise IndexError('list index out of range.'			)
										lowerCamelCase__      :	Optional[Any]						=Node(a_			)
										if self.head is None:
													lowerCamelCase__      :	Tuple						=new_node  # first node points itself
													lowerCamelCase__      :	Optional[Any]						=new_node
										elif index == 0:  # insert at head
													lowerCamelCase__      :	Union[str, Any]						=self.head
													lowerCamelCase__      :	int						=new_node
										else:
													lowerCamelCase__      :	List[str]						=self.head
													for _ in range(index - 1			):
																lowerCamelCase__      :	Optional[int]						=temp.next
													lowerCamelCase__      :	List[Any]						=temp.next
													lowerCamelCase__      :	Optional[int]						=new_node
													if index == len(self			) - 1:  # insert at tail
																lowerCamelCase__      :	Union[str, Any]						=new_node





							def  UpperCAmelCase__				(    self    :Dict			):





										"""simple docstring"""

										return self.delete_nth(0			)





							def  UpperCAmelCase__				(    self    :List[Any]			):





										"""simple docstring"""

										return self.delete_nth(len(self			) - 1			)





							def  UpperCAmelCase__				(    self    :Any	,				lowerCamelCase_    :Optional[Any] = 0			):





										"""simple docstring"""

										if not 0 <= index < len(self			):
													raise IndexError('list index out of range.'			)
										lowerCamelCase__      :	Tuple						=self.head
										if self.head == self.tail:  # just one node
													lowerCamelCase__      :	Tuple						=None
										elif index == 0:  # delete head node
													lowerCamelCase__      :	Optional[int]						=self.tail.next.next
													lowerCamelCase__      :	Union[str, Any]						=self.head.next
										else:
													lowerCamelCase__      :	Tuple						=self.head
													for _ in range(index - 1			):
																lowerCamelCase__      :	List[str]						=temp.next
													lowerCamelCase__      :	str						=temp.next
													lowerCamelCase__      :	Union[str, Any]						=temp.next.next
													if index == len(self			) - 1:  # delete at tail
																lowerCamelCase__      :	Tuple						=temp
										return delete_node.data





							def  UpperCAmelCase__				(    self    :Optional[Any]			):





										"""simple docstring"""

										return len(self			) == 0






def   lowerCAmelCase_  (						)  ->None:
			lowerCamelCase__      :	Union[str, Any]						=CircularLinkedList()
			assert len(snake_case_     ) == 0
			assert circular_linked_list.is_empty() is True
			assert str(snake_case_     ) == ""

			try:
						circular_linked_list.delete_front()
						raise AssertionError  # This should not happen
			except IndexError:
						assert True  # This should happen

			try:
						circular_linked_list.delete_tail()
						raise AssertionError  # This should not happen
			except IndexError:
						assert True  # This should happen

			try:
						circular_linked_list.delete_nth(-1     )
						raise AssertionError
			except IndexError:
						assert True

			try:
						circular_linked_list.delete_nth(0     )
						raise AssertionError
			except IndexError:
						assert True

			assert circular_linked_list.is_empty() is True
			for i in range(5     ):
						assert len(snake_case_     ) == i
						circular_linked_list.insert_nth(snake_case_				,       i + 1     )
			assert str(snake_case_     ) == "->".join(str(snake_case_     ) for i in range(1				,       6     )     )

			circular_linked_list.insert_tail(6     )
			assert str(snake_case_     ) == "->".join(str(snake_case_     ) for i in range(1				,       7     )     )
			circular_linked_list.insert_head(0     )
			assert str(snake_case_     ) == "->".join(str(snake_case_     ) for i in range(0				,       7     )     )

			assert circular_linked_list.delete_front() == 0
			assert circular_linked_list.delete_tail() == 6
			assert str(snake_case_     ) == "->".join(str(snake_case_     ) for i in range(1				,       6     )     )
			assert circular_linked_list.delete_nth(2     ) == 3

			circular_linked_list.insert_nth(2				,       3     )
			assert str(snake_case_     ) == "->".join(str(snake_case_     ) for i in range(1				,       6     )     )

			assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
							import doctest

							doctest.testmod()



'''simple docstring'''
lowerCAmelCase   : List[str]             =				2_5_6
# Modulus to hash a string
lowerCAmelCase   : Tuple             =				1_0_0_0_0_0_3




def 	_A  (       A							,A							)  ->				bool:
	lowercase						:		List[Any]   					=		len(A							)
	lowercase						:		List[Any]   					=		len(A							)
	if p_len > t_len:
		return False

	lowercase						:		List[str]   					=		0
	lowercase						:		Dict   					=		0
	lowercase						:		Any   					=		1

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




def 	_A  (       )  ->				None:
	lowercase						:		Dict   					=		"abc1abc12"
	lowercase						:		Union[str, Any]   					=		"alskfjaldsabc1abc1abc12k23adsfabcabc"
	lowercase						:		Any   					=		"alskfjaldsk23adsfabcabc"
	assert rabin_karp(A							,A							) and not rabin_karp(A							,A							)

	# Test 2)
	lowercase						:		str   					=		"ABABX"
	lowercase						:		Union[str, Any]   					=		"ABABZABABYABABX"
	assert rabin_karp(A							,A							)

	# Test 3)
	lowercase						:		str   					=		"AAAB"
	lowercase						:		List[str]   					=		"ABAAAAAB"
	assert rabin_karp(A							,A							)

	# Test 4)
	lowercase						:		List[str]   					=		"abcdabcy"
	lowercase						:		str   					=		"abcxabcdabxabcdabcdabcy"
	assert rabin_karp(A							,A							)

	# Test 5)
	lowercase						:		int   					=		"Lü"
	lowercase						:		Optional[Any]   					=		"Lüsai"
	assert rabin_karp(A							,A							)
	lowercase						:		Tuple   					=		"Lue"
	assert not rabin_karp(A							,A							)
	print("Success."							)


if __name__ == "__main__":
					test_rabin_karp()


