
'''simple docstring'''

class 					a_					:


       class 					a_					:
              __lowerCAmelCase      :			List[str]      = """_prev""", """_data""", """_next"""




              def __init__(       self				,				snake_case_				,				snake_case_				,				snake_case_					):
                _lowerCAmelCase    :					List[str]							=   link_p
                _lowerCAmelCase    :					Tuple							=   element
                _lowerCAmelCase    :					Dict							=   link_n







              def 							__UpperCamelCase    (       self					):
                return (
                    f' Prev -> {self._prev is not None}, Next -> {self._next is not None}'
                )




       def __init__(       self					):
         _lowerCAmelCase    :					Tuple							=   self._Node(snake_case_				,				snake_case_				,				snake_case_					)
         _lowerCAmelCase    :					List[Any]							=   self._Node(snake_case_				,				snake_case_				,				snake_case_					)
         _lowerCAmelCase    :					Any							=   self._trailer
         _lowerCAmelCase    :					List[Any]							=   self._header
         _lowerCAmelCase    :					Dict							=   0




       def __len__(       self					):
         return self._size




       def 							__UpperCamelCase    (       self					):
         return self.__len__() == 0




       def 							__UpperCamelCase    (       self				,				snake_case_				,				snake_case_				,				snake_case_					):
         # Create new_node by setting it's prev.link -> header
         # setting it's next.link -> trailer
         _lowerCAmelCase    :					List[str]							=   self._Node(snake_case_				,				snake_case_				,				snake_case_					)
         _lowerCAmelCase    :					Tuple							=   new_node
         _lowerCAmelCase    :					Dict							=   new_node
         self._size += 1
         return self







       def 							__UpperCamelCase    (       self				,				snake_case_					):
         _lowerCAmelCase    :					Tuple							=   node._prev
         _lowerCAmelCase    :					int							=   node._next

         _lowerCAmelCase    :					Union[str, Any]							=   successor
         _lowerCAmelCase    :					Dict							=   predecessor
         self._size -= 1
         _lowerCAmelCase    :					Optional[Any]							=   node._data
         _lowerCAmelCase    :					List[str]							=   None
         del node
         return temp



class 					a_					(_DoublyLinkedBase      ):




       def 							__UpperCamelCase    (       self					):
         if self.is_empty():
           raise Exception("""List is empty"""					)
         return self._header._next._data




       def 							__UpperCamelCase    (       self					):
         if self.is_empty():
           raise Exception("""List is empty"""					)
         return self._trailer._prev._data




       def 							__UpperCamelCase    (       self				,				snake_case_					):
         return self._insert(self._header				,				snake_case_				,				self._header._next					)




       def 							__UpperCamelCase    (       self				,				snake_case_					):
         return self._insert(self._trailer._prev				,				snake_case_				,				self._trailer					)




       def 							__UpperCamelCase    (       self					):
         if self.is_empty():
           raise IndexError("""remove_first from empty list"""					)
         return self._delete(self._header._next					)







       def 							__UpperCamelCase    (       self					):
         if self.is_empty():
           raise IndexError("""remove_first from empty list"""					)
         return self._delete(self._trailer._prev					)



'''simple docstring'''

from __future__ import annotations


class 					a_					:




       def __init__(       self				,				snake_case_ = 0					):
         _lowerCAmelCase    :					Optional[Any]							=   value
         _lowerCAmelCase    :					Node | None							=   None
         _lowerCAmelCase    :					Node | None							=   None



def 		_UpperCAmelCase			(					_lowerCamelCase  :    Node | None					, _lowerCamelCase  :    Node | None						)      ->  Node | None:
  if treea is None:
    return treea
  if treea is None:
    return treea

  _lowerCAmelCase    :					Any							=   treea.value + treea.value
  _lowerCAmelCase    :					Tuple							=   merge_two_binary_trees(treea.left					, treea.left						)
  _lowerCAmelCase    :					List[str]							=   merge_two_binary_trees(treea.right					, treea.right						)
  return treea


def 		_UpperCAmelCase			(					_lowerCamelCase  :    Node | None						)      ->  None:
  if root:
    print(root.value						)
    print_preorder(root.left						)
    print_preorder(root.right						)


if __name__ == "__main__":
     UpperCamelCase_            =    Node(1)
     UpperCamelCase_            =    Node(2)
     UpperCamelCase_            =    Node(3)
     UpperCamelCase_            =    Node(4)

     UpperCamelCase_            =    Node(2)
     UpperCamelCase_            =    Node(4)
     UpperCamelCase_            =    Node(6)
     UpperCamelCase_            =    Node(9)
     UpperCamelCase_            =    Node(5)

     print("""Tree1 is: """)
     print_preorder(treea)
     print("""Tree2 is: """)
     print_preorder(treea)
     UpperCamelCase_            =    merge_two_binary_trees(treea, treea)
     print("""Merged Tree is: """)
     print_preorder(merged_tree)


