Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
import copy 

def resolve(List):
    # L[0]!=0を起点とする
    L = copy.deepcopy(List)
    cnt = 0
    s = L[0]
    for i in range(1,len(L)):
        a = L[i]
        if(s>0 and s+a>=0):
            L[i] = -s-1
            cnt += (s+a+1)
            s = -1
        elif(s<0 and s+a<=0):
            L[i] = -s+1
            cnt += (-s-a+1)
            s = 1
        else:
            s += a
    return cnt      

def ans(List):
    L = copy.deepcopy(List)
    a = L[0]
    c0,c1=0,0

    if (a>0):
        c0 = resolve(L)
        c1 = (a+1) + resolve([-1]+L[1:])
    elif (a<0):
        c0 = resolve(L)
        c1 = (-a+1) + resolve([1]+L[1:])
    else:
        c0 = 1 + resolve([1]+L[1:])
        c1 = 1 + resolve([-1]+L[1:])
    
    return(min(c0,c1))

def main():
    N = int(input())
    List = [int(x) for x in input().split(' ')]
    print(ans(List))

main()


# Example run
# Input:
2116
-579377
# Output:
0
n = int(input())
a_list = list(map(int, input().split()))

sum1 = a_list[0]

def func(sum1):
    cost = 0
    for i in a_list[1:]:
        # 前の合計値と次の合計値の積が負になれば良い
        if sum1 * (sum1 + i) < 0:
            sum1 += i
            continue
        else:
            if sum1 < 0:
                a_new = 1 - sum1
                cost += a_new - i
                sum1 += a_new
            else:
                a_new = -1 - sum1
                cost += i - a_new
                sum1 += a_new

    return cost

if a_list[0] > 0:
    # リストの最初が-1の場合のコストも考える
    answer = min(func(sum1), func(-1)+a_list[0]+1)
elif a_list[0] < 0:
    answer = min(func(sum1), func(1)-a_list[0]+1)
else:
    # リストの最初が0だったとき
    answer = min(func(1), func(-1)) + 1

print(answer)

# Example run
# Input:
-7737
-126905272
# Output:
0
def culc(a, plus, ans):
    sum = a[0]
    for i in range(1, len(a)):
        plus = not(plus)
        sum += a[i]
        if plus:
            if sum <= 0:
                ans += abs(sum) + 1
                sum = 1
        else:
            if sum >= 0:
                ans += abs(sum) + 1
                sum = -1
    return ans

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

plus = None
ans = 0
if a[0] == 0:
    ans += 1
    a[0] = 1
    plus = True
elif a[0] > 0:
    plus = True
else:
    plus = False

ans1 = culc(a, plus, ans)

a[0] = a[0] // abs(a[0]) * -1

ans2 = culc(a, not(plus), abs(a[0]) + 1 - ans)

print(min(ans1, ans2))

# Example run
# Input:
140940
-2
# Output:
0
def my_sign(x):
    return (x > 0) - (x < 0)

N = int(input())
A = list(map(int,input().split()))
tsum = 0 #これが答え。いくつ足したか。
nsum = A[0]
#一個目をプラスにする場合
if A[0] <= 0:
  nsum = 1
  tsum = 1-A[0]
for i in range(1,N):
  #print(nsum,nsum+A[i],tsum)
  if my_sign(nsum)*my_sign(nsum+A[i]) == -1: #符号が違う場合はそのままでおｋ
    #print(nsum,"A")
    nsum += A[i]
  else:
    if nsum>0: #次で負にする必要がある
      #print(abs(nsum+A[i]+1))
      tsum += abs(nsum+A[i]+1)
      nsum = -1
    else:
      #print(nsum+A[i],abs(nsum+A[i]-1),"X")
      tsum += abs(nsum+A[i]-1)
      nsum = 1      
ans = tsum
#print(ans)
tsum = 0 #これが答え。いくつ足したか。
nsum = A[0]
#一個目をマイナスにする場合
if A[0] >= 0:
  nsum = -1
  tsum = A[0]+1
for i in range(1,N):
  #print(nsum,nsum+A[i],tsum)
  if my_sign(nsum)*my_sign(nsum+A[i]) == -1: #符号が違う場合はそのままでおｋ
    nsum += A[i]
  else:
    if nsum>0: #次で負にする必要がある
      tsum += abs(nsum+A[i]+1)
      nsum = -1
    else:
      #print(nsum,nsum+A[i])
      tsum += abs(nsum+A[i]-1)
      nsum = 1
