
from manim import *






class     UpperCAmelCase						(		A_					):



   def 							_SCREAMING_SNAKE_CASE  (self						:   Optional[int]					)						->      List[Any]:


          '''simple docstring'''


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

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

          snake_case			:  str     							= [mem.copy() for i in range(4					)]
          snake_case			:  Optional[int]     							= VGroup(*snake_case__					).arrange(snake_case__       ,		buff=0					)
          snake_case			:  Tuple     							= Text("GPU"       ,		font_size=24					)
          snake_case			:  str     							= Group(snake_case__       ,		snake_case__					).arrange(snake_case__       ,		buff=0.5       ,		aligned_edge=snake_case__					)
          gpu.move_to([-1, -1, 0]					)
          self.add(snake_case__					)

          snake_case			:  Tuple     							= [mem.copy() for i in range(6					)]
          snake_case			:  int     							= VGroup(*snake_case__					).arrange(snake_case__       ,		buff=0					)

          snake_case			:  Union[str, Any]     							= Text("Model"       ,		font_size=24					)
          snake_case			:  int     							= Group(snake_case__       ,		snake_case__					).arrange(snake_case__       ,		buff=0.5       ,		aligned_edge=snake_case__					)
          model.move_to([3, -1.0, 0]					)
          self.add(snake_case__					)

          snake_case			:  Tuple     							= []
          for i, rect in enumerate(snake_case__					):
                 rect.set_stroke(snake_case__					)
                 # target = fill.copy().set_fill(YELLOW, opacity=0.7)
                 # target.move_to(rect)
                 # self.add(target)

                 snake_case			:  Dict     							= Rectangle(height=0.46 / 4       ,		width=0.46 / 3					).set_stroke(width=0.0					).set_fill(snake_case__       ,		opacity=0.7					)

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

          snake_case			:  Optional[int]     							= [mem.copy() for i in range(6					)]
          snake_case			:  Optional[int]     							= VGroup(*snake_case__					).arrange(snake_case__       ,		buff=0					)

          snake_case			:  Tuple     							= Text("Loaded Checkpoint"       ,		font_size=24					)
          snake_case			:  int     							= Group(snake_case__       ,		snake_case__					).arrange(snake_case__       ,		aligned_edge=snake_case__       ,		buff=0.4					)
          checkpoint.move_to([3, 0.5, 0]					)

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

          snake_case			:  List[str]     							= 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(snake_case__       ,		snake_case__					)

          snake_case			:  str     							= MarkupText(
              f"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""       ,		font_size=18       ,		)

          blue_text.next_to(snake_case__       ,		DOWN * 2.4       ,		aligned_edge=key_text.get_left()					)

          snake_case			:  Dict     							= MarkupText(
              f"""Next, a <i><span fgcolor=\"{BLUE}\">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor=\"{BLUE}\">single shard</span>."""       ,		font_size=24       ,		)
          step_a.move_to([2, 2, 0]					)
          self.play(Write(snake_case__					)       ,		Write(snake_case__					)					)

          self.play(Write(snake_case__       ,		run_time=1					)       ,		Create(snake_case__       ,		run_time=1					)					)

          snake_case			:  Optional[Any]     							= []
          snake_case			:  str     							= []
          for i, rect in enumerate(snake_case__					):
                 snake_case			:  int     							= fill.copy().set_fill(snake_case__       ,		opacity=0.7					)
                 target.move_to(snake_case__					)
                 first_animations.append(GrowFromCenter(snake_case__       ,		run_time=1					)					)

                 snake_case			:  Dict     							= target.copy()
                 cpu_target.generate_target()
                 if i < 5:
                        cpu_target.target.move_to(cpu_left_col_base[i + 1]					)
                 else:
                        cpu_target.target.move_to(cpu_right_col_base[i - 5]					)
                 second_animations.append(MoveToTarget(snake_case__       ,		run_time=1.5					)					)

          self.play(*snake_case__					)
          self.play(*snake_case__					)
          self.wait()







from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

__lowerCamelCase				=			TypeVar("""T""")






class     UpperCAmelCase						(		Generic[T]					):



   def __init__(self						:   int       ,		snake_case__						:   list[T]       ,		snake_case__						:   Callable[[T, T], T]					)						->      None:


          '''simple docstring'''


          snake_case			:  Any | T     							= None

          snake_case			:  int     							= len(snake_case__					)
          snake_case			:  list[T]     							= [any_type for _ in range(self.N					)] + arr
          snake_case			:  str     							= fnc
          self.build()



   def 							_SCREAMING_SNAKE_CASE  (self						:   Union[str, Any]					)						->      None:


          '''simple docstring'''


          for p in range(self.N - 1       ,		0       ,		-1					):
                 snake_case			:  int     							= self.fn(self.st[p * 2]       ,		self.st[p * 2 + 1]					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   Dict       ,		snake_case__						:   int       ,		snake_case__						:   T					)						->      None:


          '''simple docstring'''


          p += self.N
          snake_case			:  int     							= v
          while p > 1:
                 snake_case			:  List[str]     							= p // 2
                 snake_case			:  Tuple     							= self.fn(self.st[p * 2]       ,		self.st[p * 2 + 1]					)



   def 							_SCREAMING_SNAKE_CASE  (self						:   Optional[Any]       ,		snake_case__						:   int       ,		snake_case__						:   int					)						->      T | None:  # noqa: E741


          '''simple docstring'''


          snake_case							,   snake_case			:  Optional[int]     							= l + self.N, r + self.N

          snake_case			:  T | None     							= None
          while l <= r:
                 if l % 2 == 1:
                        snake_case			:  List[str]     							= self.st[l] if res is None else self.fn(snake_case__       ,		self.st[l]					)
                 if r % 2 == 0:
                        snake_case			:  int     							= self.st[r] if res is None else self.fn(snake_case__       ,		self.st[r]					)
                 snake_case							,   snake_case			:  str     							= (l + 1) // 2, (r - 1) // 2
          return res


if __name__ == "__main__":
   from functools import reduce

   __lowerCamelCase				=			[1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

   __lowerCamelCase				=			{
       0: 7,
       1: 2,
       2: 6,
       3: -14,
       4: 5,
       5: 4,
       6: 7,
       7: -10,
       8: 9,
       9: 10,
       10: 12,
       11: 1,
   }

   __lowerCamelCase				=			SegmentTree(test_array, min)
   __lowerCamelCase				=			SegmentTree(test_array, max)
   __lowerCamelCase				=			SegmentTree(test_array, lambda a, b: a + b)


   def      UpperCamelCase   (       ):
          for i in range(len(__lowerCamelCase       )       ):
                 for j in range(__lowerCamelCase							,   len(__lowerCamelCase       )       ):
                        snake_case			:  int     							= reduce(__lowerCamelCase							,   test_array[i : j + 1]       )
                        snake_case			:  Tuple     							= reduce(__lowerCamelCase							,   test_array[i : j + 1]       )
                        snake_case			:  Union[str, Any]     							= reduce(lambda __lowerCamelCase							,   __lowerCamelCase       : a + b							,   test_array[i : j + 1]       )
                        assert min_range == min_segment_tree.query(__lowerCamelCase							,   __lowerCamelCase       )
                        assert max_range == max_segment_tree.query(__lowerCamelCase							,   __lowerCamelCase       )
                        assert sum_range == sum_segment_tree.query(__lowerCamelCase							,   __lowerCamelCase       )

   test_all_segments()

   for index, value in test_updates.items():
      __lowerCamelCase				=			value
      min_segment_tree.update(index, value)
      max_segment_tree.update(index, value)
      sum_segment_tree.update(index, value)
      test_all_segments()





