




'''simple docstring'''

from __future__ import annotations

import math
import random
from typing import Any






class 						a				:


				def __init__(		self    :					Union[str, Any]					):
									snake_case_									=				[]
									snake_case_									=				0
									snake_case_									=				0


				def   A_ (		self    :					Tuple					):
									return self.head == self.tail


				def   A_ (		self    :					int       ,				lowercase_    :					Any					):
									self.data.append(lowercase_					)
									snake_case_									=				self.tail + 1


				def   A_ (		self    :					List[str]					):
									snake_case_									=				self.data[self.head]
									snake_case_									=				self.head + 1
									return ret


				def   A_ (		self    :					Tuple					):
									return self.tail - self.head


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







class 						a				:


				def __init__(		self    :					Optional[int]       ,				lowercase_    :					Any					):
									snake_case_									=				data
									snake_case_									=				None
									snake_case_									=				None
									snake_case_									=				1


				def   A_ (		self    :					List[str]					):
									return self.data


				def   A_ (		self    :					str					):
									return self.left


				def   A_ (		self    :					Any					):
									return self.right


				def   A_ (		self    :					Tuple					):
									return self.height


				def   A_ (		self    :					Any       ,				lowercase_    :					Any					):
									snake_case_									=				data


				def   A_ (		self    :					str       ,				lowercase_    :					MyNode | None					):
									snake_case_									=				node


				def   A_ (		self    :					Dict       ,				lowercase_    :					MyNode | None					):
									snake_case_									=				node


				def   A_ (		self    :					Any       ,				lowercase_    :					int					):
									snake_case_									=				height







def 		__magic_name__    (	__UpperCAmelCase	)		->					int:

					'''simple docstring'''

					if node is None:
										return 0
					return node.get_height()


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase	)		->					int:

					'''simple docstring'''

					if a > b:
										return a
					return b


def 		__magic_name__    (	__UpperCAmelCase	)		->					MyNode:

					'''simple docstring'''

					print('''left rotation node:''',      node.get_data()	)
					snake_case_									=				node.get_left()
					assert ret is not None
					node.set_left(ret.get_right()	)
					ret.set_right(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(node.get_right()	),      get_height(node.get_left()	)	) + 1
					node.set_height(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(ret.get_right()	),      get_height(ret.get_left()	)	) + 1
					ret.set_height(__UpperCAmelCase	)
					return ret


def 		__magic_name__    (	__UpperCAmelCase	)		->					MyNode:

					'''simple docstring'''

					print('''right rotation node:''',      node.get_data()	)
					snake_case_									=				node.get_right()
					assert ret is not None
					node.set_right(ret.get_left()	)
					ret.set_left(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(node.get_right()	),      get_height(node.get_left()	)	) + 1
					node.set_height(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(ret.get_right()	),      get_height(ret.get_left()	)	) + 1
					ret.set_height(__UpperCAmelCase	)
					return ret


def 		__magic_name__    (	__UpperCAmelCase	)		->					MyNode:

					'''simple docstring'''

					snake_case_									=				node.get_left()
					assert left_child is not None
					node.set_left(left_rotation(__UpperCAmelCase	)	)
					return right_rotation(__UpperCAmelCase	)


def 		__magic_name__    (	__UpperCAmelCase	)		->					MyNode:

					'''simple docstring'''

					snake_case_									=				node.get_right()
					assert right_child is not None
					node.set_right(right_rotation(__UpperCAmelCase	)	)
					return left_rotation(__UpperCAmelCase	)


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase	)		->					MyNode | None:

					'''simple docstring'''

					if node is None:
										return MyNode(__UpperCAmelCase	)
					if data < node.get_data():
										node.set_left(insert_node(node.get_left(),      __UpperCAmelCase	)	)
										if (
										    get_height(node.get_left()	) - get_height(node.get_right()	) == 2
										):  # an unbalance detected
															snake_case_									=				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
																				snake_case_									=				right_rotation(__UpperCAmelCase	)
															else:
																				snake_case_									=				lr_rotation(__UpperCAmelCase	)
					else:
										node.set_right(insert_node(node.get_right(),      __UpperCAmelCase	)	)
										if get_height(node.get_right()	) - get_height(node.get_left()	) == 2:
															snake_case_									=				node.get_right()
															assert right_child is not None
															if data < right_child.get_data():
																				snake_case_									=				rl_rotation(__UpperCAmelCase	)
															else:
																				snake_case_									=				left_rotation(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(node.get_right()	),      get_height(node.get_left()	)	) + 1
					node.set_height(__UpperCAmelCase	)
					return node


def 		__magic_name__    (	__UpperCAmelCase	)		->					Any:

					'''simple docstring'''

					while True:
										snake_case_									=				root.get_right()
										if right_child is None:
															break
										snake_case_									=				right_child
					return root.get_data()


