



from collections import deque


def A    (							__UpperCamelCase       )    ->   List[Any]:
			A__	  =     len(__UpperCamelCase       )
			A__	  =     deque()
			A__	  =     [False for _ in range(__UpperCamelCase       )]
			A__	  =     [-1 for _ in range(__UpperCamelCase       )]
			A__	  =     index_of[:]

			def strong_connect(__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       ):
						A__	  =     index  # the number when this node is seen
						A__	  =     index  # lowest rank node reachable from here
						index += 1
						stack.append(__UpperCamelCase       )
						A__	  =     True

						for w in g[v]:
									if index_of[w] == -1:
												A__	  =     strong_connect(__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )
												A__	  =     (
												    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
												)
									elif on_stack[w]:
												A__	  =     (
												    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
												)

						if lowlink_of[v] == index_of[v]:
									A__	  =     []
									A__	  =     stack.pop()
									A__	  =     False
									component.append(__UpperCamelCase       )
									while w != v:
												A__	  =     stack.pop()
												A__	  =     False
												component.append(__UpperCamelCase       )
									components.append(__UpperCamelCase       )
						return index

			A__	  =     []
			for v in range(__UpperCamelCase       ):
						if index_of[v] == -1:
									strong_connect(__UpperCamelCase			,						0			,						__UpperCamelCase       )

			return components


def A    (							__UpperCamelCase			,						__UpperCamelCase       )    ->   List[Any]:
			A__	  =     [[] for _ in range(__UpperCamelCase       )]
			for u, v in edges:
						g[u].append(__UpperCamelCase       )
			return g


if __name__ == "__main__":
							# Test
							SCREAMING_SNAKE_CASE__   			=   7
							SCREAMING_SNAKE_CASE__   			=   [0, 0, 1, 2, 3, 3, 4, 4, 6]
							SCREAMING_SNAKE_CASE__   			=   [1, 3, 2, 0, 1, 4, 5, 6, 5]
							SCREAMING_SNAKE_CASE__   			=   [(u, v) for u, v in zip(source, target)]
							SCREAMING_SNAKE_CASE__   			=   create_graph(n_vertices, edges)

							assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)








'''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()


