



from __future__ import annotations

from random import random






class 		lowercase						:






	"""simple docstring"""


	def __init__(     self     :						Tuple						,  __UpperCAmelCase     :						int | None = None					)      ->			Optional[Any]:
							UpperCAmelCase_=       value
							UpperCAmelCase_=       random()
							UpperCAmelCase_=       None
							UpperCAmelCase_=       None




	def __repr__(     self     :						Dict					)      ->			str:
							from pprint import pformat

							if self.left is None and self.right is None:
													return F"""'{self.value}: {self.prior:.5}'"""
							else:
													return pformat(
													    {F"""{self.value}: {self.prior:.5}""": (self.left, self.right)}						,  indent=1					)




	def __str__(     self     :						str					)      ->			str:
							UpperCAmelCase_=       str(self.value					) + """ """
							UpperCAmelCase_=       str(self.left or """"""					)
							UpperCAmelCase_=       str(self.right or """"""					)
							return value + left + right



def 	__a					(   lowerCAmelCase_       : Node | None      ,lowerCAmelCase_       : int    )				->			tuple[Node | None, Node | None]:






						'''simple docstring'''



						if root is None:  # None tree is split into 2 Nones
												return None, None
						elif root.value is None:
												return None, None
						else:
												if value < root.value:
																		UpperCAmelCase_,       UpperCAmelCase_=       split(root.left      ,lowerCAmelCase_    )
																		return left, root
												else:
																		UpperCAmelCase_,       UpperCAmelCase_=       split(root.right      ,lowerCAmelCase_    )
																		return root, right



def 	__a					(   lowerCAmelCase_       : Node | None      ,lowerCAmelCase_       : Node | None    )				->			Node | None:






						'''simple docstring'''



						if (not left) or (not right):  # If one node is None, return the other
												return left or right
						elif left.prior < right.prior:
												UpperCAmelCase_=       merge(left.right      ,lowerCAmelCase_    )
												return left
						else:
												UpperCAmelCase_=       merge(lowerCAmelCase_      ,right.left    )
												return right



def 	__a					(   lowerCAmelCase_       : Node | None      ,lowerCAmelCase_       : int    )				->			Node | None:






						'''simple docstring'''



						UpperCAmelCase_=       Node(lowerCAmelCase_    )
						UpperCAmelCase_,       UpperCAmelCase_=       split(lowerCAmelCase_      ,lowerCAmelCase_    )
						return merge(merge(lowerCAmelCase_      ,lowerCAmelCase_    )      ,lowerCAmelCase_    )



def 	__a					(   lowerCAmelCase_       : Node | None      ,lowerCAmelCase_       : int    )				->			Node | None:






						'''simple docstring'''



						UpperCAmelCase_,       UpperCAmelCase_=       split(lowerCAmelCase_      ,value - 1    )
						UpperCAmelCase_,       UpperCAmelCase_=       split(lowerCAmelCase_      ,lowerCAmelCase_    )
						return merge(lowerCAmelCase_      ,lowerCAmelCase_    )



def 	__a					(   lowerCAmelCase_       : Node | None    )				->			None:






						'''simple docstring'''



						if not root:  # None
												return
						else:
												inorder(root.left    )
												print(root.value      ,end=""","""    )
												inorder(root.right    )



def 	__a					(   lowerCAmelCase_       : Node | None      ,lowerCAmelCase_       : str    )				->			Node | None:






						'''simple docstring'''



						for arg in args.split():
												if arg[0] == "+":
																		UpperCAmelCase_=       insert(lowerCAmelCase_      ,int(arg[1:]    )    )

												elif arg[0] == "-":
																		UpperCAmelCase_=       erase(lowerCAmelCase_      ,int(arg[1:]    )    )

												else:
																		print("""Unknown command"""    )

						return root



def 	__a					(   )				->			None:






						'''simple docstring'''



						UpperCAmelCase_=       None
						print(
						    """enter numbers to create a tree, + value to add value into treap, """
						    """- value to erase all nodes with value. 'q' to quit. """    )

						UpperCAmelCase_=       input()
						while args != "q":
												UpperCAmelCase_=       interact_treap(lowerCAmelCase_      ,lowerCAmelCase_    )
												print(lowerCAmelCase_    )
												UpperCAmelCase_=       input()

						print("""good by!"""    )


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()




from __future__ import annotations



def 	__a					(   lowerCAmelCase_       : list[int]      ,lowerCAmelCase_       : int    )				->			list[list[int]]:






						'''simple docstring'''



						UpperCAmelCase_=       []
						UpperCAmelCase_=       []
						UpperCAmelCase_=       0
						UpperCAmelCase_=       sum(lowerCAmelCase_    )
						create_state_space_tree(lowerCAmelCase_      ,lowerCAmelCase_      ,lowerCAmelCase_      ,lowerCAmelCase_      ,lowerCAmelCase_      ,lowerCAmelCase_    )
						return result



def 	__a					(   lowerCAmelCase_       : list[int]      ,lowerCAmelCase_       : int      ,lowerCAmelCase_       : int      ,lowerCAmelCase_       : list[int]      ,lowerCAmelCase_       : list[list[int]]      ,lowerCAmelCase_       : int      ,)				->			None:






						'''simple docstring'''



						if sum(lowerCAmelCase_    ) > max_sum or (remaining_nums_sum + sum(lowerCAmelCase_    )) < max_sum:
												return
						if sum(lowerCAmelCase_    ) == max_sum:
												result.append(lowerCAmelCase_    )
												return
						for index in range(lowerCAmelCase_      ,len(lowerCAmelCase_    )    ):
												create_state_space_tree(
												    lowerCAmelCase_      ,lowerCAmelCase_      ,index + 1      ,[*path, nums[index]]      ,lowerCAmelCase_      ,remaining_nums_sum - nums[index]      ,)
__A       =						[3, 34, 4, 12, 5, 2]
__A       =						9
__A       =						generate_sum_of_subsets_soln(nums, max_sum)



print(*result)




