Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
a = [int(x) for x in input().split()]
ans = n * 1000000000
s = a[0]
cnt = 0
for i in range(1,n):
  ns = s + a[i]
  if s * ns < 0:
    s = ns
    continue
  else:
    cnt += abs(ns)+1
    s = -1 if ns > 0 else 1
ans = min(ans, cnt)

s = -1 if a[0] > 0 else 1
cnt = abs(a[0])+1
for i in range(1,n):
  ns = s + a[i]
  if s * ns < 0:
    s = ns
    continue
  else:
    cnt += abs(ns)+1
    s = -1 if ns > 0 else 1
ans = min(ans, cnt)
print(ans)

# Example run
# Input:
-253690
-1
# Output:
-253690000000000
N = int(input())
a = [int(i) for i in input().split()]

def pura(A):
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += abs(1-A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 + check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 + check))
                A[i] = 1 - check
        check += A[i]
    return ans

print(pura(a))

# Example run
# Input:
0
11
# Output:
0
n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count = 0

for i in range(1, n) :

    if sum == 0 :
        count += 1
        if a[i] > 0 :
            sum = -1
        elif a[i] > 0 :
            sum = 1

    temp = sum
    sum += a[i]
    if temp > 0 and sum > 0 :
        count += sum + 1
        sum = -1
    elif temp < 0 and sum < 0 :
        count += -sum + 1
        sum = 1

if sum == 0 :
    count += 1

print(count)


# Example run
# Input:
-25115
1
# Output:
0
n = int(input())
a = list(map(int,input().split()))

x = a[0]

ans = float('inf')
for _ in range(2):
    tmp = 0
    if _:
        if a[0] > 0:
            x = a[0]
        else:
            x = 1 - a[0]
            tmp = 1 - a[0]
    else:
        if a[0] < 0:
            x = a[0]
        else:
            x = -1 - a[0]
            tmp = 1 + a[0]
    
    for i in range(1, n):
        y = x + a[i]
        if x*y >= 0:
            if x > 0:
                tmp += y+1
                y -= y+1
            elif x < 0:
                tmp -= y-1
                y -= y-1
        x = y
    ans = min(ans, tmp)
print(ans)

# Example run
# Input:
-5271130
19
# Output:
0
n=int(input())
a= (list(map(int,input().split())))
sm1=sm2=0
cnt1=cnt2=0
for i ,num in enumerate(a):
	sm1+=num
	if sm1<=0 and i%2==0:
		cnt1+=1-sm1
		sm1=1
	elif sm1>=0 and i%2!=0:
		cnt1+=1+sm1
		sm1=-1
		
	sm2+=num
	if sm2<=0 and i%2!=0:
		cnt2+=1-sm2
		sm2=1
	elif sm2>=0 and i%2==0:
		cnt2+=1+sm2
		sm2=-1
print(min(cnt1,cnt2))

# Example run
# Input:
228
23
# Output:
0
n=int(input())
p=list(map(int,input().split()))
p2=[i for i in p]
stack=[0]*(n+1)
ans=0
if p[0]<=0:
  ans+=1-p[0]
  p[0]=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      ans+=(p[i]+p[i-1]+stack[i-1])+1
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
  stack[i+1]=p[i]+p[i-1]+stack[i-1]
stack=[0]*(n+1)
ans2=0
if p2[0]>=0:
  ans2+=p2[0]+1
  p[0]=-1
  stack[1]=-1
else:
  stack[1]=p2[0]
for i in range(1,n):
  if i%2==0:
    if p2[i]+p2[i-1]+stack[i-1]>=0:
      ans2+=(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]-=(p2[i]+p2[i-1]+stack[i-1])+1
  else:
    if p2[i]+p2[i-1]+stack[i-1]<=0:
      ans2+=-(p2[i]+p2[i-1]+stack[i-1])+1
      p2[i]+=-(p2[i]+p2[i-1]+stack[i-1])+1
  stack[i+1]=p2[i]+p2[i-1]+stack[i-1]
