
"""simple docstring"""







from __future__ import annotations

from collections import namedtuple
from dataclasses import dataclass




@dataclass
class  A__       :
		A_						:       int
		A_						:       TreeNode | None				   =	None
		A_						:       TreeNode | None				   =	None



lowerCamelCase__   					=		namedtuple("""CoinsDistribResult""", """moves excess""")
def     __lowerCAmelCase				(_UpperCamelCase		):


	if root is None:
		return 0

	# Validation
	def count_nodes(_UpperCamelCase		) -> int:
		if node is None:
			return 0

		return count_nodes(node.left		) + count_nodes(node.right		) + 1

	def count_coins(_UpperCamelCase		) -> int:
		if node is None:
			return 0

		return count_coins(node.left		) + count_coins(node.right		) + node.data

	if count_nodes(lowerCAmelCase__		) != count_coins(lowerCAmelCase__		):
		raise ValueError('The nodes number should be same as the number of coins'		)

	# Main calculation
	def get_distrib(_UpperCamelCase		) -> CoinsDistribResult:

		if node is None:
			return CoinsDistribResult(0       ,  1		)

		__lowerCAmelCase			,   __lowerCAmelCase			:						Dict									=      get_distrib(node.left		)
		__lowerCAmelCase			,   __lowerCAmelCase			:						Dict									=      get_distrib(node.right		)

		__lowerCAmelCase			:						Optional[int]									=      1 - left_distrib_excess
		__lowerCAmelCase			:						List[Any]									=      1 - right_distrib_excess

		__lowerCAmelCase			:						str									=      (
		    left_distrib_moves
		    + right_distrib_moves
		    + abs(lowerCAmelCase__		)
		    + abs(lowerCAmelCase__		)
		)
		__lowerCAmelCase			:						List[str]									=      node.data - coins_to_left - coins_to_right

		return CoinsDistribResult(lowerCAmelCase__       ,  lowerCAmelCase__		)

	return get_distrib(lowerCAmelCase__		)[0]


if __name__ == "__main__":
							import doctest

							doctest.testmod()
"""simple docstring"""






from __future__ import annotations


def 			UpperCAmelCase__       (				lowerCAmelCase__     :list[int]		) ->    int:
      '''simple docstring'''


      if not nums:
            return 0
      lowercase														=	nums[0]
      lowercase														=	0
      for num in nums[1:]:
            lowercase							,							lowercase														=	(
                max_excluding + num,
                max(lowerCAmelCase__					,		lowerCAmelCase__		),
            )
      return max(lowerCAmelCase__					,		lowerCAmelCase__		)


if __name__ == "__main__":
       import doctest

       doctest.testmod()



