"""simple docstring"""






from __future__ import annotations

from collections.abc import Iterable, Iterator
from dataclasses import dataclass

__lowerCAmelCase       :			Any   	=(3, 9, -1_1, 0, 7, 5, 1, -1)
__lowerCAmelCase       :			Dict   	=(4, 6, 2, 0, 8, 1_0, 3, -2)





@dataclass
class 					_A		:
      snake_case__     :  int
      snake_case__     :  Node | None






class 					_A		:

      def __init__(		self						,			__lowerCAmelCase		):







            """simple docstring"""



            lowercase								=      None
            for i in sorted(__lowerCAmelCase						,			reverse=__lowerCAmelCase		):
                  lowercase								=      Node(__lowerCAmelCase						,			self.head		)

      def __iter__(		self		):







            """simple docstring"""



            lowercase								=      self.head
            while node:
                  yield node.data
                  lowercase								=      node.next_node

      def __len__(		self		):







            """simple docstring"""



            return sum(1 for _ in self		)







      def __str__(		self		):







            """simple docstring"""



            return " -> ".join([str(__lowerCAmelCase		) for node in self]		)






def      UpperCAmelCase__			(							lowerCAmelCase__	:SortedLinkedList   ,						lowerCAmelCase__	:SortedLinkedList						)					->       SortedLinkedList:
      '''simple docstring'''


      return SortedLinkedList(list(lowerCAmelCase__						) + list(lowerCAmelCase__						)						)


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       __lowerCAmelCase       :			Tuple   	=SortedLinkedList
       print(merge_lists(SSL(test_data_odd), SSL(test_data_even)))




"""simple docstring"""






from copy import deepcopy





class 					_A		:

      def __init__(		self						,			__lowerCAmelCase = None						,			__lowerCAmelCase = None		):







            """simple docstring"""



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

      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



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

      def 							A__			(		self		):







            """simple docstring"""



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

      @staticmethod
      def 							A__			(		__lowerCAmelCase		):







            """simple docstring"""



            return index + (index & (-index))

      @staticmethod
      def 							A__			(		__lowerCAmelCase		):







            """simple docstring"""



            return index - (index & (-index))

      def 							A__			(		self						,			__lowerCAmelCase						,			__lowerCAmelCase		):







            """simple docstring"""



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

      def 							A__			(		self						,			__lowerCAmelCase						,			__lowerCAmelCase		):







            """simple docstring"""



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

      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



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

      def 							A__			(		self						,			__lowerCAmelCase						,			__lowerCAmelCase		):







            """simple docstring"""



            return self.prefix(__lowerCAmelCase		) - self.prefix(__lowerCAmelCase		)

      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



            return self.query(__lowerCAmelCase						,			index + 1		)







      def 							A__			(		self						,			__lowerCAmelCase		):







            """simple docstring"""



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

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

            lowercase								=      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()



