Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
c=copy(a)
res_c=0
for i in range(n):
  if ans1[i]*sum(b[:i+1])>0:
    pass
  else:
    b[i]=ans1[i]-sum(b[:i])
    res_b+=abs(b[i]-a[i])
  if -1*ans1[i]*sum(c[:i+1])>0:
    pass
  else:
    c[i]=-1*ans1[i]-sum(c[:i])
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]
ans2=[(-1)**(i+1) for i in range(n)]

b=copy(a)
res_b=0
for i in range(n):
  if ans1[i]*sum(b[:i+1])>0:
    pass
  else:
    b[i]=ans1[i]-sum(b[:i])
    res_b+=abs(b[i]-a[i])
    
c=copy(a)
res_c=0
for i in range(n):
  if ans2[i]*sum(c[:i+1])>0:
    pass
  else:
    c[i]=ans2[i]-sum(c[:i])
    res_c+=abs(c[i]-a[i])
print(min(res_b,res_c))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]
ans2=[(-1)**(i+1) for i in range(n)]

b=copy(a)
res_b=0
for i in range(n):
  if ans1[i]*sum(b[:i+1])>0:
    pass
  else:
    b[i]=ans1[i]-sum(b[:i])
    res_b+=abs(b[i]-a[i])
    
c=copy(a)
res_c=0
for i in range(n):
  if ans2[i]*sum(c[:i+1])>0:
    pass
  else:
    c[i]=ans2[i]-sum(c[:i])
    res_c+=abs(c[i]-a[i])
print(min(res_b,res_c))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
N=int(input())
l=list(map(int, input().split())) 

cp = copy.copy(l)
 
if l[0]!=0:

  for k in range(1,N):
    if sum(l[:k])*sum(l[:k+1])>0:
      l[k]=-np.sign(sum(l[:k]))-sum(l[:k])

  if sum(l)==0:
    print(1+sum([abs(l[n]-cp[n]) for n in range(N)]))
  else:
    print(sum([abs(l[n]-cp[n]) for n in range(N)]))

  
else:#頭0のとき；和0なので変える =>1,-1にした時両方やって良いほうに
  #1にする場合
  sei_l=copy.copy(l)
  sei_l[0]=1
  for k in range(1,N):

    if sum(sei_l[:k])*sum(sei_l[:k+1])>0:

      sei_l[k]=-np.sign(sum(sei_l[:k]))-sum(sei_l[:k])

  if sum(sei_l)==0:
    c1=1+sum([abs(sei_l[n]-cp[n]) for n in range(N)])
  else:
    c1=sum([abs(sei_l[n]-cp[n]) for n in range(N)])  

  #-1にする場合
  fu_l=copy.copy(l)
  fu_l[0]=-1
  for k in range(1,N):

    if sum(fu_l[:k])*sum(fu_l[:k+1])>0:

      fu_l[k]=-np.sign(sum(fu_l[:k]))-sum(fu_l[:k])

  if sum(fu_l)==0:
    c2=1+sum([abs(fu_l[n]-cp[n]) for n in range(N)])
  else:
    c2=sum([abs(fu_l[n]-cp[n]) for n in range(N)])  
  
  print(max(c1,c2))


Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
N=int(input())
l=list(map(int, input().split())) 

cp = copy.copy(l)
 
if l[0]!=0:

  for k in range(1,N):
    if sum(l[:k])*sum(l[:k+1])>0:
      l[k]=-np.sign(sum(l[:k]))-sum(l[:k])

  if sum(l)==0:
    print(1+sum([abs(l[n]-cp[n]) for n in range(N)]))
  else:
    print(sum([abs(l[n]-cp[n]) for n in range(N)]))

  
else:#頭0のとき；和0なので変える =>1,-1にした時両方やって良いほうに
  #1にする場合
  sei_l=copy.copy(l)
  sei_l[0]=1
  for k in range(1,N):

    if sum(sei_l[:k])*sum(sei_l[:k+1])>0:

      sei_l[k]=-np.sign(sum(sei_l[:k]))-sum(sei_l[:k])

  if sum(sei_l)==0:
    c1=1+sum([abs(sei_l[n]-cp[n]) for n in range(N)])
  else:
    c1=sum([abs(sei_l[n]-cp[n]) for n in range(N)])  

  #-1にする場合
  fu_l=copy.copy(l)
  sei_l[0]=-1
  for k in range(1,N):

    if sum(fu_l[:k])*sum(fu_l[:k+1])>0:

      fu_l[k]=-np.sign(sum(fu_l[:k]))-sum(fu_l[:k])

  if sum(fu_l)==0:
    c2=1+sum([abs(fu_l[n]-cp[n]) for n in range(N)])
  else:
    c2=sum([abs(fu_l[n]-cp[n]) for n in range(N)])  
  
  print(max(c1,c2))


Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)