print(min(ans,ans2))      

# Example run
# Input:
1
4887419
# Output:
0
n = int(input())
A = list(map(int, input().split()))

plus_ans = 0
minus_ans = 0

for i in range(len(A)):
    if i == 0:
        if A[0] <= 0:
            plus_ans += A[0] + 1
            sum = 1
        else:
            sum = A[0]
    else:
        if sum > 0:
            if sum + A[i] >= 0:
                plus_ans += abs(sum + A[i]) + 1
                sum = -1
            else:
                sum += A[i]
        elif sum < 0:
            if sum + A[i] <= 0:
                plus_ans += abs(sum + A[i]) + 1
                sum = 1
            else:
                sum += A[i]

for i in range(len(A)):
    if i == 0:
        if A[0] >= 0:
            minus_ans += A[0] + 1
            sum = -1
        else:
            sum = A[0]
    else:
        if sum > 0:
            if sum + A[i] >= 0:
                minus_ans += abs(sum + A[i]) + 1
                sum = -1
            else:
                sum += A[i]
        elif sum < 0:
            if sum + A[i] <= 0:
                minus_ans += abs(sum + A[i]) + 1
                sum = 1
            else:
                sum += A[i]

print(min(plus_ans, minus_ans))


# Example run
# Input:
107
186860433
# Output:
0
N = int(input())
L = list(map(int, input().split()))

tmp = L[0]
res = 0

def diff(a,b):
    if a*b < 0:
        return True
    else:
        return False

if tmp == 0:
    tmp = -1
    res = 1

        
    for i in range(1, N):
        n = L[i] + tmp
        if diff(n, tmp):
            tmp = n
        else:
            if tmp < 0:
                res = res + abs(n) + 1
                tmp = 1
            else:
                res = res + abs(n) + 1
                tmp = -1
    res1 = res
    
    res = 1
    tmp = 1
    for i in range(1, N):
        n = L[i] + tmp
        if diff(n, tmp):
            tmp = n
        else:
            if tmp < 0:
                res = res + abs(n) + 1
                tmp = 1
            else:
                res = res + abs(n) + 1
                tmp = -1
    
    print(min(res, res1))
    
else:
    tmp = L[0]
    res = 0
    for i in range(1, N):
        n = L[i] + tmp
        if diff(n, tmp):
            tmp = n
        else:
            if tmp < 0:
                res = res + abs(n) + 1
                tmp = 1
            else:
                res = res + abs(n) + 1
                tmp = -1
    print(res)

# Example run
# Input:
-831
110
# Output:
0
#!/usr/bin/env python3
from itertools import accumulate

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = list(accumulate(a))
    
    if a[0] != 0:
        ans = 0
        diff = 0
        for i in range(1,n):
            p = a[i] + diff
            q = a[i-1] + diff
            if p * q >= 0:
                tmp = -q//abs(q) - p
                ans += abs(tmp)
                diff += tmp
        print(ans)
    else:
        ans = 10**18
        for d in [-1,1]:
            ans2 = 1
            for i in range(1,n):
                p = a[i] + d
                q = a[i-1] + d
                if p * q >= 0:
                    tmp = -q//abs(q) - p
                    ans2 += abs(tmp)
                    diff += tmp
            ans = min(ans, ans2)
        print(ans)

if __name__ == "__main__":
    main()


# Example run
# Input:
-80
-7517
# Output:
0
N = int(input())
A = list(map(int, input().split()))

def count(s):
    ans = 0
    for i, a in enumerate(A):
        if i == 0:
            continue
        if s < 0:
            if 1-s-a >= 0:
                ans += 1-s-a
                s = 1
            else:
                s += a
        elif s > 0:
            if s+a+1 >= 0:
                ans += s+a+1
                s = -1
            else:
                s += a
    return ans

b = A[0]
ans1 = count(b)
if b > 0:
    ans2 = count(-1)+b+1
elif b < 0:
    ans2 = count(1)+1-b