ans = min(ans,tsum)
print(ans)
      

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

#前から貪欲でよいか
#a[0]を正か負に定めて貪欲

#a[0]が正と仮定してよい
if a[0]<0:
    for i in range(n):
        a[i]*=-1

#場合分け用
a2 = [a[i] for i in range(n)]


ans1 = 0
if not a[0]:
    ans1 += 1
    a[0] = 1
sm = a[0]

for i in range(1,n):
    sm2 = sm + a[i]
    #print(sm,sm2)
    if sm2*sm>=0:
        if sm<0:#sm+a[i]=1
            ans1 += abs((1-sm)-a[i])
            a[i]=1-sm
            sm = 1
            
        else:#sm+a[i] = -1
            ans1 += abs(-1-sm-a[i])
            a[i]=-1-sm
            sm = -1
    else:
        sm=sm2

ans2 = abs(-1-a2[0])
a2[0]=-1
sm = -1

for i in range(1,n):
    sm2 = sm + a2[i]
    if sm2*sm>=0:
        if sm<0:#sm+a[i]=1
            ans2 += abs((1-sm)-a2[i])###a[i]と間違えるから関数として定義してa1,a2投げる
            a2[i] = 1-sm
            sm = 1
        else:#sm+a[i] = -1
            ans2 += abs(-1-sm-a2[i])###
            a2[i]=-1-sm
            sm = -1
    else:
        sm =sm2
   

print(min(ans1,ans2))
            

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

if A[0] < 0:
	sumP = 1
	sumM = A[0]
	countP = -A[0] + 1
	countM = 0
elif A[0] == 0:
	sumP = 1
	sumM = -1
	countP = 1
	countM = 1
else:
	sumP = A[0]
	sumM = -1
	countP = 0
	countM = -A[0] + 1

for i in range(1, N):
	if sumP > 0:
		if A[i] + sumP >= 0:
			countP += A[i] + sumP + 1
			sumP = -1
		else:
			sumP += A[i]
	else:
		if A[i] + sumP <= 0:
			countP += -(A[i] + sumP) + 1
			sumP = 1
		else:
			sumP += A[i]
	
	if sumM > 0:
		if A[i] + sumM >= 0:
			countM += A[i] + sumM + 1
			sumM = -1
		else:
			sumM += A[i]
	else:
		if A[i] + sumM <= 0:
			countM += -(A[i] + sumM) + 1
			sumM = 1
		else:
			sumM += A[i]

print(min(countP, countM))

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

cnt1,cnt2,sm1,sm2=0,0,0,0
for i in a:#+
	sm1+=i
	if a.index(i)%2 ==0:
		if sm1<1:
			cnt1+=1-sm1
			sm1=1
	else:
		if sm1>-1:
			cnt1+=1+sm1
			sm1=-1

for i in a:#-
	sm2=i
	if a.index(i)%2 ==0:
		if sm2>-1:
			cnt2+=1+sm2
			sm2=-1
		else:
			if sm2<1:
				cnt2+=1-sm2
				sm2=1
				
print(min(cnt1,cnt2))

# Example run
# Input:
-6019
139893
# Output:
0
n = int(input())
a = list(map(int, input().split()))
t1, s1 = 0, 0
for i, x in enumerate(a):
    s1 += x
    if i % 2 == 0:
        if s1 < 1:
            t1 += (1-s1)
            s1 = 1
    else:
        if s1 > -1:
            t1 += (s1+1)
            s1 = -1
t2, s2 = 0, 0
for i, x in enumerate(a):
    s2 += x
    if i % 2 == 0:
        if s2 > -1:
            t2 += (s2+1)
            s2 = -1
    else:
        if s2 < 1:
            t2 += (1-s2)
            s2 = 1
print(min(t1, t2))

# Example run
# Input:
3469
-1817683
# Output:
0
import copy

n = int(input())
a = list(map(int,(input().split())))
s = [0]*n
s[0] = a[0]
for i in range(n-1):
    s[i+1] = s[i] + a[i+1]

s2 = copy.copy(s)
ans = []

