code: 
  
  '''simple docstring'''
  
  
  
  
  
  from __future__ import annotations
  
  import unittest
  from collections.abc import Iterator
  
  class __UpperCamelCase    :
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__	):
  						UpperCAmelCase__:  str		       =   label
  						UpperCAmelCase__:  Dict		       =   parent
  						UpperCAmelCase__:  str		       =   None
  						UpperCAmelCase__:  Optional[int]		       =   None
  
  class __UpperCamelCase    :
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self	):
  						UpperCAmelCase__:  Dict		       =   None
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[Any]		       =   None
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return self.root is None
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						UpperCAmelCase__:  str		       =   self._put(self.root							,			a_	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__ = None	):
  						if node is None:
  							UpperCAmelCase__:  str		       =   Node(a_							,			a_	)
  						else:
  							if label < node.label:
  								UpperCAmelCase__:  Union[str, Any]		       =   self._put(node.left							,			a_							,			a_	)
  							elif label > node.label:
  								UpperCAmelCase__:  Optional[Any]		       =   self._put(node.right							,			a_							,			a_	)
  							else:
  								UpperCAmelCase__:  Optional[int]		       =   F"Node with label {label} already exists"
  								raise Exception(a_	)
  
  						return node
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						return self._search(self.root							,			a_	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__	):
  						if node is None:
  							UpperCAmelCase__:  List[Any]		       =   F"Node with label {label} does not exist"
  							raise Exception(a_	)
  						else:
  							if label < node.label:
  								UpperCAmelCase__:  Tuple		       =   self._search(node.left							,			a_	)
  							elif label > node.label:
  								UpperCAmelCase__:  Dict		       =   self._search(node.right							,			a_	)
  
  						return node
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						UpperCAmelCase__:  Optional[Any]		       =   self.search(a_	)
  						if node.right and node.left:
  							UpperCAmelCase__:  int		       =   self._get_lowest_node(node.right	)
  							UpperCAmelCase__:  Optional[Any]		       =   node.left
  							UpperCAmelCase__:  Tuple		       =   node.right
  							UpperCAmelCase__:  Dict		       =   lowest_node
  							if node.right:
  								UpperCAmelCase__:  str		       =   lowest_node
  							self._reassign_nodes(a_							,			a_	)
  						elif not node.right and node.left:
  							self._reassign_nodes(a_							,			node.left	)
  						elif node.right and not node.left:
  							self._reassign_nodes(a_							,			node.right	)
  						else:
  							self._reassign_nodes(a_							,			a_	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__	):
  						if new_children:
  							UpperCAmelCase__:  List[Any]		       =   node.parent
  
  						if node.parent:
  							if node.parent.right == node:
  								UpperCAmelCase__:  int		       =   new_children
  							else:
  								UpperCAmelCase__:  Optional[int]		       =   new_children
  						else:
  							UpperCAmelCase__:  Union[str, Any]		       =   new_children
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						if node.left:
  							UpperCAmelCase__:  List[str]		       =   self._get_lowest_node(node.left	)
  						else:
  							UpperCAmelCase__:  Any		       =   node
  							self._reassign_nodes(a_							,			node.right	)
  
  						return lowest_node
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						try:
  							self.search(a_	)
  							return True
  						except Exception:
  							return False
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						if self.root is None:
  							raise Exception("Binary search tree is empty"	)
  
  						UpperCAmelCase__:  Union[str, Any]		       =   self.root
  						while node.right is not None:
  							UpperCAmelCase__:  List[str]		       =   node.right
  
  						return node.label
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						if self.root is None:
  							raise Exception("Binary search tree is empty"	)
  
  						UpperCAmelCase__:  List[str]		       =   self.root
  						while node.left is not None:
  							UpperCAmelCase__:  str		       =   node.left
  
  						return node.label
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return self._inorder_traversal(self.root	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						if node is not None:
  							yield from self._inorder_traversal(node.left	)
  							yield node
  							yield from self._inorder_traversal(node.right	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return self._preorder_traversal(self.root	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__	):
  						if node is not None:
  							yield node
  							yield from self._preorder_traversal(node.left	)
  							yield from self._preorder_traversal(node.right	)
  
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					@staticmethod
  					def       _UpperCAmelCase						(							):
  						UpperCAmelCase__:  Tuple		       =   BinarySearchTree()
  						t.put(8	)
  						t.put(3	)
  						t.put(6	)
  						t.put(1	)
  						t.put(1_0	)
  						t.put(1_4	)
  						t.put(1_3	)
  						t.put(4	)
  						t.put(7	)
  						t.put(5	)
  
  						return t
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Tuple		       =   BinarySearchTree()
  						assert t.is_empty()
  
  						t.put(8	)
  						assert t.root is not None
  						assert t.root.parent is None
  						assert t.root.label == 8
  
  						t.put(1_0	)
  						assert t.root.right is not None
  						assert t.root.right.parent == t.root
  						assert t.root.right.label == 1_0
  
  						t.put(3	)
  						assert t.root.left is not None
  						assert t.root.left.parent == t.root
  						assert t.root.left.label == 3
  
  						t.put(6	)
  						assert t.root.left.right is not None
  						assert t.root.left.right.parent == t.root.left
  						assert t.root.left.right.label == 6
  
  						t.put(1	)
  						assert t.root.left.left is not None
  						assert t.root.left.left.parent == t.root.left
  						assert t.root.left.left.label == 1
  
  						with self.assertRaises(a_	):  # noqa: B017
  							t.put(1	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self._get_binary_search_tree()
  
  						UpperCAmelCase__:  Tuple		       =   t.search(6	)
  						assert node.label == 6
  
  						UpperCAmelCase__:  Tuple		       =   t.search(1_3	)
  						assert node.label == 1_3
  
  						with self.assertRaises(a_	):  # noqa: B017
  							t.search(2	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Any		       =   self._get_binary_search_tree()
  
  						t.remove(1_3	)
  						assert t.root is not None
  						assert t.root.right is not None
  						assert t.root.right.right is not None
  						assert t.root.right.right.right is None
  						assert t.root.right.right.left is None
  
  						t.remove(7	)
  						assert t.root.left is not None
  						assert t.root.left.right is not None
  						assert t.root.left.right.left is not None
  						assert t.root.left.right.right is None
  						assert t.root.left.right.left.label == 4
  
  						t.remove(6	)
  						assert t.root.left.left is not None
  						assert t.root.left.right.right is not None
  						assert t.root.left.left.label == 1
  						assert t.root.left.right.label == 4
  						assert t.root.left.right.right.label == 5
  						assert t.root.left.right.left is None
  						assert t.root.left.left.parent == t.root.left
  						assert t.root.left.right.parent == t.root.left
  
  						t.remove(3	)
  						assert t.root is not None
  						assert t.root.left.label == 4
  						assert t.root.left.right.label == 5
  						assert t.root.left.left.label == 1
  						assert t.root.left.parent == t.root
  						assert t.root.left.left.parent == t.root.left
  						assert t.root.left.right.parent == t.root.left
  
  						t.remove(4	)
  						assert t.root.left is not None
  						assert t.root.left.left is not None
  						assert t.root.left.label == 5
  						assert t.root.left.right is None
  						assert t.root.left.left.label == 1
  						assert t.root.left.parent == t.root
  						assert t.root.left.left.parent == t.root.left
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   self._get_binary_search_tree()
  
  						t.remove(3	)
  						assert t.root is not None
  						assert t.root.left is not None
  						assert t.root.left.left is not None
  						assert t.root.left.right is not None
  						assert t.root.left.right.left is not None
  						assert t.root.left.right.right is not None
  						assert t.root.left.label == 4
  						assert t.root.left.right.label == 6
  						assert t.root.left.left.label == 1
  						assert t.root.left.right.right.label == 7
  						assert t.root.left.right.left.label == 5
  						assert t.root.left.parent == t.root
  						assert t.root.left.right.parent == t.root.left
  						assert t.root.left.left.parent == t.root.left
  						assert t.root.left.right.left.parent == t.root.left.right
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   self._get_binary_search_tree()
  						t.empty()
  						assert t.root is None
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Union[str, Any]		       =   self._get_binary_search_tree()
  						assert not t.is_empty()
  
  						t.empty()
  						assert t.is_empty()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Union[str, Any]		       =   self._get_binary_search_tree()
  
  						assert t.exists(6	)
  						assert not t.exists(-1	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[Any]		       =   self._get_binary_search_tree()
  
  						assert t.get_max_label() == 1_4
  
  						t.empty()
  						with self.assertRaises(a_	):  # noqa: B017
  							t.get_max_label()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self._get_binary_search_tree()
  
  						assert t.get_min_label() == 1
  
  						t.empty()
  						with self.assertRaises(a_	):  # noqa: B017
  							t.get_min_label()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   self._get_binary_search_tree()
  
  						UpperCAmelCase__:  Tuple		       =   [i.label for i in t.inorder_traversal()]
  						assert inorder_traversal_nodes == [1, 3, 4, 5, 6, 7, 8, 1_0, 1_3, 1_4]
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self._get_binary_search_tree()
  
  						UpperCAmelCase__:  List[str]		       =   [i.label for i in t.preorder_traversal()]
  						assert preorder_traversal_nodes == [8, 3, 1, 6, 4, 5, 7, 1_0, 1_4, 1_3]
  
  
  
  def  _A  (			):
  	UpperCAmelCase__:  Any		       =   BinarySearchTree()
  	t.put(8			)
  	t.put(3			)
  	t.put(6			)
  	t.put(1			)
  	t.put(1_0			)
  	t.put(1_4			)
  	t.put(1_3			)
  	t.put(4			)
  	t.put(7			)
  	t.put(5			)
  
  	print(
  	    "\n            8\n           / \\\n          3   10\n         / \\    \\\n        1   6    14\n           / \\   /\n          4   7 13\n           \\\n            5\n        "			)
  
  	print("Label 6 exists:"  ,t.exists(6			)			)
  	print("Label 13 exists:"  ,t.exists(1_3			)			)
  	print("Label -1 exists:"  ,t.exists(-1			)			)
  	print("Label 12 exists:"  ,t.exists(1_2			)			)
  
  	# Prints all the elements of the list in inorder traversal
  	UpperCAmelCase__:  Dict		       =   [i.label for i in t.inorder_traversal()]
  	print("Inorder traversal:"  ,UpperCamelCase__			)
  
  	# Prints all the elements of the list in preorder traversal
  	UpperCAmelCase__:  List[Any]		       =   [i.label for i in t.preorder_traversal()]
  	print("Preorder traversal:"  ,UpperCamelCase__			)
  
  	print("Max. label:"  ,t.get_max_label()			)
  	print("Min. label:"  ,t.get_min_label()			)
  
  	# Delete elements
  	print("\nDeleting elements 13, 10, 8, 3, 6, 14"			)
  	print(
  	    "\n          4\n         / \\\n        1   7\n             \\\n              5\n        "			)
  	t.remove(1_3			)
  	t.remove(1_0			)
  	t.remove(8			)
  	t.remove(3			)
  	t.remove(6			)
  	t.remove(1_4			)
  
  	# Prints all the elements of the list in inorder traversal after delete
  	UpperCAmelCase__:  Dict		       =   [i.label for i in t.inorder_traversal()]
  	print("Inorder traversal after delete:"  ,UpperCamelCase__			)
  
  	# Prints all the elements of the list in preorder traversal after delete
  	UpperCAmelCase__:  Dict		       =   [i.label for i in t.preorder_traversal()]
  	print("Preorder traversal after delete:"  ,UpperCamelCase__			)
  
  	print("Max. label:"  ,t.get_max_label()			)
  	print("Min. label:"  ,t.get_min_label()			)
  
  
  if __name__ == "__main__":
  					binary_search_tree_example()
style_context: 
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,):
  	UpperCAmelCase__:  Tuple		       =   list(SCREAMING_SNAKE_CASE			)
  	UpperCAmelCase__:  int		       =   list(SCREAMING_SNAKE_CASE			)
  	UpperCAmelCase__:  Dict		       =   len(SCREAMING_SNAKE_CASE			)
  	UpperCAmelCase__:  int		       =   len(SCREAMING_SNAKE_CASE			)
  
  	UpperCAmelCase__:  Any		       =   [
  	    [0 for _ in range(len_destination_seq + 1			)] for _ in range(len_source_seq + 1			)
  	]
  	UpperCAmelCase__:  List[Any]		       =   [
  	    ["0" for _ in range(len_destination_seq + 1			)] for _ in range(len_source_seq + 1			)
  	]
  
  	for i in range(1  ,len_source_seq + 1			):
  		UpperCAmelCase__:  List[Any]		       =   i * delete_cost
  		UpperCAmelCase__:  str		       =   f"D{source_seq[i - 1]:c}"
  
  	for i in range(1  ,len_destination_seq + 1			):
  		UpperCAmelCase__:  Union[str, Any]		       =   i * insert_cost
  		UpperCAmelCase__:  Optional[Any]		       =   f"I{destination_seq[i - 1]:c}"
  
  	for i in range(1  ,len_source_seq + 1			):
  		for j in range(1  ,len_destination_seq + 1			):
  			if source_seq[i - 1] == destination_seq[j - 1]:
  				UpperCAmelCase__:  Any		       =   costs[i - 1][j - 1] + copy_cost
  				UpperCAmelCase__:  Tuple		       =   f"C{source_seq[i - 1]:c}"
  			else:
  				UpperCAmelCase__:  Union[str, Any]		       =   costs[i - 1][j - 1] + replace_cost
  				UpperCAmelCase__:  Optional[int]		       =   f"R{source_seq[i - 1]:c}" + str(destination_seq[j - 1]			)
  
  			if costs[i - 1][j] + delete_cost < costs[i][j]:
  				UpperCAmelCase__:  Optional[int]		       =   costs[i - 1][j] + delete_cost
  				UpperCAmelCase__:  int		       =   f"D{source_seq[i - 1]:c}"
  
  			if costs[i][j - 1] + insert_cost < costs[i][j]:
  				UpperCAmelCase__:  Any		       =   costs[i][j - 1] + insert_cost
  				UpperCAmelCase__:  Tuple		       =   f"I{destination_seq[j - 1]:c}"
  
  	return costs, ops
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	if i == 0 and j == 0:
  		return []
  	else:
  		if ops[i][j][0] == "C" or ops[i][j][0] == "R":
  			UpperCAmelCase__:  Union[str, Any]		       =   assemble_transformation(SCREAMING_SNAKE_CASE  ,i - 1  ,j - 1			)
  			seq.append(ops[i][j]			)
  			return seq
  		elif ops[i][j][0] == "D":
  			UpperCAmelCase__:  Optional[Any]		       =   assemble_transformation(SCREAMING_SNAKE_CASE  ,i - 1  ,SCREAMING_SNAKE_CASE			)
  			seq.append(ops[i][j]			)
  			return seq
  		else:
  			UpperCAmelCase__:  Dict		       =   assemble_transformation(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,j - 1			)
  			seq.append(ops[i][j]			)
  			return seq
  
  
  if __name__ == "__main__":
  					_lowerCAmelCase   ,  _lowerCAmelCase     :			Dict    =compute_transform_tables("""Python""", """Algorithms""", -1, 1, 2, 2)
  
  					_lowerCAmelCase     :			List[Any]    =len(operations)
  					_lowerCAmelCase     :			Optional[int]    =len(operations[0])
  					_lowerCAmelCase     :			Dict    =assemble_transformation(operations, m - 1, n - 1)
  
  					_lowerCAmelCase     :			int    =list("""Python""")
  					_lowerCAmelCase     :			Optional[int]    =0
  					_lowerCAmelCase     :			List[Any]    =0
  
  					with open("""min_cost.txt""", """w""") as file:
  										for op in sequence:
  															print("""""".join(string))
  
  															if op[0] == "C":
  																				file.write("""%-16s""" % """Copy %c""" % op[1])
  																				file.write("""\t\t\t""" + """""".join(string))
  																				file.write("""\r\n""")
  
  																				cost -= 1
  															elif op[0] == "R":
  																				_lowerCAmelCase     :			Tuple    =op[2]
  
  																				file.write("""%-16s""" % ("""Replace %c""" % op[1] + """ with """ + str(op[2])))
  																				file.write("""\t\t""" + """""".join(string))
  																				file.write("""\r\n""")
  
  																				cost += 1
  															elif op[0] == "D":
  																				string.pop(i)
  
  																				file.write("""%-16s""" % """Delete %c""" % op[1])
  																				file.write("""\t\t\t""" + """""".join(string))
  																				file.write("""\r\n""")
  
  																				cost += 2
  															else:
  																				string.insert(i, op[1])
  
  																				file.write("""%-16s""" % """Insert %c""" % op[1])
  																				file.write("""\t\t\t""" + """""".join(string))
  																				file.write("""\r\n""")
  
  																				cost += 2
  
  															i += 1
  
  										print("""""".join(string))
  										print("""Cost: """, cost)
  
  										file.write("""\r\nMinimum cost: """ + str(cost))