

'''simple docstring'''





class 		__SCREAMING_SNAKE_CASE							:







				def __init__(       self     :		Dict   ):
										'''simple docstring'''
										lowercase :							Dict    		=''''''
										lowercase :							Tuple    		=''''''
										lowercase :							List[str]    		=[]







				def  lowerCamelCase_	(       self     :		Tuple		,					UpperCAmelCase__     :		int		,					UpperCAmelCase__     :		int   ):
										'''simple docstring'''
										if m == -1:
																return n + 1
										elif n == -1:
																return m + 1
										elif self.dp[m][n] > -1:
																return self.dp[m][n]
										else:
																if self.worda[m] == self.worda[n]:
																						lowercase :							List[Any]    		=self.__min_dist_top_down_dp(m - 1		,					n - 1   )
																else:
																						lowercase :							Optional[int]    		=self.__min_dist_top_down_dp(UpperCAmelCase__		,					n - 1   )
																						lowercase :							Any    		=self.__min_dist_top_down_dp(m - 1		,					UpperCAmelCase__   )
																						lowercase :							List[str]    		=self.__min_dist_top_down_dp(m - 1		,					n - 1   )
																						lowercase :							Optional[Any]    		=1 + min(UpperCAmelCase__		,					UpperCAmelCase__		,					UpperCAmelCase__   )

																return self.dp[m][n]







				def  lowerCamelCase_	(       self     :		str		,					UpperCAmelCase__     :		str		,					UpperCAmelCase__     :		str   ):
										'''simple docstring'''
										lowercase :							List[str]    		=worda
										lowercase :							List[Any]    		=worda
										lowercase :							List[str]    		=[[-1 for _ in range(len(UpperCAmelCase__   )   )] for _ in range(len(UpperCAmelCase__   )   )]

										return self.__min_dist_top_down_dp(len(UpperCAmelCase__   ) - 1		,					len(UpperCAmelCase__   ) - 1   )







				def  lowerCamelCase_	(       self     :		Optional[Any]		,					UpperCAmelCase__     :		str		,					UpperCAmelCase__     :		str   ):
										'''simple docstring'''
										lowercase :							List[Any]    		=worda
										lowercase :							Any    		=worda
										lowercase :							str    		=len(UpperCAmelCase__   )
										lowercase :							List[Any]    		=len(UpperCAmelCase__   )
										lowercase :							int    		=[[0 for _ in range(n + 1   )] for _ in range(m + 1   )]

										for i in range(m + 1   ):
																for j in range(n + 1   ):
																						if i == 0:  # first string is empty
																												lowercase :							Any    		=j
																						elif j == 0:  # second string is empty
																												lowercase :							Tuple    		=i
																						elif worda[i - 1] == worda[j - 1]:  # last characters are equal
																												lowercase :							Dict    		=self.dp[i - 1][j - 1]
																						else:
																												lowercase :							List[str]    		=self.dp[i][j - 1]
																												lowercase :							Any    		=self.dp[i - 1][j]
																												lowercase :							int    		=self.dp[i - 1][j - 1]
																												lowercase :							List[Any]    		=1 + min(UpperCAmelCase__		,					UpperCAmelCase__		,					UpperCAmelCase__   )
										return self.dp[m][n]


if __name__ == "__main__":
							UpperCamelCase_    						=       EditDistance()

							print("""****************** Testing Edit Distance DP Algorithm ******************""")
							print()

							UpperCamelCase_    						=       input("""Enter the first string: """).strip()
							UpperCamelCase_    						=       input("""Enter the second string: """).strip()

							print()
							print(f'''The minimum edit distance is: {solver.min_dist_top_down(Sa, Sa)}''')
							print(f'''The minimum edit distance is: {solver.min_dist_bottom_up(Sa, Sa)}''')
							print()
							print("""*************** End of Testing Edit Distance DP Algorithm ***************""")








'''simple docstring'''



import operator


def       snake_case   (	snake_case      : list					,		snake_case      : bool = False					,		snake_case      : list | None = None			) ->  list:


    """simple docstring"""


    lowerCAmelCase 						=							operator.lt if reverse else operator.gt
    lowerCAmelCase 						=							solution or []

    if not arr:
        return solution

    lowerCAmelCase 						=							[arr.pop(0			)]
    for i, item in enumerate(snake_case			):
        if _operator(snake_case					,		sublist[-1]			):
            sublist.append(snake_case			)
            arr.pop(snake_case			)

    #  merging sublist into solution list
    if not solution:
        solution.extend(snake_case			)
    else:
        while sublist:
            lowerCAmelCase 						=							sublist.pop(0			)
            for i, xx in enumerate(snake_case			):
                if not _operator(snake_case					,		snake_case			):
                    solution.insert(snake_case					,		snake_case			)
                    break
            else:
                solution.append(snake_case			)

    strand_sort(snake_case					,		snake_case					,		snake_case			)
    return solution


if __name__ == "__main__":
     assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
     assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]