def 		__magic_name__    (	__UpperCAmelCase	)		->					Any:

					'''simple docstring'''

					while True:
										snake_case_									=				root.get_left()
										if left_child is None:
															break
										snake_case_									=				left_child
					return root.get_data()


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase	)		->					MyNode | None:

					'''simple docstring'''

					snake_case_									=				root.get_left()
					snake_case_									=				root.get_right()
					if root.get_data() == data:
										if left_child is not None and right_child is not None:
															snake_case_									=				get_left_most(__UpperCAmelCase	)
															root.set_data(__UpperCAmelCase	)
															root.set_right(del_node(__UpperCAmelCase,      __UpperCAmelCase	)	)
										elif left_child is not None:
															snake_case_									=				left_child
										elif right_child is not None:
															snake_case_									=				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(__UpperCAmelCase,      __UpperCAmelCase	)	)
					else:  # root.get_data() < data
										if right_child is None:
															return root
										else:
															root.set_right(del_node(__UpperCAmelCase,      __UpperCAmelCase	)	)

					if get_height(__UpperCAmelCase	) - get_height(__UpperCAmelCase	) == 2:
										assert right_child is not None
										if get_height(right_child.get_right()	) > get_height(right_child.get_left()	):
															snake_case_									=				left_rotation(__UpperCAmelCase	)
										else:
															snake_case_									=				rl_rotation(__UpperCAmelCase	)
					elif get_height(__UpperCAmelCase	) - get_height(__UpperCAmelCase	) == -2:
										assert left_child is not None
										if get_height(left_child.get_left()	) > get_height(left_child.get_right()	):
															snake_case_									=				right_rotation(__UpperCAmelCase	)
										else:
															snake_case_									=				lr_rotation(__UpperCAmelCase	)
					snake_case_									=				my_max(get_height(root.get_right()	),      get_height(root.get_left()	)	) + 1
					root.set_height(__UpperCAmelCase	)
					return root






class 						a				:


				def __init__(		self    :					Union[str, Any]					):
									snake_case_									=				None


				def   A_ (		self    :					Any					):
									return get_height(self.root					)


				def   A_ (		self    :					Any       ,				lowercase_    :					Any					):
									print('''insert:''' + str(lowercase_					)					)
									snake_case_									=				insert_node(self.root       ,				lowercase_					)


				def   A_ (		self    :					Dict       ,				lowercase_    :					Any					):
									print('''delete:''' + str(lowercase_					)					)
									if self.root is None:
														print('''Tree is empty!'''					)
														return
									snake_case_									=				del_node(self.root       ,				lowercase_					)


				def __str__(		self    :					List[Any]       ,				):  # a level traversale, gives a more intuitive look on the tree
									snake_case_									=				''''''
									snake_case_									=				MyQueue()
									q.push(self.root					)
									snake_case_									=				self.get_height()
									if layer == 0:
														return output
									snake_case_									=				0
									while not q.is_empty():
														snake_case_									=				q.pop()
														snake_case_									=				''' ''' * int(math.pow(2       ,				layer - 1					)					)
														output += space
														if node is None:
																			output += "*"
																			q.push(lowercase_					)
																			q.push(lowercase_					)
														else:
																			output += str(node.get_data()					)
																			q.push(node.get_left()					)
																			q.push(node.get_right()					)
														output += space
														snake_case_									=				cnt + 1
														for i in range(100					):
																			if cnt == math.pow(2       ,				lowercase_					) - 1:
																								snake_case_									=				layer - 1
																								if layer == 0:
																													output += "\n*************************************"
																													return output
																								output += "\n"
																								break
									output += "\n*************************************"
									return output







def 		__magic_name__    (	)		->					None:

					'''simple docstring'''

					import doctest

					doctest.testmod()


if __name__ == "__main__":
							_test()
							a  :				List[Any]									=  AVLtree()
							a  :				List[str]									=  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))






from __future__ import annotations

from math import ceil, floor, sqrt




def 	__UpperCamelCase	(  _lowerCAmelCase = 200_0000		)       ->  int:



    """simple docstring"""






    A :       list[int]          =   [0]
    A :       int

    for idx in range(1      ,     ceil(sqrt(target * 2		) * 1.1		)		):
        triangle_numbers.append(triangle_numbers[-1] + idx		)

    # we want this to be as close as possible to target
    A :       int          =   0
    # the area corresponding to the grid that gives the product closest to target
    A :       int          =   0
    # an estimate of b, using the quadratic formula
    A :       float
    # the largest integer less than b_estimate
    A :       int
    # the largest integer less than b_estimate
    A :       int
    # the triangle number corresponding to b_floor
    A :       int
    # the triangle number corresponding to b_ceil
    A :       int

    for idx_a, triangle_a in enumerate(triangle_numbers[1:]      ,     1		):
        A :       Union[str, Any]          =   (-1 + sqrt(1 + 8 * target / triangle_a		)) / 2
        A :       List[Any]          =   floor(_lowerCAmelCase		)
        A :       Tuple          =   ceil(_lowerCAmelCase		)
        A :       int          =   triangle_numbers[b_floor]
        A :       Dict          =   triangle_numbers[b_ceil]

        if abs(target - triangle_b_first_guess * triangle_a		) < abs(
            target - best_product		):
            A :       Optional[int]          =   triangle_b_first_guess * triangle_a
            A :       Optional[int]          =   idx_a * b_floor

        if abs(target - triangle_b_second_guess * triangle_a		) < abs(
            target - best_product		):
            A :       Tuple          =   triangle_b_second_guess * triangle_a
            A :       Tuple          =   idx_a * b_ceil

    return area


if __name__ == "__main__":
     print(F"""{solution() = }""")