#even_c=0
#odd_c=0
c=0

if l[0]!=0:
  #l[0]=-1
  #even_c=even_c+1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    s=sum(l[:k])
    if s*sum(l[:k+1])>0:
      #print(k)
      c=c+abs(-np.sign(s)-s-l[k])
      l[k]=-np.sign(s)-s
  #print(l)
  if sum(l)==0:
    print(c+1)
    #print(1+sum([abs(l[n]-cp[n]) for n in range(N)]))
  else:
    print(c)
    #print(sum([abs(l[n]-cp[n]) for n in range(N)]))

  
else:
  #1
  sei_l=copy.copy(l)
  sei_l[0]=1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    if sum(sei_l[:k])*sum(sei_l[:k+1])>0:
      #print(k)
      sei_l[k]=-np.sign(sum(sei_l[:k]))-sum(sei_l[:k])
  #print(l)
  if sum(sei_l)==0:
    c1=1+sum([abs(sei_l[n]-cp[n]) for n in range(N)])
  else:
    c1=sum([abs(sei_l[n]-cp[n]) for n in range(N)])  
  #-1
  fu_l=copy.copy(l)
  sei_l[0]=-1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    if sum(fu_l[:k])*sum(fu_l[:k+1])>0:
      #print(k)
      fu_l[k]=-np.sign(sum(fu_l[:k]))-sum(fu_l[:k])
  #print(l)
  if sum(fu_l)==0:
    c2=1+sum([abs(fu_l[n]-cp[n]) for n in range(N)])
  else:
    c2=sum([abs(fu_l[n]-cp[n]) for n in range(N)])  
  
  print(max(c1,c2))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)
 
if l[0]!=0:

  for k in range(1,N):
    if sum(l[:k])*sum(l[:k+1])>0:
      l[k]=-np.sign(sum(l[:k]))-sum(l[:k])

  if sum(l)==0:
    print(1+sum([abs(l[n]-cp[n]) for n in range(N)]))
  else:
    print(sum([abs(l[n]-cp[n]) for n in range(N)]))
  exit()
  
else:
  #1
  sei_l=copy.copy(l)
  sei_l[0]=1
  for k in range(1,N):

    if sum(sei_l[:k])*sum(sei_l[:k+1])>0:

      sei_l[k]=-np.sign(sum(sei_l[:k]))-sum(sei_l[:k])

  if sum(sei_l)==0:
    c1=1+sum([abs(sei_l[n]-cp[n]) for n in range(N)])
  else:
    c1=sum([abs(sei_l[n]-cp[n]) for n in range(N)])  
  #-1
  fu_l=copy.copy(l)
  sei_l[0]=-1
  for k in range(1,N):

    if sum(fu_l[:k])*sum(fu_l[:k+1])>0:

      fu_l[k]=-np.sign(sum(fu_l[:k]))-sum(fu_l[:k])

  if sum(fu_l)==0:
    c2=1+sum([abs(fu_l[n]-cp[n]) for n in range(N)])
  else:
    c2=sum([abs(fu_l[n]-cp[n]) for n in range(N)])  
  
  print(max(c1,c2))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy
N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)

#even_c=0
#odd_c=0


if l[0]!=0:
  #l[0]=-1
  #even_c=even_c+1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    if sum(l[:k])*sum(l[:k+1])>0:
      #print(k)
      l[k]=-np.sign(sum(l[:k]))-sum(l[:k])
  #print(l)
  if sum(l)==0:
    print(1+sum([abs(l[n]-cp[n]) for n in range(N)]))
  else:
    print(sum([abs(l[n]-cp[n]) for n in range(N)]))

  
