




from __future__ import annotations

from collections import deque




class 			UpperCAmelCase_      :




							'''simple docstring'''



							def __init__(					self       :	str       ,     a       :	Tuple			)			->					List[Any]:
										SCREAMING_SNAKE_CASE           =					[]
										self.adlist.append(
										    {"""value""": """""", """next_states""": [], """fail_state""": 0, """output""": []}			)

										for keyword in keywords:
													self.add_keyword(A_			)
										self.set_fail_transitions()





							def    _UpperCAmelCase     (					self       :	Optional[Any]       ,     a       :	Dict       ,     a       :	List[str]			)			->					int | None:
										for state in self.adlist[current_state]["next_states"]:
													if char == self.adlist[state]["value"]:
																return state
										return None





							def    _UpperCAmelCase     (					self       :	Optional[int]       ,     a       :	List[str]			)			->					None:
										SCREAMING_SNAKE_CASE           =					0
										for character in keyword:
													SCREAMING_SNAKE_CASE           =					self.find_next_state(A_       ,     A_			)
													if next_state is None:
																self.adlist.append(
																    {
																        """value""": character,
																        """next_states""": [],
																        """fail_state""": 0,
																        """output""": [],
																    }			)
																self.adlist[current_state]["next_states"].append(len(self.adlist			) - 1			)
																SCREAMING_SNAKE_CASE           =					len(self.adlist			) - 1
													else:
																SCREAMING_SNAKE_CASE           =					next_state
										self.adlist[current_state]["output"].append(A_			)





							def    _UpperCAmelCase     (					self       :	Union[str, Any]			)			->					None:
										SCREAMING_SNAKE_CASE           =					deque()
										for node in self.adlist[0]["next_states"]:
													q.append(A_			)
													SCREAMING_SNAKE_CASE           =					0
										while q:
													SCREAMING_SNAKE_CASE           =					q.popleft()
													for child in self.adlist[r]["next_states"]:
																q.append(A_			)
																SCREAMING_SNAKE_CASE           =					self.adlist[r]["""fail_state"""]
																while (
																    self.find_next_state(A_       ,     self.adlist[child]["""value"""]			) is None
																    and state != 0
																):
																			SCREAMING_SNAKE_CASE           =					self.adlist[state]["""fail_state"""]
																SCREAMING_SNAKE_CASE           =					self.find_next_state(
																    A_       ,     self.adlist[child]["""value"""]			)
																if self.adlist[child]["fail_state"] is None:
																			SCREAMING_SNAKE_CASE           =					0
																SCREAMING_SNAKE_CASE           =					(
																    self.adlist[child]["""output"""]
																    + self.adlist[self.adlist[child]["""fail_state"""]]["""output"""]
																)







							def    _UpperCAmelCase     (					self       :	Dict       ,     a       :	Any			)			->					dict[str, list[int]]:
										SCREAMING_SNAKE_CASE           =					{}  # returns a dict with keywords and list of its occurrences
										SCREAMING_SNAKE_CASE           =					0
										for i in range(len(A_			)			):
													while (
													    self.find_next_state(A_       ,     string[i]			) is None
													    and current_state != 0
													):
																SCREAMING_SNAKE_CASE           =					self.adlist[current_state]["""fail_state"""]
													SCREAMING_SNAKE_CASE           =					self.find_next_state(A_       ,     string[i]			)
													if next_state is None:
																SCREAMING_SNAKE_CASE           =					0
													else:
																SCREAMING_SNAKE_CASE           =					next_state
																for key in self.adlist[current_state]["output"]:
																			if key not in result:
																						SCREAMING_SNAKE_CASE           =					[]
																			result[key].append(i - len(A_			) + 1			)
										return result


if __name__ == "__main__":
		import doctest

		doctest.testmod()












from __future__ import annotations

import typing
from collections.abc import Iterable

import numpy as np

__A						:							Dict							=  typing.Union[Iterable[float], Iterable[int], np.ndarray]  # noqa: UP007
__A						:							Tuple							=  typing.Union[np.floataa, int, float]  # noqa: UP007
def 					lowerCamelCase_    (    SCREAMING_SNAKE_CASE					,	SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''
			return np.sqrt(np.sum((np.asarray(SCREAMING_SNAKE_CASE   ) - np.asarray(SCREAMING_SNAKE_CASE   )) ** 2   )   )
def 					lowerCamelCase_    (    SCREAMING_SNAKE_CASE					,	SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''
			return sum((va - va) ** 2 for va, va in zip(SCREAMING_SNAKE_CASE					,	SCREAMING_SNAKE_CASE   )   ) ** (1 / 2)


if __name__ == "__main__":
		def 					lowerCamelCase_    (    ):
					'''simple docstring'''
					from timeit import timeit

					print("""Without Numpy"""   )
					print(
					    timeit(
					        """euclidean_distance_no_np([1, 2, 3], [4, 5, 6])"""					,	number=1_00_00					,	globals=globals()					,	)   )
					print("""With Numpy"""   )
					print(
					    timeit(
					        """euclidean_distance([1, 2, 3], [4, 5, 6])"""					,	number=1_00_00					,	globals=globals()					,	)   )




		benchmark()






