
"""simple docstring"""




from __future__ import annotations

from collections import deque







class   _lowercase						:


     '''simple docstring'''





     def __init__(      self ,			__UpperCamelCase  )->					str:
          UpperCAmelCase__							: list[dict] 							=						[]
          self.adlist.append(
              {"value": "", "next_states": [], "fail_state": 0, "output": []}  )

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



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



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



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



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


if __name__ == "__main__":
    import doctest

    doctest.testmod()





"""simple docstring"""




def 							a__ (				lowerCAmelCase	:       list       ,    lowerCAmelCase	:       list		):






     '''simple docstring'''
     _validate_point(lowerCAmelCase		)
     _validate_point(lowerCAmelCase		)
     if len(lowerCAmelCase		) != len(lowerCAmelCase		):
          raise ValueError("Both points must be in the same n-dimensional space"		)

     return float(sum(abs(a - b		) for a, b in zip(lowerCAmelCase       ,    lowerCAmelCase		)		)		)



def 							a__ (				lowerCAmelCase	:       list[float]		):






     '''simple docstring'''
     if point:
          if isinstance(lowerCAmelCase       ,    lowerCAmelCase		):
               for item in point:
                    if not isinstance(lowerCAmelCase       ,    (int, float)		):
                         UpperCAmelCase__							: Tuple 							=						(
                             "Expected a list of numbers as input, found "
                             F"{type(lowerCAmelCase		).__name__}"
                         )
                         raise TypeError(lowerCAmelCase		)
          else:
               UpperCAmelCase__							: Dict 							=						F"Expected a list of numbers as input, found {type(lowerCAmelCase		).__name__}"
               raise TypeError(lowerCAmelCase		)
     else:
          raise ValueError("Missing an input"		)



def 							a__ (				lowerCAmelCase	:       list       ,    lowerCAmelCase	:       list		):






     '''simple docstring'''
     _validate_point(lowerCAmelCase		)
     _validate_point(lowerCAmelCase		)
     if len(lowerCAmelCase		) != len(lowerCAmelCase		):
          raise ValueError("Both points must be in the same n-dimensional space"		)

     return float(sum(abs(x - y		) for x, y in zip(lowerCAmelCase       ,    lowerCAmelCase		)		)		)


if __name__ == "__main__":
    import doctest

    doctest.testmod()



