'''simple docstring'''




from __future__ import annotations

import queue





class     __magic_name__						:







			def __init__(	self				:  List[str]				,			lowercase_				:  int    ):
										lowercase_					:			str										=       data
										lowercase_					:			Tuple										=       None
										lowercase_					:			Optional[Any]										=       None




def 							lowerCamelCase	(      )			->      TreeNode:
							print("""\n********Press N to stop entering at any point of time********\n""" )
							lowercase_					:			List[Any]										=       input("""Enter the value of the root node: """ ).strip().lower()
							lowercase_					:			queue.Queue										=       queue.Queue()
							lowercase_					:			Union[str, Any]										=       TreeNode(int(UpperCAmelCase__ ) )
							q.put(UpperCAmelCase__ )
							while not q.empty():
														lowercase_					:			Dict										=       q.get()
														lowercase_					:			Dict										=       F'''Enter the left node of {node_found.data}: '''
														lowercase_					:			List[Any]										=       input(UpperCAmelCase__ ).strip().lower() or """n"""
														if check == "n":
																					return tree_node
														lowercase_					:			Optional[Any]										=       TreeNode(int(UpperCAmelCase__ ) )
														lowercase_					:			Any										=       left_node
														q.put(UpperCAmelCase__ )
														lowercase_					:			Tuple										=       F'''Enter the right node of {node_found.data}: '''
														lowercase_					:			Dict										=       input(UpperCAmelCase__ ).strip().lower() or """n"""
														if check == "n":
																					return tree_node
														lowercase_					:			int										=       TreeNode(int(UpperCAmelCase__ ) )
														lowercase_					:			List[Any]										=       right_node
														q.put(UpperCAmelCase__ )
							raise




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							print(node.data      ,      end=""",""" )
							pre_order(node.left )
							pre_order(node.right )




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							in_order(node.left )
							print(node.data      ,      end=""",""" )
							in_order(node.right )




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							post_order(node.left )
							post_order(node.right )
							print(node.data      ,      end=""",""" )




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							lowercase_					:			queue.Queue										=       queue.Queue()
							q.put(UpperCAmelCase__ )
							while not q.empty():
														lowercase_					:			List[Any]										=       q.get()
														print(node_dequeued.data      ,      end=""",""" )
														if node_dequeued.left:
																					q.put(node_dequeued.left )
														if node_dequeued.right:
																					q.put(node_dequeued.right )




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							lowercase_					:			queue.Queue										=       queue.Queue()
							q.put(UpperCAmelCase__ )
							while not q.empty():
														lowercase_					:			Dict										=       []
														while not q.empty():
																					lowercase_					:			int										=       q.get()
																					print(node_dequeued.data      ,      end=""",""" )
																					if node_dequeued.left:
																												list_.append(node_dequeued.left )
																					if node_dequeued.right:
																												list_.append(node_dequeued.right )
														print()
														for node in list_:
																					q.put(UpperCAmelCase__ )




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							lowercase_					:			list[TreeNode]										=       []
							lowercase_					:			Dict										=       node
							while n or stack:
														while n:  # start from root node, find its left child
																					print(n.data      ,      end=""",""" )
																					stack.append(UpperCAmelCase__ )
																					lowercase_					:			Optional[Any]										=       n.left
														# end of while means current node doesn't have left child
														lowercase_					:			Union[str, Any]										=       stack.pop()
														# start to traverse its right child
														lowercase_					:			str										=       n.right




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							lowercase_					:			list[TreeNode]										=       []
							lowercase_					:			Union[str, Any]										=       node
							while n or stack:
														while n:
																					stack.append(UpperCAmelCase__ )
																					lowercase_					:			Optional[int]										=       n.left
														lowercase_					:			Optional[int]										=       stack.pop()
														print(n.data      ,      end=""",""" )
														lowercase_					:			Dict										=       n.right




def 							lowerCamelCase	(      UpperCAmelCase__       :					TreeNode )			->      None:
							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ) or not node:
														return
							lowercase_						,						lowercase_					:			Optional[int]										=       [], []
							lowercase_					:			Dict										=       node
							stacka.append(UpperCAmelCase__ )
							while stacka:  # to find the reversed order of post order, store it in stack2
														lowercase_					:			str										=       stacka.pop()
														if n.left:
																					stacka.append(n.left )
														if n.right:
																					stacka.append(n.right )
														stacka.append(UpperCAmelCase__ )
							while stacka:  # pop up from stack2 will be the post order
														print(stacka.pop().data      ,      end=""",""" )




def 							lowerCamelCase	(      UpperCAmelCase__       :					str = ""      ,      UpperCAmelCase__       :					Tuple=50      ,      UpperCAmelCase__       :					Any="*" )			->      str:
							if not s:
														return "\n" + width * char
							lowercase_						,						lowercase_					:			Optional[int]										=       divmod(width - len(UpperCAmelCase__ ) - 2      ,      2 )
							return F'''{left * char} {s} {(left + extra) * char}'''


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						print(prompt("Binary Tree Traversals"))

						_lowercase						: TreeNode						=						build_tree()
						print(prompt("Pre Order Traversal"))
						pre_order(node)
						print(prompt() + "\n")

						print(prompt("In Order Traversal"))
						in_order(node)
						print(prompt() + "\n")

						print(prompt("Post Order Traversal"))
						post_order(node)
						print(prompt() + "\n")

						print(prompt("Level Order Traversal"))
						level_order(node)
						print(prompt() + "\n")

						print(prompt("Actual Level Order Traversal"))
						level_order_actual(node)
						print("*" * 50 + "\n")

						print(prompt("Pre Order Traversal - Iteration Version"))
						pre_order_iter(node)
						print(prompt() + "\n")

						print(prompt("In Order Traversal - Iteration Version"))
						in_order_iter(node)
						print(prompt() + "\n")

						print(prompt("Post Order Traversal - Iteration Version"))
						post_order_iter(node)
						print(prompt())






'''simple docstring'''




import math




def 							lowerCamelCase	(      UpperCAmelCase__       :					int )			->      int:

							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ):
														lowercase_					:			List[Any]										=       F'''Input value of [number={number}] must be an integer'''
														raise TypeError(UpperCAmelCase__ )

							if number < 1:
														lowercase_					:			Tuple										=       F'''Input value of [number={number}] must be > 0'''
														raise ValueError(UpperCAmelCase__ )
							elif number == 1:
														return 3
							elif number == 2:
														return 5
							else:
														lowercase_					:			Union[str, Any]										=       int(math.log(number // 3      ,      2 ) ) + 2

														lowercase_					:			Any										=       [3, 5]
														lowercase_					:			List[Any]										=       2
														lowercase_					:			Optional[Any]										=       3
														for block in range(1      ,      UpperCAmelCase__ ):
																					for _ in range(UpperCAmelCase__ ):
																												proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1] )
																												proth_index += 1
																					increment *= 2

							return proth_list[number - 1]


if __name__ == "__main__":
						import doctest

						doctest.testmod()

						for number in range(11):
												_lowercase						: Optional[Any]						=						0
												try:
																		_lowercase						: str						=						proth(number)
												except ValueError:
																		print(f"""ValueError: there is no {number}th Proth number""")
																		continue

												print(f"""The {number}th Proth number: {value}""")





