



"""simple docstring"""






import operator






def 	snake_case_  (				A_ :		list,    A_ :		bool = False,    A_ :		list | None = None						):


       '''simple docstring'''





       _lowerCamelCase						:    Any         =			operator.lt if reverse else operator.gt
       _lowerCamelCase						:    Optional[int]         =			solution or []

       if not arr:
              return solution

       _lowerCamelCase						:    Union[str, Any]         =			[arr.pop(0						)]
       for i, item in enumerate(lowerCAmelCase__						):
              if _operator(lowerCAmelCase__,    sublist[-1]						):
                     sublist.append(lowerCAmelCase__						)
                     arr.pop(lowerCAmelCase__						)

    #  merging sublist into solution list
       if not solution:
              solution.extend(lowerCAmelCase__						)
       else:
              while sublist:
                     _lowerCamelCase						:    Optional[int]         =			sublist.pop(0						)
                     for i, xx in enumerate(lowerCAmelCase__						):
                            if not _operator(lowerCAmelCase__,    lowerCAmelCase__						):
                                   solution.insert(lowerCAmelCase__,    lowerCAmelCase__						)
                                   break
                     else:
                            solution.append(lowerCAmelCase__						)

       strand_sort(lowerCAmelCase__,    lowerCAmelCase__,    lowerCAmelCase__						)
       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]







"""simple docstring"""






from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat






def 	snake_case_  (				):


       '''simple docstring'''





       _lowerCamelCase						:    Optional[Any]         =			[randint(-10_00,    10_00						) for i in range(10						)]
       _lowerCamelCase						:    Tuple         =			randint(-50_00,    50_00						)
       return (arr, r)


lowerCAmelCase__      =    make_dataset()






def 	snake_case_  (				A_ :		list[int],    A_ :		int						):


       '''simple docstring'''





       for triplet in permutations(A_,    3						):
              if sum(A_						) == target:
                     return tuple(sorted(A_						)						)
       return (0, 0, 0)






def 	snake_case_  (				A_ :		list[int],    A_ :		int						):


       '''simple docstring'''





       arr.sort()
       _lowerCamelCase						:    Optional[Any]         =			len(A_						)
       for i in range(n - 1						):
              _lowerCamelCase      ,   _lowerCamelCase						:    int         =			i + 1, n - 1
              while left < right:
                     if arr[i] + arr[left] + arr[right] == target:
                            return (arr[i], arr[left], arr[right])
                     elif arr[i] + arr[left] + arr[right] < target:
                            left += 1
                     elif arr[i] + arr[left] + arr[right] > target:
                            right -= 1
       return (0, 0, 0)






def 	snake_case_  (				):


       '''simple docstring'''





       _lowerCamelCase						:    Tuple         =			'''
from __main__ import dataset, triplet_sum1, triplet_sum2
'''
       _lowerCamelCase						:    List[Any]         =			'''
triplet_sum1(*dataset)
'''
       _lowerCamelCase						:    str         =			'''
triplet_sum2(*dataset)
'''
       _lowerCamelCase						:    Optional[int]         =			repeat(setup=A_,    stmt=A_,    repeat=5,    number=1_00_00						)
       _lowerCamelCase						:    Union[str, Any]         =			repeat(setup=A_,    stmt=A_,    repeat=5,    number=1_00_00						)
       return (min(A_						), min(A_						))


if __name__ == "__main__":
   from doctest import testmod

   testmod()
   lowerCAmelCase__      =    solution_times()
   print(F"""The time for naive implementation is {times[0]}.""")
   print(F"""The time for optimized implementation is {times[1]}.""")