# 最初を正とする場合
ans1 = 0
tmp = 0
for i in range(n):
    if i%2 == 0: #奇数項
        s[i] += tmp
        if s[i] <= 0:
            tmp += 1 - s[i]
            ans1 += 1 - s[i]
    else: #偶数項
        s[i] += tmp
        if s[i] >= 0:
            tmp -= s[i] + 1
            ans1 += s[i] + 1

s = s2
# 最初を負とする場合
ans2 = 0
tmp = 0
for i in range(n):
    if i%2 == 0: #奇数項
        s[i] += tmp
        if s[i] >= 0:
            tmp -= s[i] + 1
            ans2 += s[i] + 1
    else: #偶数項
        s[i] += tmp
        if s[i] <= 0:
            tmp += 1 - s[i]
            ans2 += 1 - s[i]

print(min(ans1,ans2))

# Example run
# Input:
1
-12503953
# Output:
0
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:
456
212
# Output:
0
n = int(input())
A = [int(i) for i in input().split()]

ff = -1
for i in range(n):
    if A[i] != 0:
        ff = i
        break

if A[0] != 0:
    ans = 0
    S = A[0]
    f = A[0]//abs(A[0])
else:
    if ff == -1:
        ans = 1
        S = 1
        f = 1
    else:
        if ff % 2 == 0:
            ans = 1
            S = 1
            f = 1
        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
print(ans)


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

#      0  1  2  3  evn odd
# kevn +  -  +  -   +   -
# kodd -  +  -  +   -   +

def kf(a,flag,n):
    a0=a[0]*flag
    if a0<=0:
        kevn=1-a0
        sevn=1
    elif a0>0:
        kevn=0
        sevn=a0

    for i in range(1,n):
        ai=a[i]*flag
        if i%2==0:
            if sevn+ai<=0:
                kevn=kevn+1-(ai+sevn)
                sevn=1
            elif sevn+ai>0:
                kevn=kevn
                sevn=sevn+ai
        elif i%2==1:
            if sevn+ai<0:
                kevn=kevn
                sevn=sevn+ai
            elif sevn+ai>=0:
                kevn=kevn+1+(ai+sevn)
                sevn=-1
    return kevn

print(min(kf(a,1,n),kf(a,-1,n)))
            

# Example run
# Input:
-554740
65444
# Output:
0
def solve():
  ans = 0
  N = int(input())
  A = list(map(int, input().split()))
  total = A[0]
  if total==0:
    for i in range(1,N):
      if A[i]!=0:
        total = pow(-1,i)*A[i]//abs(A[i])
        break
    else:
      return 2*N-1
  for i in range(1,N):
    new_total = total+A[i]
    if total*(new_total)>=0:
      new_total = (-1)*total//abs(total)
      ans += abs(new_total-(total+A[i]))
    total = new_total
  return ans
print(solve())

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

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S > 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-A[0] // abs(A[0])) + abs(A[0]) + 1)
print(ans)


# Example run
# Input:
15
-24166826
# Output:
0
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    def solve(positive, A):
        total = 0
        ope = 0
        for i in range(len(A)):
            # print("####")
            # print(total)
            # print(ope)
            if positive:
                # 次は負の数=正の数になるなら補正
                if total + A[i] >= 0:
                    ope += total + A[i] + 1
                    total = total + A[i] - (total + A[i]) - 1
                else:
                    total += A[i]
            else:
                # 次は正の数=負の数になるなら補正
                if total + A[i] <= 0:
                    ope += abs(total + A[i]) + 1
                    total = total + A[i] + abs(total + A[i]) + 1
                else:
                    total += A[i]
            positive = (not positive)
        return ope
    
    print(min(solve(True, A), solve(False, A)))



if '__main__' == __name__:
    resolve()

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

