Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    ans -= 1
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and (a[j] == abs(a[j])) != (s == abs(s)):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and (a[j] == abs(a[j])) != (s == abs(s)):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s, ans, i = 0, 0, 0
while a[i] == 0 and i < n:
    ans += 2
    i += 1
ans = max(0, ans - 1)
if i == n:
    print(ans)
    exit()

if ans > 0:
    if abs(a[i]) == 1:
        ans += 1
        s = a[i] // abs(a[i])
else:
    s = a[0]

i += 1
for j in range(i, n):
    if abs(a[j]) > abs(s) and a[j] // abs(a[j]) != s // abs(s):
        s += a[j]
    else:
        pre_s = s
        s = -1 * s // abs(s)
        ans += abs(a[j] - s + pre_s)

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
s, ans, i = 0,0,0
while a[i] == 0 and i < n:
  ans += 2
  i += 1
ans = max(0, ans - 1)
if i == n:
  print(ans)
  exit()

if ans > 0:
  if abs(a[i]) == 1:
    ans += 1
    s = a[i] // abs(a[i])
else:
  s = a[0]

i += 1
for j in range(i,n):
  if abs(a[j]) > abs(s) and a[j] // abs(a[j]) != s // abs(s):
    s += a[j]
  else:
    s = -1 * s // abs(s)
    ans += abs(abs(a[j]) - 2)
  
  
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))