
from __future__ import annotations





def 						SCREAMING_SNAKE_CASE__     (   __lowerCAmelCase     ,		__lowerCAmelCase				):
    snake_case__    =					get_failure_array(__lowerCAmelCase				)

    # 2) Step through text searching for pattern
    snake_case__    ,       snake_case__    =					0, 0  # index into text, pattern
    while i < len(__lowerCAmelCase				):
        if pattern[j] == text[i]:
            if j == (len(__lowerCAmelCase				) - 1):
                return True
            j += 1

        # if this is a prefix in our pattern
        # just go back far enough to continue
        elif j > 0:
            snake_case__    =					failure[j - 1]
            continue
        i += 1
    return False





def 						SCREAMING_SNAKE_CASE__     (   __lowerCAmelCase				):
    snake_case__    =					[0]
    snake_case__    =					0
    snake_case__    =					1
    while j < len(__lowerCAmelCase				):
        if pattern[i] == pattern[j]:
            i += 1
        elif i > 0:
            snake_case__    =					failure[i - 1]
            continue
        j += 1
        failure.append(__lowerCAmelCase				)
    return failure


if __name__ == "__main__":
     # Test 1)
     __magic_name__  							=	'''abc1abc12'''
     __magic_name__  							=	'''alskfjaldsabc1abc1abc12k23adsfabcabc'''
     __magic_name__  							=	'''alskfjaldsk23adsfabcabc'''
     assert kmp(pattern, texta) and not kmp(pattern, texta)

     # Test 2)
     __magic_name__  							=	'''ABABX'''
     __magic_name__  							=	'''ABABZABABYABABX'''
     assert kmp(pattern, text)

     # Test 3)
     __magic_name__  							=	'''AAAB'''
     __magic_name__  							=	'''ABAAAAAB'''
     assert kmp(pattern, text)

     # Test 4)
     __magic_name__  							=	'''abcdabcy'''
     __magic_name__  							=	'''abcxabcdabxabcdabcdabcy'''
     assert kmp(pattern, text)

     # Test 5)
     __magic_name__  							=	'''aabaabaaa'''
     assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]





def 						SCREAMING_SNAKE_CASE__     (   __lowerCAmelCase				):
    if any(not isinstance(__lowerCAmelCase     ,		__lowerCAmelCase				) or x < 0 for x in sequence				):
        raise TypeError("Sequence must be list of non-negative integers"				)
    for _ in range(len(__lowerCAmelCase				)				):
        for i, (rod_upper, rod_lower) in enumerate(zip(__lowerCAmelCase     ,		sequence[1:]				)				):
            if rod_upper > rod_lower:
                sequence[i] -= rod_upper - rod_lower
                sequence[i + 1] += rod_upper - rod_lower
    return sequence


if __name__ == "__main__":
     assert bead_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
     assert bead_sort([7, 9, 4, 3, 5]) == [3, 4, 5, 7, 9]



