"""simple docstring"""







from __future__ import annotations

from collections import defaultdict
from dataclasses import dataclass






@dataclass
class 			_lowercase		:
				lowerCamelCase__						=       4_2
				lowerCamelCase__						=       None
				lowerCamelCase__						=       None


def   a__      (		)->	Optional[int]:
						return TreeNode(3		,			TreeNode(9			)		,			TreeNode(2_0		,			TreeNode(1_5			)		,			TreeNode(7			)			)			)


def   a__      (		UpperCAmelCase__       :			Any			)->	int:


						def depth_first_search(
						    UpperCAmelCase__       :			List[Any]		,			UpperCAmelCase__       :			List[str]		,			UpperCAmelCase__       :			Dict			) -> 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__						=		[]
						if not root:
												return right_view

						depth_first_search(_A		,			0		,			_A			)
						return right_view


def   a__      (		UpperCAmelCase__       :			int			)->	Tuple:


						def depth_first_search(
						    UpperCAmelCase__       :			Union[str, Any]		,			UpperCAmelCase__       :			Union[str, Any]		,			UpperCAmelCase__       :			Optional[Any]			) -> 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__						=		[]
						if not root:
												return left_view

						depth_first_search(_A		,			0		,			_A			)
						return left_view


def   a__      (		UpperCAmelCase__       :			List[str]			)->	Optional[int]:


						def breadth_first_search(UpperCAmelCase__       :			int		,			UpperCAmelCase__       :			Optional[int]			) -> None:
												UpperCAmelCase__						=		[(root, 0)]
												UpperCAmelCase__						=		defaultdict(_A			)

												while queue:
																		UpperCAmelCase__						=		queue.pop(0			)
																		UpperCAmelCase__	,      UpperCAmelCase__						=		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 UpperCAmelCase__			: each[0]			):
																		top_view.append(pair[1][0]			)

						UpperCAmelCase__						=		[]
						if not root:
												return top_view

						breadth_first_search(_A		,			_A			)
						return top_view


def   a__      (		UpperCAmelCase__       :			List[str]			)->	List[str]:
						from collections import defaultdict

						def breadth_first_search(UpperCAmelCase__       :			Tuple		,			UpperCAmelCase__       :			List[str]			) -> None:
												UpperCAmelCase__						=		[(root, 0)]
												UpperCAmelCase__						=		defaultdict(_A			)

												while queue:
																		UpperCAmelCase__						=		queue.pop(0			)
																		UpperCAmelCase__	,      UpperCAmelCase__						=		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 UpperCAmelCase__			: each[0]			):
																		bottom_view.append(pair[1][-1]			)

						UpperCAmelCase__						=		[]
						if not root:
												return bottom_view

						breadth_first_search(_A		,			_A			)
						return bottom_view


if __name__ == "__main__":
						import doctest

						doctest.testmod()


"""simple docstring"""







import math
from timeit import timeit


def   a__      (		UpperCAmelCase__       :			int			)->	int:
						UpperCAmelCase__						=		0
						UpperCAmelCase__						=		abs(UpperCAmelCase__			)
						while True:
												UpperCAmelCase__						=		n // 1_0
												digits += 1
												if n == 0:
																		break
						return digits


def   a__      (		UpperCAmelCase__       :			int			)->	int:
						return 1 if n == 0 else math.floor(math.log(abs(UpperCAmelCase__			)		,			1_0			) + 1			)


def   a__      (		UpperCAmelCase__       :			int			)->	int:
						return len(str(abs(UpperCAmelCase__			)			)			)


def   a__      (		)->	None:
						from collections.abc import Callable

						def benchmark_a_function(UpperCAmelCase__       :			Callable		,			UpperCAmelCase__       :			int			) -> None:
												UpperCAmelCase__						=		f'{func.__name__}({value})'
												UpperCAmelCase__						=		timeit(f'__main__.{call}'		,			setup="""import __main__"""			)
												print(f'{call}: {func(UpperCAmelCase__			)} -- {timing} seconds'			)

						for value in (2_6_2_1_4_4, 1_1_2_5_8_9_9_9_0_6_8_4_2_6_2_4, 1_2_6_7_6_5_0_6_0_0_2_2_8_2_2_9_4_0_1_4_9_6_7_0_3_2_0_5_3_7_6):
												for func in (num_digits, num_digits_fast, num_digits_faster):
																		benchmark_a_function(UpperCAmelCase__		,			UpperCAmelCase__			)
												print()


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						benchmark()

