



'''simple docstring'''





from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
_lowerCAmelCase										=     Lock()
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    global process_lock

    # we perform n swaps since after n swaps we know we are sorted
    # we *could* stop early if we are sorted already, but it takes as long to
    # find out we are sorted as it does to sort the list with this algorithm
    for i in range(0							,   10      ):
        if (i + position) % 2 == 0 and r_send is not None:
            # send your value to your right neighbor
            process_lock.acquire()
            r_send[1].send(UpperCamelCase      )
            process_lock.release()

            # receive your right neighbor's value
            process_lock.acquire()
            lowerCAmelCase__			:  Any											= rr_cv[0].recv()
            process_lock.release()

            # take the lower value since you are on the left
            lowerCAmelCase__			:  str											= min(UpperCamelCase							,   UpperCamelCase      )
        elif (i + position) % 2 != 0 and l_send is not None:
            # send your value to your left neighbor
            process_lock.acquire()
            l_send[1].send(UpperCamelCase      )
            process_lock.release()

            # receive your left neighbor's value
            process_lock.acquire()
            lowerCAmelCase__			:  Tuple											= lr_cv[0].recv()
            process_lock.release()

            # take the higher value since you are on the right
            lowerCAmelCase__			:  List[str]											= max(UpperCamelCase							,   UpperCamelCase      )
    # after all swaps are performed, send the values back to main
    result_pipe[1].send(UpperCamelCase      )
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  Tuple											= []
    lowerCAmelCase__			:  Union[str, Any]											= []
    # initialize the list of pipes where the values will be retrieved
    for _ in arr:
        result_pipe.append(Pipe()      )
    # creates the processes
    # the first and last process only have one neighbor so they are made outside
    # of the loop
    lowerCAmelCase__			:  int											= Pipe()
    lowerCAmelCase__			:  Union[str, Any]											= Pipe()
    process_array_.append(
        Process(
            target=UpperCamelCase							,   args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])							,   )      )
    lowerCAmelCase__			:  Union[str, Any]											= temp_rs
    lowerCAmelCase__			:  Union[str, Any]											= temp_rr

    for i in range(1							,   len(UpperCamelCase      ) - 1      ):
        lowerCAmelCase__			:  str											= Pipe()
        lowerCAmelCase__			:  str											= Pipe()
        process_array_.append(
            Process(
                target=UpperCamelCase							,   args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])							,   )      )
        lowerCAmelCase__			:  str											= temp_rs
        lowerCAmelCase__			:  Tuple											= temp_rr

    process_array_.append(
        Process(
            target=UpperCamelCase							,   args=(
                len(UpperCamelCase      ) - 1,
                arr[len(UpperCamelCase      ) - 1],
                temp_ls,
                None,
                temp_lr,
                None,
                result_pipe[len(UpperCamelCase      ) - 1],
            )							,   )      )

    # start the processes
    for p in process_array_:
        p.start()

    # wait for the processes to end and write their values to the list
    for p in range(0							,   len(UpperCamelCase      )      ):
        lowerCAmelCase__			:  str											= result_pipe[p][0].recv()
        process_array_[p].join()
    return arr
def        _SCREAMING_SNAKE_CASE  (	):



    """simple docstring"""





    lowerCAmelCase__			:  int											= list(range(10							,   0							,   -1      )      )
    print("""Initial List"""      )
    print(*UpperCamelCase      )
    lowerCAmelCase__			:  List[Any]											= odd_even_transposition(UpperCamelCase      )
    print("""Sorted List\n"""      )
    print(*UpperCamelCase      )


if __name__ == "__main__":
 main()







'''simple docstring'''





from __future__ import annotations

# This is the precision for this function which can be altered.
# It is recommended for users to keep this number greater than or equal to 10.
_lowerCAmelCase										=     10
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    for i in range(UpperCamelCase							,   UpperCamelCase      ):
        if array[i] == target:
            return i
    return -1
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  Optional[Any]											= 0
    lowerCAmelCase__			:  Optional[int]											= len(UpperCamelCase      )
    while left <= right:
        if right - left < precision:
            return lin_search(UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      )

        lowerCAmelCase__			:  Tuple											= (left + right) // 3 + 1
        lowerCAmelCase__			:  List[str]											= 2 * (left + right) // 3 + 1

        if array[one_third] == target:
            return one_third
        elif array[two_third] == target:
            return two_third

        elif target < array[one_third]:
            lowerCAmelCase__			:  int											= one_third - 1
        elif array[two_third] < target:
            lowerCAmelCase__			:  Union[str, Any]											= two_third + 1

        else:
            lowerCAmelCase__			:  List[Any]											= one_third + 1
            lowerCAmelCase__			:  List[str]											= two_third - 1
    else:
        return -1
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      ):



    """simple docstring"""





    if left < right:
        if right - left < precision:
            return lin_search(UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      )
        lowerCAmelCase__			:  Dict											= (left + right) // 3 + 1
        lowerCAmelCase__			:  Tuple											= 2 * (left + right) // 3 + 1

        if array[one_third] == target:
            return one_third
        elif array[two_third] == target:
            return two_third

        elif target < array[one_third]:
            return rec_ternary_search(UpperCamelCase							,   one_third - 1							,   UpperCamelCase							,   UpperCamelCase      )
        elif array[two_third] < target:
            return rec_ternary_search(two_third + 1							,   UpperCamelCase							,   UpperCamelCase							,   UpperCamelCase      )
        else:
            return rec_ternary_search(one_third + 1							,   two_third - 1							,   UpperCamelCase							,   UpperCamelCase      )
    else:
        return -1


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 _lowerCAmelCase										=     input('''Enter numbers separated by comma:\n''').strip()
 _lowerCAmelCase										=     [int(item.strip()) for item in user_input.split(''',''')]
 assert collection == sorted(collection), F"List must be ordered.\n{collection}."
 _lowerCAmelCase										=     int(input('''Enter the number to be found in the list:\n''').strip())
 _lowerCAmelCase										=     ite_ternary_search(collection, target)
 _lowerCAmelCase										=     rec_ternary_search(0, len(collection) - 1, collection, target)
 if resulta != -1:
  print(F"""Iterative search: {target} found at positions: {resulta}""")
  print(F"""Recursive search: {target} found at positions: {resulta}""")
 else:
  print('''Not found''')


