'''simple docstring'''





from copy import deepcopy




class        __A      :



    def __init__(self    :    Dict   ,			__a    :    list[int] | None = None   ,			__a    :    int | None = None ):

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



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



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



    @staticmethod
    def 					_lowercase						(__a    :    int ):
         return index + (index & (-index))



    @staticmethod
    def 					_lowercase						(__a    :    int ):
         return index - (index & (-index))



    def 					_lowercase						(self    :    Tuple   ,			__a    :    int   ,			__a    :    int ):
         if index == 0:
              self.tree[0] += value
              return
         while index < self.size:
              self.tree[index] += value
              UpperCAmelCase_           =   self.next_(__a )



    def 					_lowercase						(self    :    Optional[Any]   ,			__a    :    int   ,			__a    :    int ):
         self.add(__a   ,			value - self.get(__a ) )



    def 					_lowercase						(self    :    Dict   ,			__a    :    int ):
         if right == 0:
              return 0
         UpperCAmelCase_           =   self.tree[0]
         right -= 1  # make right inclusive
         while right > 0:
              result += self.tree[right]
              UpperCAmelCase_           =   self.prev(__a )
         return result



    def 					_lowercase						(self    :    int   ,			__a    :    int   ,			__a    :    int ):
         return self.prefix(__a ) - self.prefix(__a )



    def 					_lowercase						(self    :    str   ,			__a    :    int ):
         return self.query(__a   ,			index + 1 )






    def 					_lowercase						(self    :    List[str]   ,			__a    :    int ):
         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'''





from __future__ import annotations





def 	lowerCAmelCase_				(					snake_case_       : list					,    snake_case_       : int | None = None					,    snake_case_       : int | None = None			)    ->      None:


     '''simple docstring'''




     if start is None:
          UpperCAmelCase_           =   0

     if end is None:
          UpperCAmelCase_           =   len(snake_case_			) - 1

     if start >= end:
          return

     UpperCAmelCase_           =   (start + end) // 2

     slowsort(snake_case_					,    snake_case_					,    snake_case_			)
     slowsort(snake_case_					,    mid + 1					,    snake_case_			)

     if sequence[end] < sequence[mid]:
          UpperCAmelCase_    , UpperCAmelCase_           =   sequence[mid], sequence[end]

     slowsort(snake_case_					,    snake_case_					,    end - 1			)


if __name__ == "__main__":
    from doctest import testmod

    testmod()