else:
    ans1 = count(1)+1
    ans2 = count(-1)+1
print(min(ans1, ans2))

# Example run
# Input:
-1
1297484349
# Output:
0
n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count = 0

for i in range(1, n) :
    temp = sum
    sum += a[i]
    if temp > 0 and sum > 0 :
        while sum >= 0 :
            count += 1
            sum -= 1
    elif temp < 0 and sum < 0 :
        while sum <= 0 :
            count += 1
            sum += 1

if sum == 0 :
    count += 1

print(count)


# Example run
# Input:
-591
41555
# Output:
0
# -*- coding: utf-8 -*-

N = int(input())
aN = list(map(int, input().split()))

sum1 = aN[0]
cnt = 0
if aN[0] > 0:
    sei = True
elif aN[0] < 0:
    sei = False
else:
    print("和が0なので、これはないはず")

for i in range(1,N):
    sum1 += aN[i]
    if sei:
        if sum1 >= 0:
            tmp = abs(sum1) +1
            cnt += tmp
            sum1 -= tmp
        sei = False
    else:
        if sum1 <= 0:
            tmp = abs(sum1) +1
            cnt += tmp
            sum1 += tmp
        sei = True
print(cnt)

# Example run
# Input:
1
17917685
# Output:
0
n = int(input())
A = list(map(int,input().split()))
acm1 = 0
acm2 = 0
ans1 = 0
ans2 = 0
for i, a in enumerate(A):
  acm1 += a
  acm2 += a
  if(i%2==1):
    if(acm1>=0):
      ans1 += acm1 + 1
      acm1 = -1
    if(acm2<=0):
      ans2 += -acm2 + 1
      acm2 = 1
  else:
    if(acm1<=0):
      ans1 += -acm1 + 1
      acm1 = 1
    if(acm2>=0):
      ans2 += acm2 + 1
      acm2 = -1
print(min(ans1, ans2))

# Example run
# Input:
281433
23263394
# Output:
0
n=int(input())
A=list(map(int,input().split()))
b=0
count=0
x=0
if A[0]>0:
    x=-1
else:
    x=1
for a in A:
    b+=a
    if x==1:
        if b<0:
            x=-1
        else:
            count+=1+b
            b=-1
            x=-1
    else:
        if b>0:
            x=1
        else:
            count+=1-b
            b=1
            x=1
print(count if b!=0 else count+1)

# Example run
# Input:
-23909
-68
# Output:
0
N = input()
a = list(map(int, input().split()))
 
def f(x):
  cnt = 0
  cur = 0
  for ai in a:
    cur += ai
    cur *= x
    if cur <= 0:
      cnt += 1 - cur
      cur = 1
    cur *= x
    x *= -1
  return cnt
 
print(min(f(1), f(-1)))

# Example run
# Input:
CFhk~
65390879
# Output:
0
n=int(input())
a=list(map(int,input().split()))
import sys
sum=a[0]
cnt=0
if a[0]==0:
    sum+=1
    cnt+=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<0:
                cnt+=(1-z)
                sum=1
            else:
                if sum>0:
                    sum=-1
                    cnt+=1
                elif sum<0:
                    sum=1
                    cnt+=1
        elif sum>0:
            z=sum+a[i]
            if z>0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
            else:
                if sum>0:
                    sum=-1
                    cnt+=1
                elif sum<0:
                    sum=1
                    cnt+=1
    cnt_plus=cnt
    sum=-1
    cnt=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<0:
                cnt+=(1-z)
                sum=1
            else:
                if sum>0:
                    sum=-1
                    cnt+=1
                elif sum<0:
                    sum=1
                    cnt+=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
            else:
                if sum>0:
                    sum=-1
                    cnt+=1
                elif sum<0:
                    sum=1
                    cnt+=1
    cnt_sbst=cnt
    print(min(cnt_plus,cnt_sbst))
    sys.exit()
