
from __future__ import annotations

import unittest
from collections.abc import Iterator







class 							lowercase						:




							def __init__(							self  ,A__  ,A__):
												lowercase		      =		label
												lowercase		      =		parent
												lowercase		      =		None
												lowercase		      =		None







class 							lowercase						:




							def __init__(							self):
												lowercase		      =		None




							def 					A__ (							self):
												lowercase		      =		None




							def 					A__ (							self):
												return self.root is None




							def 					A__ (							self  ,A__):
												lowercase		      =		self._put(self.root  ,A__)




							def 					A__ (							self  ,A__  ,A__  ,A__ = None):





												if node is None:
																	lowercase		      =		Node(A__  ,A__)
												else:
																	if label < node.label:
																						lowercase		      =		self._put(node.left  ,A__  ,A__)
																	elif label > node.label:
																						lowercase		      =		self._put(node.right  ,A__  ,A__)
																	else:
																						lowercase		      =		f'Node with label {label} already exists'
																						raise Exception(A__)

												return node




							def 					A__ (							self  ,A__):
												return self._search(self.root  ,A__)




							def 					A__ (							self  ,A__  ,A__):





												if node is None:
																	lowercase		      =		f'Node with label {label} does not exist'
																	raise Exception(A__)
												else:
																	if label < node.label:
																						lowercase		      =		self._search(node.left  ,A__)
																	elif label > node.label:
																						lowercase		      =		self._search(node.right  ,A__)

												return node




							def 					A__ (							self  ,A__):
												lowercase		      =		self.search(A__)
												if node.right and node.left:
																	lowercase		      =		self._get_lowest_node(node.right)
																	lowercase		      =		node.left
																	lowercase		      =		node.right
																	lowercase		      =		lowest_node
																	if node.right:
																						lowercase		      =		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 					A__ (							self  ,A__  ,A__):





												if new_children:
																	lowercase		      =		node.parent

												if node.parent:
																	if node.parent.right == node:
																						lowercase		      =		new_children
																	else:
																						lowercase		      =		new_children
												else:
																	lowercase		      =		new_children




							def 					A__ (							self  ,A__):





												if node.left:
																	lowercase		      =		self._get_lowest_node(node.left)
												else:
																	lowercase		      =		node
																	self._reassign_nodes(A__  ,node.right)

												return lowest_node




							def 					A__ (							self  ,A__):





												try:
																	self.search(A__)
																	return True
												except Exception:
																	return False




							def 					A__ (							self):





												if self.root is None:
																	raise Exception('''Binary search tree is empty''')

												lowercase		      =		self.root
												while node.right is not None:
																	lowercase		      =		node.right

												return node.label




							def 					A__ (							self):





												if self.root is None:
																	raise Exception('''Binary search tree is empty''')

												lowercase		      =		self.root
												while node.left is not None:
																	lowercase		      =		node.left

												return node.label




							def 					A__ (							self):
												return self._inorder_traversal(self.root)




							def 					A__ (							self  ,A__):





												if node is not None:
																	yield from self._inorder_traversal(node.left)
																	yield node
																	yield from self._inorder_traversal(node.right)




							def 					A__ (							self):
												return self._preorder_traversal(self.root)





							def 					A__ (							self  ,A__):





												if node is not None:
																	yield node
																	yield from self._preorder_traversal(node.left)
																	yield from self._preorder_traversal(node.right)







