


'''simple docstring'''



from __future__ import annotations

from collections import namedtuple
from dataclasses import dataclass



@dataclass
class 			a       :


     """simple docstring"""






     SCREAMING_SNAKE_CASE :				int
     SCREAMING_SNAKE_CASE :				TreeNode | None							     =     None
     SCREAMING_SNAKE_CASE :				TreeNode | None							     =     None



__UpperCAmelCase    :Optional[int]				       =     namedtuple("CoinsDistribResult", "moves excess")




def 			_a			(		_lowercase      :			TreeNode | None						)     ->   Optional[int]:





     '''simple docstring'''






     if root is None:
          return 0

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

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

     def count_coins(_lowercase      :			TreeNode | None						) -> int:
          if node is None:
               return 0

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

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

     # Main calculation
     def get_distrib(_lowercase      :			TreeNode | None						) -> CoinsDistribResult:

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

          __UpperCAmelCase			:				Any													=    get_distrib(node.left						)
          __UpperCAmelCase			:				Any													=    get_distrib(node.right						)

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

          __UpperCAmelCase			:				Tuple													=    (
              left_distrib_moves
              + right_distrib_moves
              + abs(_lowercase						)
              + abs(_lowercase						)
          )
          __UpperCAmelCase			:				Optional[Any]													=    node.data - coins_to_left - coins_to_right

          return CoinsDistribResult(_lowercase    ,      _lowercase						)

     return get_distrib(_lowercase						)[0]


if __name__ == "__main__":
      import doctest

      doctest.testmod()



'''simple docstring'''



def 			_a			(		_lowercase      :			List[str]						):





     '''simple docstring'''






     __UpperCAmelCase			:				int													=    len(_lowercase						)
     while cur > 1:
          # Find the maximum number in arr
          __UpperCAmelCase			:				Union[str, Any]													=    arr.index(max(arr[0:cur]						)						)
          # Reverse from 0 to mi
          __UpperCAmelCase			:				Any													=    arr[mi::-1] + arr[mi + 1 : len(_lowercase						)]
          # Reverse whole list
          __UpperCAmelCase			:				List[str]													=    arr[cur - 1 :: -1] + arr[cur : len(_lowercase						)]
          cur -= 1
     return arr


if __name__ == "__main__":
      __UpperCAmelCase    :Any				       =     input("Enter numbers separated by a comma:\n").strip()
      __UpperCAmelCase    :Optional[int]				       =     [int(item) for item in user_input.split(",")]
      print(pancake_sort(unsorted))