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

S1 = 0
S2 = 0
#S1が奇数番目が正の場合、S2が偶数番目が負の場合
cnt = 0

for i,num in enumerate(a):
    S1 += num
    if i % 2 == 0 and S1 <= 0:
        cnt1 += 1 - S1
        S1 = 1
    if i % 2 != 0 and S1 >= 0:
        cnt1 += 1 + S1
        S1 = -1

    S2 += num
    if i % 2 == 0 and S2 >= 0:
        cnt2 += 1 + S2
        S2 = -1
    if i % 2 != 0 and S2 <= 0:
        cnt2 += 1 - S2
        S2 = 1

print(cnt1 if cnt1 <= cnt2 else cnt2)


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

S1 = 0
S2 = 0
#S1が奇数番目が正の場合、S2が偶数番目が負の場合
cnt1 = 0
cnt2 = 0

for i,num in enumerate(a):
    S1 += num
    if i % 2 == 0 and S1 <= 0:
        cnt1 += 1 - S1
        S1 = 1
    if i % 2 != 0 and S1 >= 0:
        cnt1 += 1 + S1
        S1 = -1

    S2 += num
    if i % 2 == 0 and S2 >= 0:
        cnt2 += 1 + S2
        S2 = -1
    if i % 2 != 0 and S2 <= 0:
        cnt2 += 1 - S2
        S2 = 1

print(cnt1 if cnt1 <= cnt2 else cnt2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
A = [n for n in a]

cnt1 = 0
cnt2 = 0
S = 0

if a[0] > 0:
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = -1
    cnt2 = a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
elif a[0] < 0:
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = 1
    cnt2 = -a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
else:
    a[0] = 1
    cnt1 = 1
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = -1
    cnt2 = 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
cnt = cnt2 if cnt1 >= cnt2 else cnt1

print(cnt)


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

S1 = 0
S2 = 0
#S1が奇数番目が正の場合、S2が偶数番目が負の場合
cnt1 = 0
cnt2 = 0

for i,num in enumerate(a):
    S1 += num
    if i % 2 == 0 and S1 <= 0:
        cnt1 += 1 - S1
        S1 = 1
    if i % 2 != 0 and S1 >= 0:
        cnt1 += 1 + S1
        S1 = -1

    S2 += num
    if i % 2 == 0 and S2 >= 0:
        cnt2 += 1 + S2
        S2 = -1
    if i % 2 != 0 and S2 <= 0:
        cnt2 += 1 - S2
        S2 = 1

print(cnt1 if cnt1 <= cnt2 else cnt2)