





from __future__ import annotations

from sys import maxsize
from typing import Generic, TypeVar

lowercase_						=	TypeVar("""T""")




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     int:
  return (position - 1) // 2




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     int:
  return (2 * position) + 1




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     int:
  return (2 * position) + 2
class        SCREAMING_SNAKE_CASE     (Generic[T]   ):


   def __init__(					self    :       Optional[Any] )->     None:





     """simple docstring"""







     lowercase__			    =						[]
     lowercase__			    =						{}
     lowercase__			    =						0


   def __len__(					self    :       List[Any] )->     int:





     """simple docstring"""







     return self.elements


   def __repr__(					self    :       str )->     str:





     """simple docstring"""







     return str(self.heap )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[Any] )->     bool:





     """simple docstring"""







     return self.elements == 0


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[Any]    ,  a    :       T    ,  a    :       int )->     None:





     """simple docstring"""







     self.heap.append((elem, weight) )
     lowercase__			    =						self.elements
     self.elements += 1
     self._bubble_up(a )


   def  SCREAMING_SNAKE_CASE_							(					self    :       Tuple )->     T:





     """simple docstring"""







     if self.elements > 1:
       self._swap_nodes(0    ,  self.elements - 1 )
     lowercase__    ,					lowercase__			    =						self.heap.pop()
     del self.position_map[elem]
     self.elements -= 1
     if self.elements > 0:
       lowercase__    ,					lowercase__			    =						self.heap[0]
       self._bubble_down(a )
     return elem


   def  SCREAMING_SNAKE_CASE_							(					self    :       Any    ,  a    :       T    ,  a    :       int )->     None:





     """simple docstring"""







     lowercase__			    =						self.position_map[elem]
     lowercase__			    =						(elem, weight)
     if position > 0:
       lowercase__			    =						get_parent_position(a )
       lowercase__    ,					lowercase__			    =						self.heap[parent_position]
       if parent_weight > weight:
         self._bubble_up(a )
       else:
         self._bubble_down(a )
     else:
       self._bubble_down(a )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[Any]    ,  a    :       T )->     None:





     """simple docstring"""







     lowercase__			    =						self.position_map[elem]
     if curr_pos == 0:
       return None
     lowercase__			    =						get_parent_position(a )
     lowercase__    ,					lowercase__			    =						self.heap[curr_pos]
     lowercase__    ,					lowercase__			    =						self.heap[parent_position]
     if parent_weight > weight:
       self._swap_nodes(a    ,  a )
       return self._bubble_up(a )
     return None


   def  SCREAMING_SNAKE_CASE_							(					self    :       str    ,  a    :       T )->     None:





     """simple docstring"""







     lowercase__			    =						self.position_map[elem]
     lowercase__    ,					lowercase__			    =						self.heap[curr_pos]
     lowercase__			    =						get_child_left_position(a )
     lowercase__			    =						get_child_right_position(a )
     if child_left_position < self.elements and child_right_position < self.elements:
       lowercase__    ,					lowercase__			    =						self.heap[child_left_position]
       lowercase__    ,					lowercase__			    =						self.heap[child_right_position]
       if child_right_weight < child_left_weight and child_right_weight < weight:
         self._swap_nodes(a    ,  a )
         return self._bubble_down(a )
     if child_left_position < self.elements:
       lowercase__    ,					lowercase__			    =						self.heap[child_left_position]
       if child_left_weight < weight:
         self._swap_nodes(a    ,  a )
         return self._bubble_down(a )
     else:
       return None
     if child_right_position < self.elements:
       lowercase__    ,					lowercase__			    =						self.heap[child_right_position]
       if child_right_weight < weight:
         self._swap_nodes(a    ,  a )
         return self._bubble_down(a )
     return None


   def  SCREAMING_SNAKE_CASE_							(					self    :       Union[str, Any]    ,  a    :       int    ,  a    :       int )->     None:





     """simple docstring"""







     lowercase__			    =						self.heap[nodea_pos][0]
     lowercase__			    =						self.heap[nodea_pos][0]
     lowercase__    ,					lowercase__			    =						(
         self.heap[nodea_pos],
         self.heap[nodea_pos],
     )
     lowercase__			    =						nodea_pos
     lowercase__			    =						nodea_pos






class        SCREAMING_SNAKE_CASE     (Generic[T]   ):


   def __init__(					self    :       Union[str, Any] )->     None:





     """simple docstring"""







     lowercase__			    =						{}
     lowercase__			    =						0


   def __repr__(					self    :       Dict )->     str:





     """simple docstring"""







     return str(self.connections )


   def __len__(					self    :       Tuple )->     int:





     """simple docstring"""







     return self.nodes


   def  SCREAMING_SNAKE_CASE_							(					self    :       Any    ,  a    :       T )->     None:





     """simple docstring"""







     if node not in self.connections:
       lowercase__			    =						{}
       self.nodes += 1


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[str]    ,  a    :       T    ,  a    :       T    ,  a    :       int )->     None:





     """simple docstring"""







     self.add_node(a )
     self.add_node(a )
     lowercase__			    =						weight
     lowercase__			    =						weight






def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		)       ->     tuple[dict[T, int], dict[T, T | None]]:
  lowercase__			    =						{node: maxsize for node in graph.connections}
  lowercase__			    =						{node: None for node in graph.connections}

  lowercase__			    =						MinPriorityQueue()
  for node, weight in dist.items():
    priority_queue.push(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)

  if priority_queue.is_empty():
    return dist, parent

  # initialization
  lowercase__			    =						priority_queue.extract_min()
  lowercase__			    =						0
  for neighbour in graph.connections[node]:
    if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
      lowercase__			    =						dist[node] + graph.connections[node][neighbour]
      priority_queue.update_key(_SCREAMING_SNAKE_CASE	,		dist[neighbour]	)
      lowercase__			    =						node

    # running prim's algorithm
  while not priority_queue.is_empty():
    lowercase__			    =						priority_queue.extract_min()
    for neighbour in graph.connections[node]:
      if dist[neighbour] > dist[node] + graph.connections[node][neighbour]:
        lowercase__			    =						dist[node] + graph.connections[node][neighbour]
        priority_queue.update_key(_SCREAMING_SNAKE_CASE	,		dist[neighbour]	)
        lowercase__			    =						node
  return dist, parent









def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     List[Any]:
  stooge(_SCREAMING_SNAKE_CASE	,		0	,		len(_SCREAMING_SNAKE_CASE	) - 1	)
  return arr




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     int:
  if i >= h:
    return

  # If first element is smaller than the last then swap them
  if arr[i] > arr[h]:
    lowercase__    ,					lowercase__			    =						arr[h], arr[i]

  # If there are more than 2 elements in the array
  if h - i + 1 > 2:
    lowercase__			    =						(int)((h - i + 1) / 3	)

    # Recursively sort first 2/3 elements
    stooge(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		(h - t)	)

    # Recursively sort last 2/3 elements
    stooge(_SCREAMING_SNAKE_CASE	,		i + t	,		(_SCREAMING_SNAKE_CASE)	)

    # Recursively sort first 2/3 elements
    stooge(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		(h - t)	)


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