class 							lowercase						(   unittest.TestCase						):




							@staticmethod
							def 					A__ (							):
												lowercase		      =		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 					A__ (							self):
												lowercase		      =		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 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()

												lowercase		      =		t.search(6)
												assert node.label == 6

												lowercase		      =		t.search(1_3)
												assert node.label == 1_3

												with self.assertRaises(A__):  # noqa: B017
																	t.search(2)




							def 					A__ (							self):
												lowercase		      =		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 					A__ (							self):
												lowercase		      =		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 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()
												t.empty()
												assert t.root is None




							def 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()
												assert not t.is_empty()

												t.empty()
												assert t.is_empty()




							def 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()

												assert t.exists(6)
												assert not t.exists(-1)




							def 					A__ (							self):
												lowercase		      =		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 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()

												assert t.get_min_label() == 1

												t.empty()
												with self.assertRaises(A__):  # noqa: B017
																	t.get_min_label()




							def 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()

												lowercase		      =		[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 					A__ (							self):
												lowercase		      =		self._get_binary_search_tree()

												lowercase		      =		[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 			UpperCamelCase       (				):
					'''simple docstring'''
					lowercase		      =		BinarySearchTree()
					t.put(8						)
					t.put(3						)
					t.put(6						)
					t.put(1						)
					t.put(10						)
					t.put(14						)
					t.put(13						)
					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(13						)						)
					print('''Label -1 exists:'''					,     t.exists(-1						)						)
					print('''Label 12 exists:'''					,     t.exists(12						)						)

					# Prints all the elements of the list in inorder traversal
					lowercase		      =		[i.label for i in t.inorder_traversal()]
					print('''Inorder traversal:'''					,     __snake_case						)

					# Prints all the elements of the list in preorder traversal
					lowercase		      =		[i.label for i in t.preorder_traversal()]
					print('''Preorder traversal:'''					,     __snake_case						)

					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(13						)
					t.remove(10						)
					t.remove(8						)
					t.remove(3						)
					t.remove(6						)
					t.remove(14						)

					# Prints all the elements of the list in inorder traversal after delete
					lowercase		      =		[i.label for i in t.inorder_traversal()]
					print('''Inorder traversal after delete:'''					,     __snake_case						)

					# Prints all the elements of the list in preorder traversal after delete
					lowercase		      =		[i.label for i in t.preorder_traversal()]
					print('''Preorder traversal after delete:'''					,     __snake_case						)

					print('''Max. label:'''					,     t.get_max_label()						)
					print('''Min. label:'''					,     t.get_min_label()						)


if __name__ == "__main__":
							binary_search_tree_example()









def  _snake_case			(							__snake_case       ,	__snake_case       ,	__snake_case     )  ->  list[int]:






      '''simple docstring'''







      if hue < 0 or hue > 3_6_0:
            raise Exception("hue should be between 0 and 360"     )

      if saturation < 0 or saturation > 1:
            raise Exception("saturation should be between 0 and 1"     )

      if value < 0 or value > 1:
            raise Exception("value should be between 0 and 1"     )

      UpperCAmelCase_	:						Tuple					   =		value * saturation
      UpperCAmelCase_	:						Union[str, Any]					   =		hue / 6_0
      UpperCAmelCase_	:						Tuple					   =		chroma * (1 - abs(hue_section % 2 - 1     ))
      UpperCAmelCase_	:						Tuple					   =		value - chroma

      if hue_section >= 0 and hue_section <= 1:
            UpperCAmelCase_	:						List[str]					   =		round(2_5_5 * (chroma + match_value)     )
            UpperCAmelCase_	:						str					   =		round(2_5_5 * (second_largest_component + match_value)     )
            UpperCAmelCase_	:						int					   =		round(2_5_5 * (match_value)     )
      elif hue_section > 1 and hue_section <= 2:
            UpperCAmelCase_	:						Union[str, Any]					   =		round(2_5_5 * (second_largest_component + match_value)     )
            UpperCAmelCase_	:						Union[str, Any]					   =		round(2_5_5 * (chroma + match_value)     )
            UpperCAmelCase_	:						int					   =		round(2_5_5 * (match_value)     )
      elif hue_section > 2 and hue_section <= 3:
            UpperCAmelCase_	:						List[str]					   =		round(2_5_5 * (match_value)     )
            UpperCAmelCase_	:						Any					   =		round(2_5_5 * (chroma + match_value)     )
            UpperCAmelCase_	:						Optional[int]					   =		round(2_5_5 * (second_largest_component + match_value)     )
      elif hue_section > 3 and hue_section <= 4:
            UpperCAmelCase_	:						str					   =		round(2_5_5 * (match_value)     )
            UpperCAmelCase_	:						Dict					   =		round(2_5_5 * (second_largest_component + match_value)     )
            UpperCAmelCase_	:						Optional[Any]					   =		round(2_5_5 * (chroma + match_value)     )
      elif hue_section > 4 and hue_section <= 5:
            UpperCAmelCase_	:						str					   =		round(2_5_5 * (second_largest_component + match_value)     )
            UpperCAmelCase_	:						Any					   =		round(2_5_5 * (match_value)     )
            UpperCAmelCase_	:						str					   =		round(2_5_5 * (chroma + match_value)     )
      else:
            UpperCAmelCase_	:						Optional[int]					   =		round(2_5_5 * (chroma + match_value)     )
            UpperCAmelCase_	:						Dict					   =		round(2_5_5 * (match_value)     )
            UpperCAmelCase_	:						Optional[int]					   =		round(2_5_5 * (second_largest_component + match_value)     )

      return [red, green, blue]







def  _snake_case			(							__snake_case       ,	__snake_case       ,	__snake_case     )  ->  list[float]:






      '''simple docstring'''







      if red < 0 or red > 2_5_5:
            raise Exception("red should be between 0 and 255"     )

      if green < 0 or green > 2_5_5:
            raise Exception("green should be between 0 and 255"     )

      if blue < 0 or blue > 2_5_5:
            raise Exception("blue should be between 0 and 255"     )

      UpperCAmelCase_	:						str					   =		red / 2_5_5
      UpperCAmelCase_	:						Dict					   =		green / 2_5_5
      UpperCAmelCase_	:						int					   =		blue / 2_5_5
      UpperCAmelCase_	:						Any					   =		max(__snake_case       ,	__snake_case       ,	__snake_case     )
      UpperCAmelCase_	:						Union[str, Any]					   =		value - min(__snake_case       ,	__snake_case       ,	__snake_case     )
      UpperCAmelCase_	:						Optional[Any]					   =		0 if value == 0 else chroma / value

      if chroma == 0:
            UpperCAmelCase_	:						Tuple					   =		0.0
      elif value == float_red:
            UpperCAmelCase_	:						List[str]					   =		6_0 * (0 + (float_green - float_blue) / chroma)
      elif value == float_green:
            UpperCAmelCase_	:						Union[str, Any]					   =		6_0 * (2 + (float_blue - float_red) / chroma)
      else:
            UpperCAmelCase_	:						Dict					   =		6_0 * (4 + (float_red - float_green) / chroma)

      UpperCAmelCase_	:						int					   =		(hue + 3_6_0) % 3_6_0

      return [hue, saturation, value]







def  _snake_case			(							__snake_case       ,	__snake_case     )  ->  bool:






      '''simple docstring'''







      UpperCAmelCase_	:						List[str]					   =		abs(hsv_a[0] - hsv_a[0]     ) < 0.2
      UpperCAmelCase_	:						Optional[Any]					   =		abs(hsv_a[1] - hsv_a[1]     ) < 0.002
      UpperCAmelCase_	:						Tuple					   =		abs(hsv_a[2] - hsv_a[2]     ) < 0.002

      return check_hue and check_saturation and check_value
