"""simple docstring"""




from manim import *
class 						__A							( SCREAMING_SNAKE_CASE_		):






     def     __A  (		self  ):
       _lowerCAmelCase						:       str  			=     Rectangle(height=0.5				,     width=0.5  )
       _lowerCAmelCase						:       List[Any]  			=     Rectangle(height=0.4_6				,     width=0.4_6  ).set_stroke(width=0  )

       _lowerCAmelCase						:       Tuple  			=     Rectangle(height=0.2_5				,     width=0.2_5  )

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

       _lowerCAmelCase						:       Union[str, Any]  			=     [mem.copy() for i in range(4  )]
       _lowerCAmelCase						:       str  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       str  			=     Text("""GPU"""				,     font_size=24  )
       _lowerCAmelCase						:       str  			=     Group(a__				,     a__  ).arrange(a__				,     buff=0.5				,     aligned_edge=a__  )
       gpu.move_to([-1, -1, 0]  )
       self.add(a__  )

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

       _lowerCAmelCase						:       int  			=     Text("""Model"""				,     font_size=24  )
       _lowerCAmelCase						:       int  			=     Group(a__				,     a__  ).arrange(a__				,     buff=0.5				,     aligned_edge=a__  )
       model.move_to([3, -1.0, 0]  )
       self.add(a__  )

       _lowerCAmelCase						:       Optional[Any]  			=     []
       _lowerCAmelCase						:       str  			=     []

       for i, rect in enumerate(a__  ):
         _lowerCAmelCase						:       int  			=     fill.copy().set_fill(a__				,     opacity=0.8  )
         target.move_to(a__  )
         model_arr.append(a__  )

         _lowerCAmelCase						:       Dict  			=     Rectangle(height=0.4_6				,     width=0.4_6  ).set_stroke(width=0.0  ).set_fill(a__				,     opacity=0.8  )
         cpu_target.move_to(cpu_left_col_base[i]  )
         model_cpu_arr.append(a__  )

       self.add(*a__				,     *a__  )

       _lowerCAmelCase						:       str  			=     [meta_mem.copy() for i in range(6  )]
       _lowerCAmelCase						:       Dict  			=     [meta_mem.copy() for i in range(6  )]
       _lowerCAmelCase						:       Optional[int]  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       Optional[Any]  			=     VGroup(*a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       int  			=     VGroup(a__				,     a__  ).arrange(a__				,     buff=0  )
       _lowerCAmelCase						:       Dict  			=     Text("""Disk"""				,     font_size=24  )
       _lowerCAmelCase						:       Optional[int]  			=     Group(a__				,     a__  ).arrange(a__				,     buff=0.5				,     aligned_edge=a__  )
       disk.move_to([-4, -1.2_5, 0]  )
       self.add(a__				,     a__  )

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

       _lowerCAmelCase						:       Dict  			=     MarkupText(
           F"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"				,     font_size=18				,     )

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

       self.add(a__				,     a__  )

       _lowerCAmelCase						:       List[str]  			=     MarkupText(
           F"<span fgcolor='{BLUE}'>●</span> Checkpoint"				,     font_size=18				,     )

       blue_text.next_to(a__				,     DOWN * 2.4				,     aligned_edge=key_text.get_left()  )
       self.add(a__  )

       _lowerCAmelCase						:       List[str]  			=     MarkupText(
           F"Now watch as an input is passed through the model\nand how the memory is utilized and handled."				,     font_size=24				,     )
       step_a.move_to([2, 2, 0]  )

       self.play(Write(a__  )  )

       _lowerCAmelCase						:       Union[str, Any]  			=     Square(0.3  )
       input.set_fill(a__				,     opacity=1.0  )
       input.set_stroke(width=0.0  )
       input.next_to(model_base[0]				,     a__				,     buff=0.5  )

       self.play(Write(a__  )  )

       input.generate_target()
       input.target.next_to(model_arr[0]				,     direction=a__				,     buff=0.0_2  )
       self.play(MoveToTarget(a__  )  )

       self.play(FadeOut(a__  )  )

       _lowerCAmelCase						:       Dict  			=     Arrow(start=a__				,     end=a__				,     color=a__				,     buff=0.5  )
       a.next_to(model_arr[0].get_left()				,     a__				,     buff=0.2  )

       model_cpu_arr[0].generate_target()
       model_cpu_arr[0].target.move_to(gpu_rect[0]  )

       _lowerCAmelCase						:       Optional[Any]  			=     MarkupText(
           F"As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back."				,     font_size=24				,     )
       step_a.move_to([2, 2, 0]  )

       self.play(Write(a__				,     run_time=3  )  )

       _lowerCAmelCase						:       Optional[int]  			=     {"""run_time""": 1, """fade_in""": True, """fade_out""": True, """buff""": 0.0_2}

       self.play(
           Write(a__  )				,     Circumscribe(model_arr[0]				,     color=a__				,     **a__  )				,     Circumscribe(model_cpu_arr[0]				,     color=a__				,     **a__  )				,     Circumscribe(gpu_rect[0]				,     color=a__				,     **a__  )				,     )
       self.play(MoveToTarget(model_cpu_arr[0]  )  )

       _lowerCAmelCase						:       Any  			=     a.copy()
       for i in range(6  ):
         a_c.next_to(model_arr[i].get_right() + 0.0_2				,     a__				,     buff=0.2  )

         input.generate_target()
         input.target.move_to(model_arr[i].get_right() + 0.0_2  )

         _lowerCAmelCase						:       Union[str, Any]  			=     AnimationGroup(
             FadeOut(a__				,     run_time=0.5  )				,     MoveToTarget(a__				,     run_time=0.5  )				,     FadeIn(a__				,     run_time=0.5  )				,     lag_ratio=0.2  )

         self.play(a__  )

         model_cpu_arr[i].generate_target()
         model_cpu_arr[i].target.move_to(cpu_left_col_base[i]  )

         if i < 5:
           model_cpu_arr[i + 1].generate_target()
           model_cpu_arr[i + 1].target.move_to(gpu_rect[0]  )
           if i >= 1:
             _lowerCAmelCase						:       int  			=     0.7

           self.play(
               Circumscribe(model_arr[i]				,     **a__  )				,     Circumscribe(cpu_left_col_base[i]				,     **a__  )				,     Circumscribe(cpu_left_col_base[i + 1]				,     color=a__				,     **a__  )				,     Circumscribe(gpu_rect[0]				,     color=a__				,     **a__  )				,     Circumscribe(model_arr[i + 1]				,     color=a__				,     **a__  )				,     )
           if i < 1:
             self.play(
                 MoveToTarget(model_cpu_arr[i]  )				,     MoveToTarget(model_cpu_arr[i + 1]  )				,     )
           else:
             self.play(
                 MoveToTarget(model_cpu_arr[i]				,     run_time=0.7  )				,     MoveToTarget(model_cpu_arr[i + 1]				,     run_time=0.7  )				,     )
         else:
           model_cpu_arr[i].generate_target()
           model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]  )
           input.generate_target()
           input.target.next_to(model_arr[-1].get_right()				,     RIGHT + 0.0_2				,     buff=0.2  )

           self.play(
               Circumscribe(model_arr[-1]				,     color=a__				,     **a__  )				,     Circumscribe(cpu_left_col_base[-1]				,     color=a__				,     **a__  )				,     Circumscribe(gpu_rect[0]				,     color=a__				,     **a__  )				,     )

           self.play(MoveToTarget(model_cpu_arr[i]  )  )

         _lowerCAmelCase						:       Any  			=     a_c
         _lowerCAmelCase						:       Any  			=     a_c.copy()

       input.generate_target()
       input.target.next_to(model_base[-1]				,     RIGHT + 0.0_2				,     buff=0.5  )
       self.play(
           FadeOut(a__  )				,     FadeOut(a__				,     run_time=0.5  )				,     )

       _lowerCAmelCase						:       List[str]  			=     MarkupText(F"Inference on a model too large for GPU memory\nis successfully completed."				,     font_size=24  )
       step_a.move_to([2, 2, 0]  )

       self.play(Write(a__				,     run_time=3  )				,     MoveToTarget(a__  )  )

       self.wait()










