



'''simple docstring'''





from __future__ import annotations

from collections import deque



class  snake_case__						:
 def __init__(   self						:							Optional[int]      ,     __a						:							List[Any]  )      ->   List[str]:







       '''simple docstring'''
       __snake_case :   Tuple													=    []
       self.adlist.append(
           {'value': '', 'next_states': [], 'fail_state': 0, 'output': []}  )

       for keyword in keywords:
             self.add_keyword(A_  )
       self.set_fail_transitions()
 def A_   (   self						:							Dict      ,     __a						:							Any      ,     __a						:							Any  )      ->   int | None:







       '''simple docstring'''






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







       '''simple docstring'''
       __snake_case :   Union[str, Any]													=    0
       for character in keyword:
             __snake_case :   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  )
                   __snake_case :   Optional[Any]													=    len(self.adlist  ) - 1
             else:
                   __snake_case :   Any													=    next_state
       self.adlist[current_state]["output"].append(A_  )
 def A_   (   self						:							Any  )      ->   None:







       '''simple docstring'''
       __snake_case :   Tuple													=    deque()
       for node in self.adlist[0]["next_states"]:
             q.append(A_  )
             __snake_case :   Optional[int]													=    0
       while q:
             __snake_case :   Optional[Any]													=    q.popleft()
             for child in self.adlist[r]["next_states"]:
                   q.append(A_  )
                   __snake_case :   List[str]													=    self.adlist[r]['fail_state']
                   while (
                       self.find_next_state(A_      ,     self.adlist[child]['value']  ) is None
                       and state != 0
                   ):
                         __snake_case :   Tuple													=    self.adlist[state]['fail_state']
                   __snake_case :   Tuple													=    self.find_next_state(
                       A_      ,     self.adlist[child]['value']  )
                   if self.adlist[child]["fail_state"] is None:
                         __snake_case :   Tuple													=    0
                   __snake_case :   Tuple													=    (
                       self.adlist[child]['output']
                       + self.adlist[self.adlist[child]['fail_state']]['output']
                   )





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







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


if __name__ == "__main__":
    import doctest

    doctest.testmod()





'''simple docstring'''
from string import ascii_lowercase, ascii_uppercase







def 		A_(     A						:		str):
							if not sentence:
														return ""
							UpperCamelCase   			=     dict(zip(A		,     A))
							return lower_to_upper.get(sentence[0]		,     sentence[0]) + sentence[1:]


if __name__ == "__main__":
						from doctest import testmod

						testmod()