for i in range(1,n):
    if sum<0:
        z=sum+a[i]
        if z>0:
            sum=z
        elif z<0:
            cnt+=(1-z)
            sum=1
        else:
            if sum>0:
                sum=-1
                cnt+=1
            elif sum<0:
                sum=1
                cnt+=1
    elif sum>0:
        z=sum+a[i]
        if z>0:
            cnt+=(z+1)
            sum=-1
        elif z<0:
            sum=z
        else:
            if sum>0:
                sum=-1
                cnt+=1
            elif sum<0:
                sum=1
                cnt+=1
            
print(cnt)

# 6
# 0 0 -1 3 5 0





# Example run
# Input:
-15303
-412794
# Output:
0
n=int(input())
l=[int(i) for i in input().split()]
sm=l[0]
req=0 
pr=1 
if sm>0:
    pass 
else:
    req+=-sm+1 
    sm=1 
for i in range(1,n):
    if pr==1:
        n1=sm+l[i]
        if n1<0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=sm+1 
            sm=-1 
    else: 
        n1=sm+l[i]
        if n1>0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=(-sm+1) 
            sm=1 
    pr=1-pr  
req1=0 
pr=0
sm=l[0]
if sm<0:
    pass 
else:
    req1+=sm+1 
for i in range(1,n):
    if pr==1:
        n1=sm+l[i]
        if n1<0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req1+=sm+1 
            sm=-1 
    else: 
        n1=sm+l[i]
        if n1>0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req1+=(-sm+1) 
            sm=1 
    pr=1-pr  
print(min(req,req1))

# Example run
# Input:
-7467726
1372619017
# Output:
0
#!/usr/bin/env python3
import copy

n = int(input())
am = list(map(int, input().split()))

pcnt = 0
mcnt = 0

f = 0  #前の項の符号（1:+、2:-）
wa = 0

#最初の数字を正とするとき
a = copy.copy(am)
f = 2

for i in range(len(a)):
    wa += a[i]

    if f == 1:#-にする必要あり
        if wa > -1:
            pcnt += wa + 1
            a[i] -= wa + 1

        f = 2

    elif f == 2:  #+にする必要あり

        if wa < 1:
            pcnt += -wa + 1
            a[i] += -wa + 1
        
        f = 1
    
    wa = sum(a[0: i + 1])

#最初の数字を負とするとき
a = copy.copy(am)
f = 1

for i in range(len(a)):
    wa += a[i]

    if f == 1:  # -にする必要あり
        if wa > -1:
            mcnt += wa + 1
            a[i] -= wa + 1

        f = 2

    elif f == 2:  # +にする必要あり

        if wa < 1:
            mcnt += -wa + 1
            a[i] += -wa + 1

        f = 1

    wa = sum(a[0: i + 1])

print(min(pcnt, mcnt))


# Example run
# Input:
1
-33599094
# Output:
0
N = int(input())
a = list(map(int,input().split(" ")))


def is_positive(sumval,modify):
	if sumval <= 0:
		modify += abs(sumval - 1)
		sumval = 1

	return sumval,modify

def is_negative(sumval,modify):
	if sumval >= 0:
		modify += abs(sumval + 1)
		sumval = (-1)


	return sumval,modify

pos_sum,pos_modi = is_negative(a[0],0)
neg_sum,neg_modi = is_positive(a[0],0)

for i in range(1,N):
	tmp_sum,tmp_modi = is_positive(pos_sum + a[i],pos_modi)
	pos_sum,pos_modi = is_negative(neg_sum + a[i],neg_modi)
	neg_sum = tmp_sum
	neg_modi = tmp_modi

print(min(pos_modi,neg_modi))


# Example run
# Input:
-24
-35784
# Output:
0
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
n = int(input())
a = list(map(int,input().split()))

ans = 1e16
for s in [1, -1]:
  res, csum = 0, 0
  for a_i in a:
    csum += a_i
    if csum * s <= 0:
      res += abs(csum-s)
      csum = s
    s *= -1
  ans = min(ans, res)

print(ans)

# Example run
# Input:
1813543
-252699780
# Output:
0
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))