'''simple docstring'''







def 						snake_case_							(_a	:							str    ,   _a	:							str     ):
    UpperCAmelCase			       =		len(_a     ) + 1
    UpperCAmelCase			       =		len(_a     ) + 1

    # dp is a 2d matrix where dp[i][j] denotes whether prefix string of
    # length i of input_string matches with prefix string of length j of
    # given pattern.
    # "dp" stands for dynamic programming.
    UpperCAmelCase			       =		[[0 for i in range(_a     )] for j in range(_a     )]

    # since string of zero length match pattern of zero length
    UpperCAmelCase			       =		1

    # since pattern of zero length will never match with string of non-zero length
    for i in range(1    ,   _a     ):
        UpperCAmelCase			       =		0

    # since string of zero length will match with pattern where there
    # is at least one * alternatively
    for j in range(1    ,   _a     ):
        UpperCAmelCase			       =		dp[0][j - 2] if pattern[j - 1] == '''*''' else 0

    # now using bottom-up approach to find for all remaining lengths
    for i in range(1    ,   _a     ):
        for j in range(1    ,   _a     ):
            if input_string[i - 1] == pattern[j - 1] or pattern[j - 1] == ".":
                UpperCAmelCase			       =		dp[i - 1][j - 1]

            elif pattern[j - 1] == "*":
                if dp[i][j - 2] == 1:
                    UpperCAmelCase			       =		1
                elif pattern[j - 2] in (input_string[i - 1], "."):
                    UpperCAmelCase			       =		dp[i - 1][j]
                else:
                    UpperCAmelCase			       =		0
            else:
                UpperCAmelCase			       =		0

    return bool(dp[-1][-1]     )


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   # inputing the strings
   # input_string = input("input a string :")
   # pattern = input("input a pattern :")

   A     ='aab'
   A     ='c*a*b'

   # using function to check whether given string matches the given pattern
   if match_pattern(input_string, pattern):
      print(f"""{input_string} matches the given pattern {pattern}""")
   else:
      print(f"""{input_string} does not match with the given pattern {pattern}""")




