





"""simple docstring"""
from __future__ import annotations

import queue






class  _SCREAMING_SNAKE_CASE:




       def __init__(						self		,SCREAMING_SNAKE_CASE__							)      ->				Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :str		    =  data
             __SCREAMING_SNAKE_CASE       :Tuple		    =  None
             __SCREAMING_SNAKE_CASE       :str		    =  None




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



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      print(node.data			,       end=''','''							)
      pre_order(node.left							)
      pre_order(node.right							)



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      in_order(node.left							)
      print(node.data			,       end=''','''							)
      in_order(node.right							)



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      post_order(node.left							)
      post_order(node.right							)
      print(node.data			,       end=''','''							)



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      __SCREAMING_SNAKE_CASE       :queue.Queue		    =  queue.Queue()
      q.put(a_							)
      while not q.empty():
            __SCREAMING_SNAKE_CASE       :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       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      __SCREAMING_SNAKE_CASE       :queue.Queue		    =  queue.Queue()
      q.put(a_							)
      while not q.empty():
            __SCREAMING_SNAKE_CASE       :List[Any]		    =  []
            while not q.empty():
                  __SCREAMING_SNAKE_CASE       :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(a_							)



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



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      __SCREAMING_SNAKE_CASE       :list[TreeNode]		    =  []
      __SCREAMING_SNAKE_CASE       :Dict		    =  node
      while n or stack:
            while n:
                  stack.append(a_							)
                  __SCREAMING_SNAKE_CASE       :int		    =  n.left
            __SCREAMING_SNAKE_CASE       :Tuple		    =  stack.pop()
            print(n.data			,       end=''','''							)
            __SCREAMING_SNAKE_CASE       :str		    =  n.right



def 					__lowerCamelCase       (							a_					:		TreeNode							)      ->				None:
      if not isinstance(a_			,       a_							) or not node:
            return
      __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Optional[Any]		    =  [], []
      __SCREAMING_SNAKE_CASE       :int		    =  node
      stacka.append(a_							)
      while stacka:  # to find the reversed order of post order, store it in stack2
            __SCREAMING_SNAKE_CASE       :List[Any]		    =  stacka.pop()
            if n.left:
                  stacka.append(n.left							)
            if n.right:
                  stacka.append(n.right							)
            stacka.append(a_							)
      while stacka:  # pop up from stack2 will be the post order
            print(stacka.pop().data			,       end=''','''							)



def 					__lowerCamelCase       (							a_					:		str = ""			,       a_					:		List[str]=50			,       a_					:		List[Any]="*"							)      ->				str:
      if not s:
            return "\n" + width * char
      __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Optional[Any]		    =  divmod(width - len(a_							) - 2			,       2							)
      return f'''{left * char} {s} {(left + extra) * char}'''


if __name__ == "__main__":
  import doctest

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

  lowerCamelCase_       =		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("*" * 5_0 + "\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"""
def 					__lowerCamelCase       (							a_					:		int			,       a_					:		int							)      ->				int:
      return int((input_a, input_a).count(0							) == 0							)



def 					__lowerCamelCase       (							)      ->				None:
      assert and_gate(0			,       0							) == 0
      assert and_gate(0			,       1							) == 0
      assert and_gate(1			,       0							) == 0
      assert and_gate(1			,       1							) == 1


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