






"""simple docstring"""






from manim import *




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      def _SCREAMING_SNAKE_CASE (						self     :  Optional[int]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[str]    						=		Rectangle(height=0.5						,	width=0.5)
          SCREAMING_SNAKE_CASE_      :  Dict    						=		Rectangle(height=0.46						,	width=0.46).set_stroke(width=0)

          SCREAMING_SNAKE_CASE_      :  Any    						=		[mem.copy() for i in range(6)]
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		[mem.copy() for i in range(6)]
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		VGroup(*lowercase_).arrange(lowercase_						,	buff=0)
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		VGroup(*lowercase_).arrange(lowercase_						,	buff=0)
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		VGroup(lowercase_						,	lowercase_).arrange(lowercase_						,	buff=0)
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		Text('''CPU'''						,	font_size=24)
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		Group(lowercase_						,	lowercase_).arrange(lowercase_						,	buff=0.5						,	aligned_edge=lowercase_)
          cpu.move_to([-2.5, -0.5, 0])
          self.add(lowercase_)

          SCREAMING_SNAKE_CASE_      :  List[str]    						=		[mem.copy() for i in range(1)]
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		VGroup(*lowercase_).arrange(lowercase_						,	buff=0)
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		Text('''GPU'''						,	font_size=24)
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		Group(lowercase_						,	lowercase_).arrange(lowercase_						,	buff=0.5						,	aligned_edge=lowercase_)
          gpu.align_to(lowercase_						,	lowercase_)
          gpu.set_x(gpu.get_x() - 1)

          self.add(lowercase_)

          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		[mem.copy() for i in range(6)]
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		VGroup(*lowercase_).arrange(lowercase_						,	buff=0)

          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		Text('''Model'''						,	font_size=24)
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		Group(lowercase_						,	lowercase_).arrange(lowercase_						,	buff=0.5						,	aligned_edge=lowercase_)
          model.move_to([3, -1.0, 0])

          self.play(
              Create(lowercase_						,	run_time=1)						,	Create(lowercase_						,	run_time=1)						,	Create(lowercase_						,	run_time=1)						,	)

          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		MarkupText(
              F'First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'						,	font_size=24						,	)

          SCREAMING_SNAKE_CASE_      :  Dict    						=		Square(side_length=2.2)
          key.move_to([-5, 2, 0])

          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		MarkupText(
              F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'						,	font_size=18						,	)

          key_text.move_to([-5, 2.4, 0])

          step_a.move_to([2, 2, 0])
          self.play(Write(lowercase_						,	run_time=2.5)						,	Write(lowercase_)						,	Write(lowercase_))

          self.add(lowercase_)

          SCREAMING_SNAKE_CASE_      :  Any    						=		[]
          SCREAMING_SNAKE_CASE_      :  Any    						=		[]
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		[]
          for i, rect in enumerate(lowercase_):
              SCREAMING_SNAKE_CASE_      :  Any    						=		Rectangle(height=0.46						,	width=0.46).set_stroke(width=0.0).set_fill(lowercase_						,	opacity=0.7)
              cpu_target.move_to(lowercase_)
              cpu_target.generate_target()
              SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		0.46 / 4
              SCREAMING_SNAKE_CASE_      :  str    						=		0.46 / 3

              if i == 0:
                  cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT)						,	buff=0.02						,	direction=lowercase_)
                  cpu_target.target.set_x(cpu_target.target.get_x() + 0.1)
              elif i == 3:
                  cpu_target.target.next_to(cpu_targs[0].target						,	direction=lowercase_						,	buff=0.0)
              else:
                  cpu_target.target.next_to(cpu_targs[i - 1].target						,	direction=lowercase_						,	buff=0.0)
              cpu_targs.append(lowercase_)

              first_animations.append(rect.animate(run_time=0.5).set_stroke(lowercase_))
              second_animations.append(MoveToTarget(lowercase_						,	run_time=1.5))

          self.play(*lowercase_)
          self.play(*lowercase_)

          self.wait()



from __future__ import annotations

from collections import deque





class      A							:


   def __init__(self     :						Dict       ,  __UpperCAmelCase     :						list[str]		)						->				Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  []
         self.adlist.append(
             {"value": "", "next_states": [], "fail_state": 0, "output": []}		)

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


   def 			lowercase_      (self     :						Tuple       ,  __UpperCAmelCase     :						int       ,  __UpperCAmelCase     :						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 			lowercase_      (self     :						Dict       ,  __UpperCAmelCase     :						str		)						->				None:
         """simple docstring"""



         UpperCAmelCase__								=  0
         for character in keyword:
               UpperCAmelCase__								=  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__								=  len(self.adlist		) - 1
               else:
                     UpperCAmelCase__								=  next_state
         self.adlist[current_state]["output"].append(__UpperCAmelCase		)


   def 			lowercase_      (self     :						Optional[int]		)						->				None:
         """simple docstring"""



         UpperCAmelCase__								=  deque()
         for node in self.adlist[0]["next_states"]:
               q.append(__UpperCAmelCase		)
               UpperCAmelCase__								=  0
         while q:
               UpperCAmelCase__								=  q.popleft()
               for child in self.adlist[r]["next_states"]:
                     q.append(__UpperCAmelCase		)
                     UpperCAmelCase__								=  self.adlist[r]["fail_state"]
                     while (
                         self.find_next_state(__UpperCAmelCase       ,  self.adlist[child]["value"]		) is None
                         and state != 0
                     ):
                           UpperCAmelCase__								=  self.adlist[state]["fail_state"]
                     UpperCAmelCase__								=  self.find_next_state(
                         __UpperCAmelCase       ,  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 			lowercase_      (self     :						Union[str, Any]       ,  __UpperCAmelCase     :						str		)						->				dict[str, list[int]]:
         """simple docstring"""



         UpperCAmelCase__								=  {}  # returns a dict with keywords and list of its occurrences
         UpperCAmelCase__								=  0
         for i in range(len(__UpperCAmelCase		)		):
               while (
                   self.find_next_state(__UpperCAmelCase       ,  string[i]		) is None
                   and current_state != 0
               ):
                     UpperCAmelCase__								=  self.adlist[current_state]["fail_state"]
               UpperCAmelCase__								=  self.find_next_state(__UpperCAmelCase       ,  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(__UpperCAmelCase		) + 1		)
         return result


if __name__ == "__main__":
      import doctest

      doctest.testmod()



