
'''simple docstring'''

from manim import *


class      a_     (_a			):




       def 							__UpperCamelCase				(   self     ):
         _lowerCAmelCase				:     Optional[Any]       =    Rectangle(height=0.5      ,      width=0.5     )
         _lowerCAmelCase				:     List[str]       =    Rectangle(height=0.46      ,      width=0.46     ).set_stroke(width=0     )

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

         _lowerCAmelCase				:     List[Any]       =    [mem.copy() for i in range(1     )]
         _lowerCAmelCase				:     str       =    VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__      ,      buff=0     )
         _lowerCAmelCase				:     Union[str, Any]       =    Text("""GPU"""      ,      font_size=2_4     )
         _lowerCAmelCase				:     int       =    Group(SCREAMING_SNAKE_CASE__      ,      SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__      ,      buff=0.5      ,      aligned_edge=SCREAMING_SNAKE_CASE__     )
         gpu.align_to(SCREAMING_SNAKE_CASE__      ,      SCREAMING_SNAKE_CASE__     )
         gpu.set_x(gpu.get_x() - 1     )

         self.add(SCREAMING_SNAKE_CASE__     )

         _lowerCAmelCase				:     str       =    [mem.copy() for i in range(6     )]
         _lowerCAmelCase				:     int       =    VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__      ,      buff=0     )

         _lowerCAmelCase				:     List[Any]       =    Text("""Model"""      ,      font_size=2_4     )
         _lowerCAmelCase				:     int       =    Group(SCREAMING_SNAKE_CASE__      ,      SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__      ,      buff=0.5      ,      aligned_edge=SCREAMING_SNAKE_CASE__     )
         model.move_to([3, -1.0, 0]     )

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

         _lowerCAmelCase				:     List[str]       =    MarkupText(
             f'First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'      ,      font_size=2_4      ,      )

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

         _lowerCAmelCase				:     Optional[Any]       =    MarkupText(
             f'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'      ,      font_size=1_8      ,      )

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

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

         self.add(SCREAMING_SNAKE_CASE__     )

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

           if i == 0:
             cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT     )      ,      buff=0.02      ,      direction=SCREAMING_SNAKE_CASE__     )
             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=SCREAMING_SNAKE_CASE__      ,      buff=0.0     )
           else:
             cpu_target.target.next_to(cpu_targs[i - 1].target      ,      direction=SCREAMING_SNAKE_CASE__      ,      buff=0.0     )
           cpu_targs.append(SCREAMING_SNAKE_CASE__     )

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

         self.play(*SCREAMING_SNAKE_CASE__     )
         self.play(*SCREAMING_SNAKE_CASE__     )

         self.wait()









"""simple docstring"""
def      __lowerCamelCase   (							a_     :		int ,   a_     :		str							)			->      Optional[int]:
      __SCREAMING_SNAKE_CASE   :Optional[int]						=  [1]
      for i in range(2 ,   a_							):
            factorials.append(factorials[-1] * i							)
      assert 0 <= k < factorials[-1] * n, "k out of bounds"

      __SCREAMING_SNAKE_CASE   :List[str]						=  []
      __SCREAMING_SNAKE_CASE   :Optional[Any]						=  list(range(a_							)							)

      # Find permutation
      while factorials:
            __SCREAMING_SNAKE_CASE   :Optional[int]						=  factorials.pop()
            __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Dict						=  divmod(a_ ,   a_							)
            permutation.append(elements[number]							)
            elements.remove(elements[number]							)
      permutation.append(elements[0]							)

      return permutation


if __name__ == "__main__":
  import doctest

  doctest.testmod()