return the maximum possible sum amongst all non empty subsequences raises valueerror when nums is empty maxsubsequencesum1 2 3 4 2 10 maxsubsequencesum2 3 1 4 6 1 maxsubsequencesum traceback most recent call last valueerror input sequence should not be empty maxsubsequencesum traceback most recent call last valueerror input sequence should not be empty try on a sample input from the user return the maximum possible sum amongst all non empty subsequences raises valueerror when nums is empty max_subsequence_sum 1 2 3 4 2 10 max_subsequence_sum 2 3 1 4 6 1 max_subsequence_sum traceback most recent call last valueerror input sequence should not be empty max_subsequence_sum traceback most recent call last valueerror input sequence should not be empty try on a sample input from the user
from collections.abc import Sequence


def max_subsequence_sum(nums: Sequence[int] | None = None) -> int:
    
    if nums is None or not nums:
        raise ValueError("Input sequence should not be empty")

    ans = nums[0]
    for i in range(1, len(nums)):
        num = nums[i]
        ans = max(ans, ans + num, num)

    return ans


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    
    n = int(input("Enter number of elements : ").strip())
    array = list(map(int, input("\nEnter the numbers : ").strip().split()))[:n]
    print(max_subsequence_sum(array))