

'''simple docstring'''






from __future__ import annotations

from scipy.special import comb  # type: ignore






class      lowercase_      :




  """simple docstring"""




  def __init__( self  :	Optional[int]   ,lowercase__  :	list[tuple[float, float]]     ):
   __lowercase				    =					list_of_points
   # Degree determines the flexibility of the curve.
   # Degree = 1 will produce a straight line.
   __lowercase				    =					len(lowercase__     ) - 1






  def    SCREAMING_SNAKE_CASE ( self  :	str   ,lowercase__  :	float     ):
   assert 0 <= t <= 1, "Time t must be between 0 and 1."
   __lowercase				    =					[]
   for i in range(len(self.list_of_points     )     ):
    # basis function for each i
    output_values.append(
        comb(self.degree   ,lowercase__     ) * ((1 - t) ** (self.degree - i)) * (t**i)     )
   # the basis must sum up to 1 for it to produce a valid Bezier curve.
   assert round(sum(lowercase__     )   ,5     ) == 1
   return output_values






  def    SCREAMING_SNAKE_CASE ( self  :	List[str]   ,lowercase__  :	float     ):
   assert 0 <= t <= 1, "Time t must be between 0 and 1."

   __lowercase				    =					self.basis_function(lowercase__     )
   __lowercase				    =					0.0
   __lowercase				    =					0.0
   for i in range(len(self.list_of_points     )     ):
    # For all points, sum up the product of i-th basis function and i-th point.
    x += basis_function[i] * self.list_of_points[i][0]
    y += basis_function[i] * self.list_of_points[i][1]
   return (x, y)






  def    SCREAMING_SNAKE_CASE ( self  :	Union[str, Any]   ,lowercase__  :	float = 0.0_1     ):
   from matplotlib import pyplot as plt  # type: ignore

   __lowercase				    =					[]  # x coordinates of points to plot
   __lowercase				    =					[]  # y coordinates of points to plot

   __lowercase				    =					0.0
   while t <= 1:
    __lowercase				    =					self.bezier_curve_function(lowercase__     )
    to_plot_x.append(value[0]     )
    to_plot_y.append(value[1]     )
    t += step_size

   __lowercase				    =					[i[0] for i in self.list_of_points]
   __lowercase				    =					[i[1] for i in self.list_of_points]

   plt.plot(
       lowercase__   ,lowercase__   ,color='''blue'''   ,label='''Curve of Degree ''' + str(self.degree     )   ,)
   plt.scatter(lowercase__   ,lowercase__   ,color='''red'''   ,label='''Control Points'''     )
   plt.legend()
   plt.show()


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 BezierCurve([(1, 2), (3, 5)]).plot_curve()  # degree 1
 BezierCurve([(0, 0), (5, 5), (5, 0)]).plot_curve()  # degree 2
 BezierCurve([(0, 0), (5, 5), (5, 0), (2.5, -2.5)]).plot_curve()  # degree 3







"""simple docstring"""




def        a__					(							snake_case__							)		->   list:

			if len(snake_case__							) <= 1:
						return [tuple(snake_case__							)]

			lowerCamelCase      =   []

			def generate(snake_case__			,					snake_case__							):
						lowerCamelCase      =   [0] * n
						res.append(tuple(snake_case__							)							)

						lowerCamelCase      =   0
						while i < n:
									if c[i] < i:
												if i % 2 == 0:
															lowerCamelCase ,  lowerCamelCase      =   arr[i], arr[0]
												else:
															lowerCamelCase ,  lowerCamelCase      =   arr[i], arr[c[i]]
												res.append(tuple(snake_case__							)							)
												c[i] += 1
												lowerCamelCase      =   0
									else:
												lowerCamelCase      =   0
												i += 1

			generate(len(snake_case__							)			,					snake_case__							)
			return res


if __name__ == "__main__":
					lowerCAmelCase				:     str					=				input("""Enter numbers separated by a comma:\n""").strip()
					lowerCAmelCase				:     List[Any]					=				[int(item) for item in user_input.split(""",""")]
					print(heaps(arr))



