Buggy python submission (verdict: Runtime Error):
import sys
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# 無変更チェック
if a[0]!=0:
  S=int(a[0])
  for i in range(1,n):
    if S<0 and S+a[i]<=0:
      break
    elif S>0 and S+a[i]>=0:
      break
    S+=a[i]
    if i==n-1:
      print(0)
      sys.exit()
# a[0]を1に変えた場合の計算
counter_2=abs(b[0]-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+b[i]<=0:
    counter_2+=-S-b[i]+1
    b[i]=-S+1
  elif S>0 and S+b[i]>=0:
    counter_2+=S+b[i]+1
    b[i]=-S-1
  S+=b[i]
# a[0]を-1に変えた場合の計算
counter_3=abs(c[0]+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+c[i]<=0:
    counter_3+=-S-c[i]+1
    c[i]=-S+1
  elif S>0 and S+c[i]>=0:
    counter_3+=S+c[i]+1
    c[i]=-S-1
  S+=c[i]
print(min(counter_1,counter_2,counter_3))

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
counter=0
S=a[0]
# 出力
for i in range(1,n):
  S+=a[i]
  if S<0 and S+int(a[i])<=0:
    counter+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter+=S+int(a[i])+1
    a[i]=-S-1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
counter=0
# 出力
for i in range(1,n):
  S=0
  for j in range(0,i):
    S+=int(a[j])
  if S<0 and S+int(a[i])<=0:
    counter+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter+=S+int(a[i])+1
    a[i]=-S-1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
counter=0
# 出力
for i in range(1,n):
  S=0
  for j in range(0,i):
    S=S+int(a[j])
  if S<0 and S+int(a[i])<=0:
    counter=counter-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter=counter+S+int(a[i])+1
    a[i]=-S-1
print(counter)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))