# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param head ListNode类 
# @return int整型
#
class Solution:
    def FindGreatestSumOfSubArray(self , head: ListNode) -> int:
        # write code here
        ans = res = head.val#子链表和最大值,当前项最大累加和
        cur = head.next#首节点已计算,从二号节点开始
        while cur:#遍历整个链表
            res = max(cur.val,res+cur.val)#更新当前项最大累加和
            ans = max(ans,res)#更新当前项子链表最大和
            cur = cur.next
        return ans