




from copy import deepcopy







class __snake_case			:







   def __init__(      self		:						List[str]					,						_snake_case		:						list[int] | None = None					,						_snake_case		:						int | None = None):

        """simple docstring"""


        if arr is None and size is not None:
             UpperCAmelCase_          =							size
             UpperCAmelCase_          =							[0] * size
        elif arr is not None:
             self.init(_snake_case)
        else:
             raise ValueError('''Either arr or size must be specified''')







   def lowerCamelCase						(      self		:						Tuple					,						_snake_case		:						list[int]):

        """simple docstring"""


        UpperCAmelCase_          =							len(_snake_case)
        UpperCAmelCase_          =							deepcopy(_snake_case)
        for i in range(1					,						self.size):
             UpperCAmelCase_          =							self.next_(_snake_case)
             if j < self.size:
                  self.tree[j] += self.tree[i]







   def lowerCamelCase						(      self		:						List[Any]):

        """simple docstring"""


        UpperCAmelCase_          =							self.tree[:]
        for i in range(self.size - 1					,						0					,						-1):
             UpperCAmelCase_          =							self.next_(_snake_case)
             if j < self.size:
                  arr[j] -= arr[i]
        return arr







   @staticmethod
   def lowerCamelCase						(      _snake_case		:						int):

        """simple docstring"""


        return index + (index & (-index))







   @staticmethod
   def lowerCamelCase						(      _snake_case		:						int):

        """simple docstring"""


        return index - (index & (-index))







   def lowerCamelCase						(      self		:						Tuple					,						_snake_case		:						int					,						_snake_case		:						int):

        """simple docstring"""


        if index == 0:
             self.tree[0] += value
             return
        while index < self.size:
             self.tree[index] += value
             UpperCAmelCase_          =							self.next_(_snake_case)







   def lowerCamelCase						(      self		:						Tuple					,						_snake_case		:						int					,						_snake_case		:						int):

        """simple docstring"""


        self.add(_snake_case					,						value - self.get(_snake_case))







   def lowerCamelCase						(      self		:						str					,						_snake_case		:						int):

        """simple docstring"""


        if right == 0:
             return 0
        UpperCAmelCase_          =							self.tree[0]
        right -= 1  # make right inclusive
        while right > 0:
             result += self.tree[right]
             UpperCAmelCase_          =							self.prev(_snake_case)
        return result







   def lowerCamelCase						(      self		:						Dict					,						_snake_case		:						int					,						_snake_case		:						int):

        """simple docstring"""


        return self.prefix(_snake_case) - self.prefix(_snake_case)







   def lowerCamelCase						(      self		:						Optional[int]					,						_snake_case		:						int):

        """simple docstring"""


        return self.query(_snake_case					,						index + 1)







   def lowerCamelCase						(      self		:						Tuple					,						_snake_case		:						int):

        """simple docstring"""


        value -= self.tree[0]
        if value < 0:
             return -1

        UpperCAmelCase_          =							1  # Largest power of 2 <= size
        while j * 2 < self.size:
             j *= 2

        UpperCAmelCase_          =							0

        while j > 0:
             if i + j < self.size and self.tree[i + j] <= value:
                  value -= self.tree[i + j]
                  i += j
             j //= 2
        return i


if __name__ == "__main__":
    import doctest

    doctest.testmod()










'''simple docstring'''


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
				import ctypes
				import msvcrt  # noqa





				class     lowercase__  (						ctypes.Structure					):





											'''simple docstring'''


											A_							:      Optional[Any]      	=  [("""size""", ctypes.c_int), ("""visible""", ctypes.c_byte)]







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       Tuple     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       Tuple     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25l"""     )
								sys.stdout.flush()







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       int     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       List[str]     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Tuple     		=      True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25h"""     )
								sys.stdout.flush()







@contextmanager
def 			snake_case_   (  ):







				"""simple docstring"""





				try:
								hide_cursor()
								yield
				finally:
								show_cursor()