def odd_positive(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
        elif (not i & 1) and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
    return cost


def odd_negative(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
        elif (not i & 1) and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
    return cost
    
ans = min(odd_positive(a), odd_negative(a)) 
print(ans)


# Example run
# Input:
-1131247330
-9
# 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:
>79\>
-41939
# Output:
0
n = int(input())

a = list(map(int,input().split()))
b = [i for i in a]


def solve(cnt,A,N):
    sumA=A[0]
    for i in range(1, N):
        if sumA>0:
            if sumA+A[i]>=0:
                r = A[i]
                A[i]=-sumA-1
                cnt+=abs(r-A[i])
        else:
            if sumA+A[i]<=0:
                r = A[i]
                A[i]=-sumA+1
                cnt+=abs(r-A[i])

        sumA+=A[i]
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)

print(min(ans1,ans2))


# Example run
# Input:
-331748
14563732
# Output:
0
import sys

sys.setrecursionlimit(2000000)

def re(r,k,l):
    if k==0:return r
    while(k<l[0]):
        l=l[1:]
    return re(r+1,k-l[0],l)





n=int(input())
i=1
l6=[]
ans=10**5
while(i<n):
    l6.append(i)
    i*=6
i=1
l9=[]
while(i<n):
    l9.append(i)
    i*=9
l6.sort(reverse=True)
l9.sort(reverse=True)
for i in range(n+1):
    ans=min(ans,re(0,n-i,l6)+re(0,i,l9))
print(ans)

# Example run
# Input:
-7517
# Output:
100000
def sign(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    else:
        return 0


n = int(input())
a = [int(i) for i in input().split()]
s = [sum(a[:i+1]) for i in range(n)]
sp = [s[i] for i in range(n)]
sm = [s[i] for i in range(n)]
P0=0
M0=0
if s[0]==0:
    P0+=1
    M0+=1
    for j in range(n):
        sp[j]+=1
        sm[j]+=1
elif s[0]>0:
    M0+=abs(s[0]+1)
    for j in range(n):
        sm[j]-=(abs(s[0])+1)
else:
    P0+=abs(s[0]+1)
    for j in range(n):
        sp[j]+=(abs(s[0])+1)
for i in range(1,n):
    if sm[i-1]*sm[i]>=0:
        M0+=abs(sm[i])+1
        h=sign(sm[i-1])*(-1)*(abs(sm[i])+1)
        for j in range(i,n):
            sm[j]+=h
    if sp[i-1]*sp[i]>=0:
        P0+=abs(sp[i])+1
        h=sign(sp[i-1])*(-1)*(abs(sp[i])+1)
        for j in range(i,n):
            sp[j]+=h
print(min([M0,P0]))


# Example run
# Input:
479
-21519471
# Output:
21520426
N = int(input())
A = [int(x) for x in input().split()]

if A[0] < 0:
	sumP = 1
	sumM = A[0]
	countP = -A[0] + 1
	countM = 0
elif A[0] == 0:
	sumP = 1
	sumM = -1
	countP = 1
	countM = 1
else:
	sumP = A[0]
	sumM = -1
	countP = 0
	countM = A[0] + 1

for i in range(1, N):
	if sumP > 0:
		if A[i] + sumP >= 0:
			countP += A[i] + sumP + 1
			sumP = -1
		else:
			sumP += A[i]
	else:
		if A[i] + sumP <= 0:
			countP += -(A[i] + sumP) + 1
			sumP = 1
		else:
			sumP += A[i]
	
	if sumM > 0:
		if A[i] + sumM >= 0:
			countM += A[i] + sumM + 1
			sumM = -1
		else:
			sumM += A[i]
	else:
		if A[i] + sumM <= 0:
			countM += -(A[i] + sumM) + 1
			sumM = 1
		else:
			sumM += A[i]

print(min(countP, countM))

# Example run
# Input:
-97071
36241
# Output:
0
n = int(input())
a_list = list(map(int,input().split()))

def count(sign):
    
    count = 0
    a_sum = 0
    for a in a_list:
        a_sum +=a
        if a_sum*sign <= 0: 
            ope = sign - a_sum
            a_sum += ope
            count += abs(ope)
        sign *= -1
    return count
print(min(count(1),count(-1)))


# Example run
# Input:
-802
363865392
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]
temp = 0
count1 = 0
count2 = 0

if a[0] == 0:
	a[0] = 1
	count1 = 1

sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
			count1 += abs(temp - a[i])
		else:
			temp = abs(sum) + 1
			count1 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

count2 = abs(a[0]) + 1
if a[0] > 0:
	a[0] = -1
else:
	a[0] = 1

sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		count2 += abs(sum - a[i]) + 1
		if sum > 0:
			temp = -1 * abs(sum) - 1
			count2 += abs(temp - a[i])
		else:
			temp = abs(sum) + 1
			count2 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


# Example run
# Input:
-7
-7737
# Output:
0
n=int(input())

X=list(map(int,input().split()))

res=X[0]
cnt=0

if X[0]==0:
    cnt+=1
    res=1

        
for i in range(1,n):
    res+=X[i]
    if res>=0 and res-X[i]>0:
        cnt+=(1+res)
        res=-1
    elif res<=0 and res-X[i]<0:
        cnt+=(1-res)
        res=1
    

print(cnt)

# Example run
# Input:
0
16
# Output:
0
n = int(input())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
ans = 0
ans_ = 0
count = 0
for i in range(1, n + 1):
    if i == 1:
        if a_t[i] >= 0:
            ans += a_t[i] + 1
            count += -(a_t[i]) - 1
    if a_t[i - 1] + count > 0:
        if a_t[i] + count > 0:
            ans += a_t[i] + count + 1
            count += -(a_t[i] + count) - 1
        if a_t[i] + count == 0:
            ans += 1
            count -= 1
    elif a_t[i - 1] + count < 0:
        if a_t[i] + count < 0:
            ans += -(a_t[i] + count) + 1
            count += -(a_t[i] + count) + 1
        if a_t[i] + count == 0:
            ans += 1
            count += 1
for i in range(1, n + 1):
    if i == 1:
        if a_t[i] <= 0:
            ans_ += a_t[i] + 1
            count += -(a_t[i]) - 1
    if a_t[i - 1] + count > 0:
        if a_t[i] + count > 0:
            ans_ += a_t[i] + count + 1
            count += -(a_t[i] + count) - 1
        if a_t[i] + count == 0:
            ans_ += 1
            count -= 1
    elif a_t[i - 1] + count < 0:
        if a_t[i] + count < 0:
            ans_ += -(a_t[i] + count) + 1
            count += -(a_t[i] + count) + 1
        if a_t[i] + count == 0:
            ans_ += 1
            count += 1
print(min(ans, ans_))

# Example run
# Input:
-1219978197
-1151131
# Output:
0
n = int( input())
A = list( map( int, input().split()))
ansp = 0
sums = A[0]
if sums == 0:
    ansp += 1
    sums += 1
for i in range(1,n):
    sums += A[i]
    if i%2 == 1:
        if sums < 0:
            pass
        else:
            ansp += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansp += abs(1 - sums)
            sums = 1
sums = A[0]
ansm = 0
if sums == 0:
    ansm += 1
    sums -= 1
for i in range(1,n):
    sums += A[i]
    if i%2 == 0:
        if sums < 0:
            pass
        else:
            ansm += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansm += abs(1 - sums)
            sums = 1
print( min(ansp, ansm))

# Example run
# Input:
-27621754
-68122564
# Output:
0
n = int(input())
a_list = list(map(int, input().split()))

total = 0
count = 0
pos_or_neg = True  # True = +, False = -

for a in a_list:
    total += a
    if pos_or_neg:
        if total <= 0:
            count += -total + 1
            total += -total + 1
        pos_or_neg = False

    else:
        if total >= 0:
            count += total + 1
            total -= total + 1
        pos_or_neg = True

first_count = count
count = 0
total = 0
pos_or_neg = False

for a in a_list:
    total += a
    if pos_or_neg:
        if total <= 0:
            count += -total + 1
            total += -total + 1
        pos_or_neg = False

    else:
        if total >= 0:
            count += total + 1
            total -= total + 1
        pos_or_neg = True

print(min(count, first_count))

# Example run
# Input:
-7467726
1372619017
# Output:
0
n = int(input())
a = list(map(int, input().split()))
def tat(t,a,n):
  ans = 0
  ssu = 0
  for x in a:
    ssu += x
    if ssu*t <= 0:
      ans += abs(ssu-t)
      ssu = t
    t *= -1
  return ans
print(min(tat(1,a,n),tat(-1,a,n)))

# Example run
# Input:
113
9879
# Output:
0
def solve(f, A):
    r, s = 0, 0
    for a in A:
        s += a
        if s == 0:
            r += 1
            s = f
        elif s * f < 0:
            r += -(s * f) + 1
            s = f
        f = -f
    return r

def main():
    N = int(input())
    A = list(map(int, input().split()))
    return min(solve(1, A), solve(-1, A))

print(main())


# Example run
# Input:
-299483
83
# Output:
0
n=int(input())
arr1=list(map(int,input().split()))
arr2=arr1[:]
ans1=0
ans2=0

if arr1[0]<=0:
    ans1+=abs(arr1[0])+1
    arr1[0]=1
if arr2[0]>=0:
    ans2+=arr2[0]+1
    arr2[0]=-1

sum1=arr1[0]
for i in range(1,n):
    tmp=sum1+arr1[i]
    if i%2==1:
        if tmp>=0:
            ans1+=tmp+1
            sum1=-1
        else:
            sum1=tmp
    else:
        if tmp<=0:
            ans1+=abs(tmp)+1
            sum1=1
        else:
            sum1=tmp
sum2=arr2[0]
for i in range(1,n):
    tmp=sum2+arr2[i]
    if i%2==0:
        if tmp>=0:
            ans2+=tmp+1
            sum2=-1
        else:
            sum2=tmp
    else:
        if tmp<=0:
            ans2+=abs(tmp)+1
            sum2=1
        else:
            sum2=tmp
print(min(ans1,ans2))

# Example run
# Input:
-20720
-1
# Output:
0
N = int(input())

A = list(map(int, input().split()))

S = [0] * (N+1)

for i in range(N):
  S[i+1] = S[i] + A[i]
print(S)
#S[1] > 0
ans1 = 0
work = 0
for i in range(1,N+1):
  if i%2 == 1:
    # pos is required
    if S[i] + work <= 0:
      temp = 1 - (S[i] + work)
      ans1 += temp
      work += temp
  else:
    # neg is required
    if S[i] + work >= 0:
      temp = (S[i] + work) + 1
      ans1 += temp
      work -= temp

#S[1] < 0
ans2 = 0
work = 0
for i in range(1,N+1):
  if i%2 == 1:
    # neg is required
    if S[i] + work >= 0:
      temp = (S[i] + work) + 1
      ans2 += temp
      work -= temp
  else:
    # neg is required
    if S[i] + work <= 0:
      temp = 1 - (S[i] + work)
      ans2 += temp
      work += temp

print(min(ans1, ans2))

# Example run
# Input:
-15860207
-54634663
# Output:
[]
0
N = int(input())
A = list(map(int,input().split()))

ans1 = c = 0
for i,a in enumerate(A):
    c += a
    if i%2:
        if c < 1:
            ans1 += 1-c
            c = 1
    else:
        if c > -1:
            ans1 += c+1
            c = -1

ans2 = c = 0
for i,a in enumerate(A):
    c += a
    if i%2==0:
        if c < 1:
            ans2 += 1-c
            c = 1
    else:
        if c > -1:
            ans2 += c+1
            c = -1

print(min(ans1,ans2))

# Example run
# Input:
-608
32371647
# Output:
0
def resolve(SL):
    # L[0]!=0を起点とする
    cnt = 0
    for i in range(len(SL)-1):
        s0 = SL[i]
        s1 = SL[i+1]
        if(s0>0 and s1>=0):
            SL[(i+1):] = [s-(s1+1) for s in SL[(i+1):]]
            cnt += (s1+1)
        elif(s0<0 and s1<=0):
            SL[(i+1):] = [s+(-s1+1) for s in SL[(i+1):]]
            cnt += (-s1+1)  
#         print(SL)
    return cnt
            
def ans(L):
  SL = [sum(L[:(i+1)]) for i in range(len(L))]
  c0,c1=0,0
  
  if (L[0]>0):
      c0 = resolve(SL)
      c1 = (L[0]+1) + resolve(list(map(lambda x:x-(L[0]+1), SL)))
  elif (L[0]<0):
      c0 = resolve(L)
      c1 = (-L[0]+1) + resolve(list(map(lambda x:x+(-L[0]+1), SL)))
  else:
      c0 = 1 + resolve(list(map(lambda x:x+1, SL)))
      c1 = 1 + resolve(list(map(lambda x:x-1, SL)))
  
  return(min(c0,c1))

N = int(input())
L = [int(x) for x in input().split(' ')]

print(ans(L))
  

# Example run
# Input:
363865392
-1377730
# 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 = neg_sum
	neg_modi = tmp_modi

print(min(pos_modi,neg_modi))

	



# Example run
# Input:
-20196
-809459
# Output:
0