

from __future__ import annotations

from collections import deque






class _UpperCamelCase							:
			'''simple docstring'''







			def __init__(	self							:       int					,					a							:       list[str]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					list[dict]    =				[]
				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							:       Tuple					,					a							:       int					,					a							:       str		)							->				int | None:

				"""simple docstring"""

				for state in self.adlist[current_state]["next_states"]:
					if char == self.adlist[state]["value"]:
						return state
				return None
			def 							__UpperCamelCase       (	self							:       List[str]					,					a							:       str		)							->				None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				0
				for character in keyword:
					SCREAMING_SNAKE_CASE      :					Optional[int]    =				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      :					int    =				len(self.adlist		) - 1
					else:
						SCREAMING_SNAKE_CASE      :					Dict    =				next_state
				self.adlist[current_state]["output"].append(a		)
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				None:

				"""simple docstring"""

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






			def 							__UpperCamelCase       (	self							:       Optional[Any]					,					a							:       str		)							->				dict[str, list[int]]:

				"""simple docstring"""

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


if __name__ == "__main__":
			import doctest

			doctest.testmod()




'''simple docstring'''





__a          =		frozenset(
    [
        "prompt",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
        "cross_attention_kwargs",
    ]
)

__a          =		frozenset(["prompt", "negative_prompt"])

__a          =		frozenset([])

__a          =		frozenset(["image"])

__a          =		frozenset(
    [
        "image",
        "height",
        "width",
        "guidance_scale",
    ]
)

__a          =		frozenset(["image"])

__a          =		frozenset(
    [
        "prompt",
        "image",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
    ]
)

__a          =		frozenset(["prompt", "image", "negative_prompt"])

__a          =		frozenset(
    [
        # Text guided image variation with an image mask
        "prompt",
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
    ]
)

__a          =		frozenset(["prompt", "image", "mask_image", "negative_prompt"])

__a          =		frozenset(
    [
        # image variation with an image mask
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
    ]
)

__a          =		frozenset(["image", "mask_image"])

__a          =		frozenset(
    [
        "example_image",
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
    ]
)

__a          =		frozenset(["example_image", "image", "mask_image"])

__a          =		frozenset(["class_labels"])

__a          =		frozenset(["class_labels"])

__a          =		frozenset(["batch_size"])

__a          =		frozenset([])

__a          =		frozenset(["batch_size"])

__a          =		frozenset([])

__a          =		frozenset(
    [
        "prompt",
        "audio_length_in_s",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
        "cross_attention_kwargs",
    ]
)

__a          =		frozenset(["prompt", "negative_prompt"])
__a          =		frozenset(["input_tokens"])

__a          =		frozenset(["input_tokens"])