# Example run
# Input:
/8]
-1964
# Output:
0
n = int(input())
a = list(map(int, input().split()))

sm = a[0]


def f(sm):
    ret = 0
    for e in a[1:]:
        if sm * (sm + e) < 0:
            sm += e
            continue

        else:
            if sm > 0:
                a_mx = -sm - 1
                ret += e - a_mx
                sm += a_mx
            else:
                a_mn = -sm + 1
                ret += a_mn - e
                sm += a_mn

    return ret


if sm != 0:
    ans = f(sm)
else:
    ans = min(f(1), f(-1)) + 1

print(ans)


# Example run
# Input:
1
0
# Output:
1
n = int(input())
A = [int(i) for i in input().split()]

c = 10**15
for i in range(2):
    A = [-a for a in A]
    if A[0] != 0:
        ans = 0
        S = A[0]
        f = A[0]//abs(A[0])
    else:
        ans = 1
        S = 1
        f = 1

    for a in A[1:]:
        S += a
        if S == 0:
            ans += 1
            S = -f
        else:
            if S/abs(S) != f*(-1):
                ans += abs(S)+1
                S = -f
        f *= -1
    c = min(ans, c)
print(c)


# Example run
# Input:
-3753932
42339391
# Output:
0
def first_positive(n,a):
    count = 0
    sum = a[0]
    #正ならTrue
    flag = True

    if a[0] <= 0:
        sum = 1
        count += abs(1 - a[0])

    for i in range(1,n):
        if sum + a[i] < 0 and flag == True:
            sum += a[i]
            flag = False
            continue
        elif sum + a[i] <= 0 and flag == False:
            flag = True
            count += abs(1 - sum - a[i])
            sum = 1
        elif sum + a[i] >= 0 and flag == True:
            flag = False
            count += abs(-1 - sum - a[i])
            sum = -1
        elif sum + a[i] > 0 and flag == False:
            sum += a[i]
            flag = True
            continue

    return count

def first_negative(n,a):
    count = 0
    sum = a[0]
    #正ならTrue
    flag = False

    if a[0] >= 0:
        sum = -1
        count += abs(-1 - a[0])

    for i in range(1,n):
        if sum + a[i] < 0 and flag == True:
            sum += a[i]
            flag = False
            continue
        elif sum + a[i] <= 0 and flag == False:
            flag = True
            count += abs(1 - sum - a[i])
            sum = 1
        elif sum + a[i] >= 0 and flag == True:
            flag = False
            count += abs(-1 - sum - a[i])
            sum = -1
        elif sum + a[i] > 0 and flag == False:
            sum += a[i]
            flag = True
            continue

    return count

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]

    p = first_positive(n,a)
    n = first_negative(n,a)

    if p < n:
        print(p)
    else:
        print(n)


# Example run
# Input:
-31
-58867430
# Output:
0
import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

a_sum = [a_i[0]]
for i, a in enumerate(a_i[1:]):
    i += 1
    a_sum.append(a_sum[-1]+a)

signs = [1, -1]
for i, sum_i in enumerate(a_sum):
    if sum_i != 0:
        signs[i%2] = sign(sum_i)
        signs[i%2+1] = -sign(sum_i)
        break

a_sum = 0
changes = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes += abs(a_sum) + 1
        a_sum = signs[i%2]
print(changes)

#
# for i, sum_i in enumerate(a_sum):
#     if i == 0:
#         signs = [sign(sum_i), -sign(sum_i)]
#     elif sign(sum_i) != signs[i%2]:
#         a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]]
#         changes += abs(sum_i) + 1
#     # print(a_sum)
# print(changes)


