


from __future__ import annotations

from collections import defaultdict
from dataclasses import dataclass



@dataclass
class 							lowercase__:






      '''simple docstring'''







      snake_case__       =					42
      snake_case__       =					None
      snake_case__       =					None




def 	_lowerCamelCase  (		)			->			TreeNode:

   '''simple docstring'''






   return TreeNode(3							,  TreeNode(9      )							,  TreeNode(2_0							,  TreeNode(1_5      )							,  TreeNode(7      )      )      )
def 	_lowerCamelCase  (		A_  :	TreeNode      )			->			list[int]:

   '''simple docstring'''






   def depth_first_search(
       A_  :	TreeNode | None							,  A_  :	int							,  A_  :	list[int]      ) -> None:
      if not root:
         return

      if depth == len(A_      ):
         right_view.append(root.val      )

      depth_first_search(root.right							,  depth + 1							,  A_      )
      depth_first_search(root.left							,  depth + 1							,  A_      )

   UpperCamelCase__ :			list 						=[]
   if not root:
      return right_view

   depth_first_search(A_							,  0							,  A_      )
   return right_view
def 	_lowerCamelCase  (		A_  :	TreeNode      )			->			list[int]:

   '''simple docstring'''






   def depth_first_search(
       A_  :	TreeNode | None							,  A_  :	int							,  A_  :	list[int]      ) -> None:
      if not root:
         return

      if depth == len(A_      ):
         left_view.append(root.val      )

      depth_first_search(root.left							,  depth + 1							,  A_      )
      depth_first_search(root.right							,  depth + 1							,  A_      )

   UpperCamelCase__ :			list 						=[]
   if not root:
      return left_view

   depth_first_search(A_							,  0							,  A_      )
   return left_view
def 	_lowerCamelCase  (		A_  :	TreeNode      )			->			list[int]:

   '''simple docstring'''






   def breadth_first_search(A_  :	TreeNode							,  A_  :	list[int]      ) -> None:
      UpperCamelCase__ :			Optional[int] 						=[(root, 0)]
      UpperCamelCase__ :			int 						=defaultdict(A_      )

      while queue:
         UpperCamelCase__ :			Union[str, Any] 						=queue.pop(0      )
         UpperCamelCase__						,	UpperCamelCase__ :			Any 						=first

         lookup[hd].append(node.val      )

         if node.left:
            queue.append((node.left, hd - 1)      )
         if node.right:
            queue.append((node.right, hd + 1)      )

      for pair in sorted(lookup.items()							,  key=lambda A_      : each[0]      ):
         top_view.append(pair[1][0]      )

   UpperCamelCase__ :			list 						=[]
   if not root:
      return top_view

   breadth_first_search(A_							,  A_      )
   return top_view
def 	_lowerCamelCase  (		A_  :	TreeNode      )			->			list[int]:

   '''simple docstring'''






   from collections import defaultdict

   def breadth_first_search(A_  :	TreeNode							,  A_  :	list[int]      ) -> None:
      UpperCamelCase__ :			int 						=[(root, 0)]
      UpperCamelCase__ :			Any 						=defaultdict(A_      )

      while queue:
         UpperCamelCase__ :			Union[str, Any] 						=queue.pop(0      )
         UpperCamelCase__						,	UpperCamelCase__ :			Tuple 						=first
         lookup[hd].append(node.val      )

         if node.left:
            queue.append((node.left, hd - 1)      )
         if node.right:
            queue.append((node.right, hd + 1)      )

      for pair in sorted(lookup.items()							,  key=lambda A_      : each[0]      ):
         bottom_view.append(pair[1][-1]      )

   UpperCamelCase__ :			list 						=[]
   if not root:
      return bottom_view

   breadth_first_search(A_							,  A_      )
   return bottom_view


if __name__ == "__main__":
     import doctest

     doctest.testmod()





def 	_lowerCamelCase  (		A_  :	Union[str, Any]							,  A_  :	Optional[int]      )			->			Dict:

   '''simple docstring'''






   if len(str(A_      )      ) == 1 or len(str(A_      )      ) == 1:
      return a * b

   UpperCamelCase__ :			Any 						=max(len(str(A_      )      )							,  len(str(A_      )      )      )
   UpperCamelCase__ :			Optional[int] 						=ma // 2

   UpperCamelCase__						,	UpperCamelCase__ :			Dict 						=divmod(A_							,  1_0**ma      )
   UpperCamelCase__						,	UpperCamelCase__ :			Union[str, Any] 						=divmod(A_							,  1_0**ma      )

   UpperCamelCase__ :			List[Any] 						=karatsuba(A_							,  A_      )
   UpperCamelCase__ :			Dict 						=karatsuba((aa + aa)							,  (ba + ba)      )
   UpperCamelCase__ :			Optional[int] 						=karatsuba(A_							,  A_      )

   return (z * 1_0 ** (2 * ma)) + ((y - z - x) * 1_0 ** (ma)) + (x)
def 	_lowerCamelCase  (		)			->			Any:

   '''simple docstring'''






   print(karatsuba(1_5_4_6_3							,  2_3_4_8_9      )      )


if __name__ == "__main__":
     main()

