
"""simple docstring"""





from __future__ import annotations

from collections import deque





class 				a :





       """simple docstring"""







       def __init__(			self							,	snake_case_			)    ->				Any:
          _UpperCAmelCase         =      []
          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							,	snake_case_							,	snake_case_			)    ->				int | None:
          for state in self.adlist[current_state]["next_states"]:
             if char == self.adlist[state]["value"]:
                return state
          return None






       def 				__A						(			self							,	snake_case_			)    ->				None:
          _UpperCAmelCase         =      0
          for character in keyword:
             _UpperCAmelCase         =      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			)
                _UpperCAmelCase         =      len(self.adlist			) - 1
             else:
                _UpperCAmelCase         =      next_state
          self.adlist[current_state]["output"].append(__a			)






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






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


if __name__ == "__main__":
 import doctest

 doctest.testmod()






'''simple docstring'''





from __future__ import annotations





def   a_   (		_UpperCAmelCase    :      list[int]				)    ->  bool:
      return len(set(_UpperCAmelCase				)				) == len(_UpperCAmelCase				)


if __name__ == "__main__":
    import doctest

    doctest.testmod()



