






from __future__ import annotations

import math
import random
from typing import Any






class 			_UpperCamelCase:

		def __init__(					self		:    Any    ):



					'''simple docstring'''



					__a						:  List[Any]									=     []
					__a						:  Dict									=     0
					__a						:  List[str]									=     0

		def    __lowerCAmelCase  (					self		:    List[str]    ):



					'''simple docstring'''



					return self.head == self.tail

		def    __lowerCAmelCase  (					self		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					self.data.append(__lowerCamelCase    )
					__a						:  List[str]									=     self.tail + 1

		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					__a						:  Any									=     self.data[self.head]
					__a						:  Optional[int]									=     self.head + 1
					return ret

		def    __lowerCAmelCase  (					self		:    int    ):



					'''simple docstring'''



					return self.tail - self.head



		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					print(self.data    )
					print('**************'    )
					print(self.data[self.head : self.tail]    )






class 			_UpperCamelCase:

		def __init__(					self		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					__a						:  Tuple									=     data
					__a						:  Any									=     None
					__a						:  int									=     None
					__a						:  Optional[int]									=     1

		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					return self.data

		def    __lowerCAmelCase  (					self		:    Dict    ):



					'''simple docstring'''



					return self.left

		def    __lowerCAmelCase  (					self		:    Union[str, Any]    ):



					'''simple docstring'''



					return self.right

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					return self.height

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					__a						:  Dict									=     data

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    MyNode | None    ):



					'''simple docstring'''



					__a						:  Optional[int]									=     node

		def    __lowerCAmelCase  (					self		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    MyNode | None    ):



					'''simple docstring'''



					__a						:  Dict									=     node



		def    __lowerCAmelCase  (					self		:    int    ,       SCREAMING_SNAKE_CASE__		:    int    ):



					'''simple docstring'''



					__a						:  Tuple									=     height




def        UpperCAmelCase__		(						lowerCamelCase_       :       int				):
			if node is None:
						return 0
			return node.get_height()

def        UpperCAmelCase__		(						lowerCamelCase_       :       Optional[Any]   ,  lowerCamelCase_       :       Dict				):
			if a > b:
						return a
			return b

def        UpperCAmelCase__		(						lowerCamelCase_       :       Optional[Any]				):
			print('left rotation node:'   ,  node.get_data()				)
			__a						:  int									=     node.get_left()
			assert ret is not None
			node.set_left(ret.get_right()				)
			ret.set_right(lowerCAmelCase_				)
			__a						:  List[Any]									=     my_max(get_height(node.get_right()				)   ,  get_height(node.get_left()				)				) + 1
			node.set_height(lowerCAmelCase_				)
			__a						:  Optional[Any]									=     my_max(get_height(ret.get_right()				)   ,  get_height(ret.get_left()				)				) + 1
			ret.set_height(lowerCAmelCase_				)
			return ret

def        UpperCAmelCase__		(						lowerCamelCase_       :       int				):
			print('right rotation node:'   ,  node.get_data()				)
			__a						:  Any									=     node.get_right()
			assert ret is not None
			node.set_right(ret.get_left()				)
			ret.set_left(lowerCAmelCase_				)
			__a						:  int									=     my_max(get_height(node.get_right()				)   ,  get_height(node.get_left()				)				) + 1
			node.set_height(lowerCAmelCase_				)
			__a						:  Union[str, Any]									=     my_max(get_height(ret.get_right()				)   ,  get_height(ret.get_left()				)				) + 1
			ret.set_height(lowerCAmelCase_				)
			return ret

def        UpperCAmelCase__		(						lowerCamelCase_       :       List[Any]				):
			__a						:  int									=     node.get_left()
			assert left_child is not None
			node.set_left(left_rotation(lowerCAmelCase_				)				)
			return right_rotation(lowerCAmelCase_				)

def        UpperCAmelCase__		(						lowerCamelCase_       :       Dict				):
			__a						:  int									=     node.get_right()
			assert right_child is not None
			node.set_right(right_rotation(lowerCAmelCase_				)				)
			return left_rotation(lowerCAmelCase_				)

def        UpperCAmelCase__		(						lowerCamelCase_       :       Union[str, Any]   ,  lowerCamelCase_       :       List[Any]				):
			if node is None:
						return MyNode(lowerCAmelCase_				)
			if data < node.get_data():
						node.set_left(insert_node(node.get_left()   ,  lowerCAmelCase_				)				)
						if (
						    get_height(node.get_left()				) - get_height(node.get_right()				) == 2
						):  # an unbalance detected
									__a						:  str									=     node.get_left()
									assert left_child is not None
									if (
									    data < left_child.get_data()
									):  # new node is the left child of the left child
												__a						:  Tuple									=     right_rotation(lowerCAmelCase_				)
									else:
												__a						:  str									=     lr_rotation(lowerCAmelCase_				)
			else:
						node.set_right(insert_node(node.get_right()   ,  lowerCAmelCase_				)				)
						if get_height(node.get_right()				) - get_height(node.get_left()				) == 2:
									__a						:  Optional[Any]									=     node.get_right()
									assert right_child is not None
									if data < right_child.get_data():
												__a						:  int									=     rl_rotation(lowerCAmelCase_				)
									else:
												__a						:  int									=     left_rotation(lowerCAmelCase_				)
			__a						:  List[str]									=     my_max(get_height(node.get_right()				)   ,  get_height(node.get_left()				)				) + 1
			node.set_height(lowerCAmelCase_				)
			return node

def        UpperCAmelCase__		(						lowerCamelCase_       :       Dict				):
			while True:
						__a						:  Optional[int]									=     root.get_right()
						if right_child is None:
									break
						__a						:  List[Any]									=     right_child
			return root.get_data()

def        UpperCAmelCase__		(						lowerCamelCase_       :       Dict				):
			while True:
						__a						:  Optional[int]									=     root.get_left()
						if left_child is None:
									break
						__a						:  Optional[int]									=     left_child
			return root.get_data()

def        UpperCAmelCase__		(						lowerCamelCase_       :       int   ,  lowerCamelCase_       :       List[str]				):
			__a						:  Any									=     root.get_left()
			__a						:  int									=     root.get_right()
			if root.get_data() == data:
						if left_child is not None and right_child is not None:
									__a						:  Optional[int]									=     get_left_most(lowerCAmelCase_				)
									root.set_data(lowerCAmelCase_				)
									root.set_right(del_node(lowerCAmelCase_   ,  lowerCAmelCase_				)				)
						elif left_child is not None:
									__a						:  str									=     left_child
						elif right_child is not None:
									__a						:  Optional[Any]									=     right_child
						else:
									return None
			elif root.get_data() > data:
						if left_child is None:
									print('No such data'				)
									return root
						else:
									root.set_left(del_node(lowerCAmelCase_   ,  lowerCAmelCase_				)				)
			else:  # root.get_data() < data
						if right_child is None:
									return root
						else:
									root.set_right(del_node(lowerCAmelCase_   ,  lowerCAmelCase_				)				)

			if get_height(lowerCAmelCase_				) - get_height(lowerCAmelCase_				) == 2:
						assert right_child is not None
						if get_height(right_child.get_right()				) > get_height(right_child.get_left()				):
									__a						:  List[Any]									=     left_rotation(lowerCAmelCase_				)
						else:
									__a						:  Union[str, Any]									=     rl_rotation(lowerCAmelCase_				)
			elif get_height(lowerCAmelCase_				) - get_height(lowerCAmelCase_				) == -2:
						assert left_child is not None
						if get_height(left_child.get_left()				) > get_height(left_child.get_right()				):
									__a						:  Optional[int]									=     right_rotation(lowerCAmelCase_				)
						else:
									__a						:  List[Any]									=     lr_rotation(lowerCAmelCase_				)
			__a						:  Tuple									=     my_max(get_height(root.get_right()				)   ,  get_height(root.get_left()				)				) + 1
			root.set_height(lowerCAmelCase_				)
			return root






class 			_UpperCamelCase:

		def __init__(					self		:    int    ):



					'''simple docstring'''



					__a						:  List[Any]									=     None

		def    __lowerCAmelCase  (					self		:    str    ):



					'''simple docstring'''



					return get_height(self.root    )

		def    __lowerCAmelCase  (					self		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					print('insert:' + str(__lowerCamelCase    )    )
					__a						:  int									=     insert_node(self.root    ,       __lowerCamelCase    )

		def    __lowerCAmelCase  (					self		:    int    ,       SCREAMING_SNAKE_CASE__		:    Any    ):



					'''simple docstring'''



					print('delete:' + str(__lowerCamelCase    )    )
					if self.root is None:
								print('Tree is empty!'    )
								return
					__a						:  List[Any]									=     del_node(self.root    ,       __lowerCamelCase    )



		def __str__(					self		:    str    ,       ):  # a level traversale, gives a more intuitive look on the tree



					'''simple docstring'''



					__a						:  Any									=     ''
					__a						:  List[str]									=     MyQueue()
					q.push(self.root    )
					__a						:  Dict									=     self.get_height()
					if layer == 0:
								return output
					__a						:  List[str]									=     0
					while not q.is_empty():
								__a						:  Dict									=     q.pop()
								__a						:  Union[str, Any]									=     ' ' * int(math.pow(2    ,       layer - 1    )    )
								output += space
								if node is None:
											output += "*"
											q.push(__lowerCamelCase    )
											q.push(__lowerCamelCase    )
								else:
											output += str(node.get_data()    )
											q.push(node.get_left()    )
											q.push(node.get_right()    )
								output += space
								__a						:  List[Any]									=     cnt + 1
								for i in range(1_0_0    ):
											if cnt == math.pow(2    ,       __lowerCamelCase    ) - 1:
														__a						:  Optional[int]									=     layer - 1
														if layer == 0:
																	output += "\n*************************************"
																	return output
														output += "\n"
														break
					output += "\n*************************************"
					return output




def        UpperCAmelCase__		(						):
			import doctest

			doctest.testmod()


if __name__ == "__main__":
							_test()
							SCREAMING_SNAKE_CASE__				     =			AVLtree()
							SCREAMING_SNAKE_CASE__				     =			list(range(10))
							random.shuffle(lst)
							for i in lst:
														t.insert(i)
														print(str(t))
							random.shuffle(lst)
							for i in lst:
														t.del_node(i)
														print(str(t))










"""simple docstring"""






def 			snake_case		(		lowerCAmelCase_  ,						lowerCAmelCase_	)						->				int:
  return 1 if input_a == input_a else 0




def 			snake_case		(		)						->				None:
  assert xnor_gate(0  ,						0	) == 1
  assert xnor_gate(0  ,						1	) == 0
  assert xnor_gate(1  ,						0	) == 0
  assert xnor_gate(1  ,						1	) == 1


if __name__ == "__main__":
     print(xnor_gate(0, 0))
     print(xnor_gate(0, 1))
     print(xnor_gate(1, 0))
     print(xnor_gate(1, 1))





