





from __future__ import annotations

from collections import namedtuple
from dataclasses import dataclass





@dataclass
class  lowerCAmelCase							:
  __lowerCamelCase		=      42
  __lowerCamelCase		=      None
  __lowerCamelCase		=      None
_snake_case           =			namedtuple("""CoinsDistribResult""", """moves excess""")


def _A       (   __magic_name__	):




   if root is None:
      return 0

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

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

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

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

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

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

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

      lowercase__       ,							lowercase__			       =  get_distrib(node.left	)
      lowercase__       ,							lowercase__			       =  get_distrib(node.right	)

      lowercase__			       =  1 - left_distrib_excess
      lowercase__			       =  1 - right_distrib_excess

      lowercase__			       =  (
          left_distrib_moves
          + right_distrib_moves
          + abs(__magic_name__	)
          + abs(__magic_name__	)
      )
      lowercase__			       =  node.data - coins_to_left - coins_to_right

      return CoinsDistribResult(__magic_name__  , __magic_name__	)

   return get_distrib(__magic_name__	)[0]


if __name__ == "__main__":
    import doctest

    doctest.testmod()













from __future__ import annotations


def _A       (   __magic_name__  , __magic_name__	):
   lowercase__			       =  []
   create_all_state(1  , __magic_name__  , __magic_name__  , []  , __magic_name__	)
   return result


def _A       (   __magic_name__  , __magic_name__  , __magic_name__  , __magic_name__  , __magic_name__  , ):
   if level == 0:
      total_list.append(current_list[:]	)
      return

   for i in range(__magic_name__  , total_number - level + 2	):
      current_list.append(__magic_name__	)
      create_all_state(i + 1  , __magic_name__  , level - 1  , __magic_name__  , __magic_name__	)
      current_list.pop()


def _A       (   __magic_name__	):
   for i in total_list:
      print(*__magic_name__	)


if __name__ == "__main__":
  _snake_case           =			4
  _snake_case           =			2
  _snake_case           =			generate_all_combinations(n, k)
  print_all_state(total_list)