# Example run
# Input:
ixhv*'
449245
# Output:
0
#!/usr/bin/env python3
from itertools import accumulate

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = list(accumulate(a))

    ans = 10**18
    diff = [0, 0]# a[0]<0, a[0]>0それぞれの初期コスト
    for i in range(2):
        if a[0] * [-1,1][i] >= 0:
            diff[i] = [-1,1][i] * (abs(a[0])+1)

    for j in range(2):
        ans2 = abs(diff[j])
        for i in range(1,n):
            p = a[i] + diff[j]
            q = a[i-1] + diff[j]
            if p * q >= 0:
                ans2 += abs(p)+1
                diff[j] -= p+1
        ans = min(ans, ans2)
    print(ans)

if __name__ == "__main__":
    main()


# Example run
# Input:
-15915
-501843
# Output:
0
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    count=0
    suml=l[0]
    for i in range(1,n):
        if suml>0 and suml+l[i]<0:
            suml+=l[i]
        elif suml<0 and suml+l[i]>0:
            suml+=l[i]
        elif suml>0 and suml+l[i]>=0:
            count+=suml+l[i]+1
            suml=-1
        else:
            count+=-suml-l[i]+1
            suml=1
    a1=count
    count=abs(l[0])+1
    suml=-l[0]
    for i in range(1,n):
        if suml>0 and suml+l[i]<0:
            suml+=l[i]
        elif suml<0 and suml+l[i]>0:
            suml+=l[i]
        elif suml>0 and suml+l[i]>=0:
            count+=suml+l[i]+1
            suml=-1
        else:
            count+=-suml-l[i]+1
            suml=1
    a2=count
    print(min(a1,a2))
    
else:
    count=1
    suml1=1
    for i in range(1,n):
        if suml1>0 and suml1+l[i]<0:
            suml1+=l[i]
        elif suml1<0 and suml1+l[i]>0:
            suml1+=l[i]
        elif suml1>0 and suml1+l[i]>=0:
            count+=suml1+l[i]+1
            suml1=-1
        else:
            count+=-suml1-l[i]+1
            suml1=1
    k1=count
    count=1
    suml2=-1
    for i in range(1,n):
        if suml2>0 and suml2+l[i]<0:
            suml2+=l[i]
        elif suml2<0 and suml2+l[i]>0:
            suml2+=l[i]
        elif suml2>0 and suml2+l[i]>=0:
            count+=suml2+l[i]+1
            suml2=-1
        else:
            count+=-suml2-l[i]+1
            suml2=1
    k2=count
    print(min(k1,k2))
    

# Example run
# Input:
-5701370
-3339504
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]


def check(a, t):
    ans = 0
    x = 0
    for i in a:
        x += i
        if t == True and x < 1:
            ans += 1 - x
            x = 1
        elif t == False and x > -1:
            ans += x + 1
            x = -1
        t = not t
    return ans


print(min(check(a, True), check(a, False)))


# Example run
# Input:
-274078593
-28418
# Output:
0
n=int(input())
a=list(map(int,input().split()))
ans=999999999999999
temp=True
for i in range(2):
  count=0
  temp=0
  if i==0:
    t=True
  else:
    t=False
  for j in a:
    temp=temp+j
    if t==True and temp<1:
      count=count+1-temp
      temp=1
    elif t==False and temp>-1:
      count=count+1+temp
      temp=-1
    if t==True:
      t=False
    else:
      t=True
  ans=min(ans,count)
print(ans)

# Example run
# Input:
113
-194715587
# Output:
0
n = int(input())
a = list(map(int, input().split()))

sm = a[0]


def f(sm):
    ret = 0
    for e in a[1:]:
        if sm * (sm + e) < 0:
            sm += e
            continue

        else:
            if sm > 0:
                a_mx = -sm - 1
                ret += e - a_mx
                sm += a_mx
            else:
                a_mn = -sm + 1
                ret += a_mn - e
                sm += a_mn

    return ret


if sm > 0:
    ans = min(f(sm), f(-1) + sm + 1)
elif sm < 0:
    ans = min(f(sm), f(1) - sm + 1)
else:
    ans = min(f(1), f(-1)) + 1

print(ans)


# Example run
# Input:
3770
22710854
# Output:
0
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))


# Example run
# Input:
QV_
-66
# Output:
0