Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
import copy
a2 = copy.copy(a)

ans1 = 0 #偶数インデックスが正
for i in range(n):
    s1 = sum(a[:i+1])
    if i % 2 == 0:
        if s1 <= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] += x
        else:
            continue
    else:
        if s1 >= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    s2 = sum(a2[:i+1])
    if i % 2 == 1:
        if s2 <= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] += x
        else:
            continue
    else:
        if s2 >= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] -= x

print(min(ans1, ans2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a2 = a.copy()

ans1 = 0 #偶数インデックスが正
for i in range(n):
    s1 = sum(a[:i+1])
    if i % 2 == 0:
        if s1 <= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] += x
        else:
            continue
    else:
        if s1 >= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    s2 = sum(a2[:i+1])
    if i % 2 == 1:
        if s2 <= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] += x
        else:
            continue
    else:
        if s2 >= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] -= x

print(min(ans1, ans2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a2 = a.copy()

ans1 = 0 #偶数インデックスが正
for i in range(n):
    s1 = sum(a[:i+1])
    if i % 2 == 0:
        if s1 <= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] += x
        else:
            continue
    else:
        if s1 >= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    s2 = sum(a2[:i+1])
    if i % 2 == 1:
        if s2 <= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] += x
        else:
            continue
    else:
        if s2 >= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] -= x

print(min(ans1, ans2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s1 = []
s2 = []
for i in range(n):
    s1.append(sum(a[:i+1]))
    s2.append(sum(a[:i+1]))
ans1 = 0 #偶数インデックスが正
for i in range(n):
    if i % 2 == 0:
        if s1[i] <= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i, n):
                s1[j] += x
        else:
            continue
    else:
        if s1[i] >= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i,n):
                s1[j] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    if i % 2 == 1:
        if s2[i] <= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i, n):
                s2[j] += x
        else:
            continue
    else:
        if s2[i] >= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i,n):
                s2[j] -= x

print(min(ans1, ans2))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)