Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        sums.append(sum(A[:i]) + A[i])
        if i == 0:
            if A[i] == 0:
                index = -1
                for num in A:
                    if num != 0:
                        index = A.index(num)
                        break
                
                if index == -1:
                    res += 3
                    A[i] = 1
                    A[i+1] = -2
                    sums[i] = 1
                elif (index % 2 and A[index] > 0) or (index % 2 == 0 and A[index] < 0):
                    A[i] = -1
                    sums[i] = -1
                    res += 1
                else:
                    A[i] = 1
                    sums[i] = 1
                    res += 1
        else:
            if sums[i] == 0:
                if sums[i-1] > 0:
                    A[i] -= 1
                    sums[i] = sums[i-1] + A[i]
                    res += 1
                else:
                    A[i] += 1
                    sums[i] = sums[i-1] + A[i]
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += A[i] - (-sums[i-1] - 1)
                A[i] = -sums[i-1] - 1
                sums[i] = sums[i-1] + A[i]
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += 1 - (sums[i-1] + A[i])
                A[i] = abs(sums[i-1]) + 1
                sums[i] = sums[i-1] + A[i]
    
    print(res)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = 1
                res += 1
            elif A[i] < 0:
                res += 1 - A[i]
                sums[i] = 1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res += 1
                else:
                    sums[i] = 1
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += 1 - sums[i]
                sums[i] = 1
    
    sums = []
    res1 = 0

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = -1
                res1 += 1
            elif A[i] > 0:
                res1 += 1 + A[i]
                sums[i] = -1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res1 += 1
                else:
                    sums[i] = 1
                    res1 += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res1 += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res1 += 1 - sums[i]
                sums[i] = 1
    
    print(min(res, res1))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        sums.append(sum(A[:i]) + A[i])
        if i == 0:
            if A[i] == 0:
                index = -1
                for num in A:
                    if num != 0:
                        index = A.index(num)
                        break
                
                if index == -1:
                    res += 1
                    A[i] = 1
                    sums[i] = 1
                elif (index % 2 and A[index] > 0) or (index % 2 == 0 and A[index] < 0):
                    A[i] = -1
                    sums[i] = -1
                    res += 1
                else:
                    A[i] = 1
                    sums[i] = 1
                    res += 1
        else:
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] -= 1
                    A[i] -= 1
                    res += 1
                else:
                    sums[i] += 1
                    A[i] += 1
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += sums[i] + 1
                A[i] -= sums[i] + 1
                sums[i] -= sums[i] + 1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += abs(sums[i]) + 1
                A[i] += abs(sums[i]) + 1
                sums[i] += abs(sums[i]) + 1
    
    print(res)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = 1
                res += 1
            elif A[i] < 0:
                res += 1 - A[i]
                sums[i] = 1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res += 1
                else:
                    sums[i] = 1
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += 1 - sums[i]
                sums[i] = 1
    
    sums = []
    res1 = 0

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = -1
                res1 += 1
            elif A[i] > 0:
                res1 += 1 + A[i]
                sums[i] = -1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res1 += 1
                else:
                    sums[i] = 1
                    res1 += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res1 += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res1 += 1 - sums[i]
                sums[i] = 1
    
    print(min(res, res1))

if __name__ == '__main__':
    main()