else:
  #1
  sei_l=copy.copy(l)
  sei_l[0]=1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    if sum(sei_l[:k])*sum(sei_l[:k+1])>0:
      #print(k)
      sei_l[k]=-np.sign(sum(sei_l[:k]))-sum(sei_l[:k])
  #print(l)
  if sum(sei_l)==0:
    c1=1+sum([abs(sei_l[n]-cp[n]) for n in range(N)])
  else:
    c1=sum([abs(sei_l[n]-cp[n]) for n in range(N)])  
  #-1
  fu_l=copy.copy(l)
  sei_l[0]=-1
  for k in range(1,N):
    #print(sum(l[:k]),sum(l[:k+1]))
    if sum(fu_l[:k])*sum(fu_l[:k+1])>0:
      #print(k)
      fu_l[k]=-np.sign(sum(fu_l[:k]))-sum(fu_l[:k])
  #print(l)
  if sum(fu_l)==0:
    c2=1+sum([abs(fu_l[n]-cp[n]) for n in range(N)])
  else:
    c2=sum([abs(fu_l[n]-cp[n]) for n in range(N)])  
  
  print(max(c1,c2))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Runtime Error):
import copy
 
N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)
#c=0
 
for k in range(1,N):
 
  if sum(l[:k])==0:
    #c=c+1
    if l[k]>0:
      l[k]=l[k]+1
    else:
      l[k]=l[k]-1
 
  if sum(l[:k])*sum(l[:k+1])>0:
    
    if sum(l[:k+1])>0:
      l[k]=l[k]-(sum(l[:k+1])-(-1))
      #c=c+abs(sum(l[:k+1])-(-1))
    else:
      l[k]=l[k]+(1-sum(l[:k+1]))
      #c=c+abs(1-sum(l[:k+1]))
 
 
if sum(l)==0:
  c=c+1
  l[-1]=l[-1]+1
 
#print(l)
print(sum([abs(l[n]-cp[n]) for n in range(N)]))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Runtime Error):
import copy

N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)
#c=0

for k in range(N-1):

  if sum(l[:k+1])==0:
    #c=c+1
    if l[k+1]>0:
      l[k+1]=l[k+1]+1
    else:
      l[k+1]=l[k+1]-1

  if sum(l[:k])*sum(l[:k+1])>0:
    
    if sum(l[:k+1])>0:
      l[k]=l[k]-(sum(l[:k+1])-(-1))
      #c=c+abs(sum(l[:k+1])-(-1))
    else:
      l[k]=l[k]+(1-sum(l[:k+1]))
      #c=c+abs(1-sum(l[:k+1]))


if sum(l)==0:
  c=c+1
  l[-1]=l[-1]+1

  
print(sum([abs(l[n]-cp[n]) for n in range(N)]))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))

Buggy python submission (verdict: Runtime Error):
import copy

N=int(input())
l=list(map(int, input().split()))  #リスト入力
cp = copy.copy(l)
#c=0

for k in range(N-1):

  if sum(l[:k+1])==0:
    #c=c+1
    if l[k+1]>0:
      l[k+1]=l[k+1]+1
    else:
      l[k+1]=l[k+1]-1

  if sum(l[:k])*sum(l[:k+1])>0:
    print(k,sum(l[:k]),sum(l[:k+1]),l[k+1])
    if sum(l[:k+1])>0:
      l[k]=l[k]-(sum(l[:k+1])-(-1))
      #c=c+abs(sum(l[:k+1])-(-1))
    else:
      l[k]=l[k]+(1-sum(l[:k+1]))
      #c=c+abs(1-sum(l[:k+1]))
    print(l[k])

if sum(l)==0:
  c=c+1
  l[-1]=l[-1]+1
#print(l)
#print(c)
print(sum([abs(l[n]-cp[n]) for n in range(N)]))

Fixed submission:
from copy import copy
n = int(input())
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]

b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
  sb+=a[i]
  if ans1[i]*sb>0:
    pass
  else:
    b[i]=ans1[i]-(sb-b[i])
    sb=sb-a[i]+b[i]
    res_b+=abs(b[i]-a[i])

  sc+=a[i]
  if -1*ans1[i]*sc>0:
    pass
  else:
    c[i]=-1*ans1[i]-(sc-c[i])
    sc=sc-a[i]+c[i]
    res_c+=abs(c[i]-a[i])
  
print(min(res_b,res_c))