Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())

a = list(int(i) for i in input().split())
b = []
for i in range(0,len(a)):
    b.append(a[i])


def solve(cnt,A,N):
    for i in range(1, N):
        if sum(A[0:i])>0:
            if sum(A[0:i+1])>=0:
                r = A[i]
                A[i]=-sum(A[0:i])-1
                cnt+=abs(r-A[i])
        else:
            if sum(A[0:i+1])<=0:
                r = A[i]
                A[i]=-sum(A[0:i])+1
                cnt+=abs(r-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:
0
3537
# Output:
0
n = int(input())
A = list(map(int,input().split()))
s1 = s2 =  0
#偶数番目までの和を正→ans1、奇数番目までの和を正→ans2
ans1 = ans2 = 0
#ans1について
for i in range(len(A)):
    s1 += A[i]
    if (i+1)%2==0:
        if s1>0:
            continue
        else:
            ans1+= abs(s1) + 1
            s1 = 1
    else:
        if s1<0:
            continue
        else:
            ans1 += abs(s1) +1
            s1 = -1
#ans2について
for i in range(len(A)):
    s2 += A[i]
    if (i+1)%2 == 0:
        if s2 <0:
            continue
        else:
            ans2 += abs(s2) + 1
            s2 = -1
    else:
        if s2 > 0:
            continue
        else:
            ans2 += abs(s2) + 1
            s2 = 1
print(min(ans1,ans2))

# Example run
# Input:
-740
1
# Output:
0
N = int(input())
*A, = map(int, input().split())
ans1 = 0
sum1 = 0
for i, a in enumerate(A):
    sum1 += a
    if i % 2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
    elif i % 2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
ans2 = 0
sum2 = 0
for i, a in enumerate(A):
    sum2 += a
    if i % 2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
    elif i % 2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
print(min(ans1, ans2))

# Example run
# Input:
23
493
# Output:
0
N = int(input())
A = tuple(map(int,input().split()))

def solve(f):
    acc = 0
    cnt = 0
    for a in A:
        acc += a
        if f and acc <= 0:
            cnt += 1 - acc
            acc = 1
        elif not f and acc >= 0:
            cnt += acc + 1
            acc = -1
        f = not f
    return cnt

print(min(solve(True),solve(False)))

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

idx=0
ans=0
sum_last=0

for i in a:
    if i!=0:
        break
    idx+=1

ans=idx
if idx==len(a):
    pass
elif idx>0:
    if a[idx]>0:
        sum_last=-1
    else:
        sum_last=1
else:
    sum_last=a[0]
    idx+=1

for i in a[idx:]:
    sum_cur=sum_last+i
    if sum_cur*sum_last>=0:
        ans+=abs(sum_cur)+1
        if sum_last>0:
            sum_last=-1
        else:
            sum_last=1
    else:
        sum_last=sum_cur
print(ans)

# Example run
# Input:
1115599
-206075
# Output:
0
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

    ans = 0

    cumulative = 0
    count = 0
    for i in range(len(a)):
        cumulative += a[i]
        if i % 2 == 0: # positive
            if cumulative <= 0:
                count += abs(cumulative) + 1
                cumulative -= (abs(cumulative) + 1)
        else:  # negative
            if cumulative >= 0:
                count += abs(cumulative) + 1
                cumulative += (abs(cumulative) + 1)
    ans = max(ans, count)

    cumulative = 0
    count = 0
    for i in range(len(a)):
        cumulative += a[i]
        if i % 2 == 0: # negative
            if cumulative >= 0:
                count += abs(cumulative) + 1
                cumulative -= (abs(cumulative) + 1)
        else:  # positive
            if cumulative <= 0:
                count += abs(cumulative) + 1
                cumulative -= (abs(cumulative) + 1)

    ans = max(ans, count)
    print(ans)

if __name__ == '__main__':
    main()


# Example run
# Input:
20415230
-21
# Output:
22
N = int(input())
A = [int(_) for _ in input().split()]
now = 0
cnt = 0
for i, a in enumerate(A):
    b = (-1)**i
    now += a
    if now * b <= 0:
        cnt += abs(now - b)
        now = b
ans = cnt
now = 0
cnt = 0
for i, a in enumerate(A):
    b = (-1)**(i + 1)
    now += a
    if now * b <= 0:
        cnt += abs(now - b)
        now = b
ans = min(ans, cnt)
print(ans)


# Example run
# Input:
-247
-12142
# Output:
0
n = int(input())
a = list(map(int,input().split()))
s = []
for i in range(n):
    s.append(sum(a[0:i+1]))

count = 0
ans1 = 0
for i in range(n):
    if i%2 == 0:
        if s[i]+count > 0:
            continue
        else:
            ans1 += 1-(s[i]+count)
            count += 1-(s[i]+count)
    else:
        if s[i]+count < 0:
            continue
        else:
            ans1 += (s[i]+count) + 1
            count -= (s[i]+count) + 1
            
count1 = 0
ans2 = 0
for i in range(n):
    if i%2 == 1:
        if s[i]+count1 > 0:
            continue
        else:
            ans2 += 1-(s[i]+count1)
            count1 += 1-(s[i]+count1)
    else:
        if s[i]+count1 < 0:
            continue
        else:
            ans2 += (s[i]+count1) + 1
            count1 -= (s[i]+count1) + 1
            
print(min(ans1,ans2))
            

# Example run
# Input:
-6126
-5
# Output:
0
n = int(input())
num_list = list(map(int, input().split()))
count = 0
sum_ = num_list[0]
if sum_ > 0:
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 0:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count1 = count
    
    count = 0
    sum_ = -1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 1:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count2 = count + num_list[0] + 1
    
    print(min(count1, count2))
elif sum_ < 0:
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 1:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count1 = count
    
    count = 0
    sum_ = 1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 0:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count2 = count + abs(num_list[0]) + 1
    
    print(min(count1, count2))
    
else:
    sum_ = -1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 1:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count1 = count + 1
    
    count = 0
    sum_ = 1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 0:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1
                sum_ = -1
    count2 = count + 1    

    print(min(count1, count2))

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

def calc(s,number,sign):
    if sign:
        if s+number>0:
            return (s+number,0,sign^1)
        else:
            return (1,1-s-number,sign^1)
    else:
        if s+number<0:
            return (s+number,0,sign^1)
        else:
            return (-1,s+number+1,sign^1)
signPlus=1
ansP = 0
s = 0
for number in a:
    s,d,signPlus=calc(s,number,signPlus)
    ansP+=d
signPlus=0
ansM = 0
s = 0
for number in a:
    s,d,signPlus=calc(s,number,signPlus)
    ansM+=d
print(min(ansP,ansM))

# Example run
# Input:
-18758
470
# Output:
0
n=int(input())
a=list(map(int,input().split()))
import sys
sum=0
cnt=0
# 奇数+
for i in range(n):
    z=sum+a[i]
    if i%2==0:
        if z<0:
            sum=z
        else:
            sum=-1
            cnt+=(z+1)
    else:
        if z>0:
            sum=z
        else:
            sum=1
            cnt+=(1-z)
cnt_sbst=cnt
# 奇数-
for i in range(n):
    z=sum+a[i]
    if i%2==1:
        if z<0:
            sum=z
        else:
            sum=-1
            cnt+=(z+1)
    else:
        if z>0:
            sum=z
        else:
            sum=1
            cnt+=(1-z)
cnt_plus=cnt
ans=min(cnt_plus,cnt_sbst)
print(ans)




# Example run
# Input:
-7467726
1372619017
# Output:
0
n = int(input())

numbers = list(map(int, input().split()))
counter = 0
sum_in = 0
sum_in1 = numbers[0]
key = numbers[0]

if key >= 0:
    for i in range(len(numbers)):
        sum_in += numbers[i]
        if i % 2 == 0:
            if sum_in <= 0:
                sub = abs(sum_in) + 1
                sum_in += sub
                numbers[i] += sub
                counter += sub
        else:
            if sum_in >= 0:
                sub = abs(sum_in) + 1
                sum_in -= sub
                numbers[i] -= sub
                counter += sub

else:
    for i in range(len(numbers)):
        sum_in += numbers[i]

        if i % 2 != 0:
            if sum_in <= 0:
                sub = abs(sum_in) + 1
                sum_in += sub
                numbers[i] += sub
                counter += sub
        else:
            if sum_in >= 0:
                sub = abs(sum_in) + 1
                sum_in -= sub
                numbers[i] -= sub
                counter += sub

print(counter)

# Example run
# Input:
-2314351
3986
# Output:
0
n = int(input())
A = list(map(int, input().split()))

ans1 = 0
sum = A[0]
for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        fugo = sum // abs(sum)
        nextsum = - fugo
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum += a_should_be
        ans1 += dif

print(ans1)

ans2 = A[0] + 1
sum = - (A[0] // abs(A[0]))

for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        fugo = sum // abs(sum)
        nextsum = - fugo
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum += a_should_be
        ans2 += dif
        
print(ans2) 
#A[0]を反転したほうがいいパターンの処理

# Example run
# Input:
805965556
-19
# Output:
0
-18
import math

n = int(input())
ai = tuple(map(int, input().split()))

kisuu = 0.0
guusuu = 0.0
for i, a in enumerate(ai):
    if i % 2:
        kisuu += a
    else:
        guusuu += a
kisuu /= math.floor(n / 2)
guusuu /= n - math.floor(n / 2)

if kisuu > guusuu:
    kisuu = True
    guusuu = False
else:
    kisuu = False
    guusuu = True

sum = 0
ans = 0
for i, a in enumerate(ai):
    sum += a
    if i % 2:
        if kisuu:
            if sum <= 0:
                ans += 1 - sum
                sum = 1
        else:
            if sum >= 0:
                ans += 1 + sum
                sum = -1
    else:
        if guusuu:
            if sum <= 0:
                ans += 1 - sum
                sum = 1
        else:
            if sum >= 0:
                ans += 1 + sum
                sum = -1
    print(sum)
print (ans)

# Example run
# Input:
10366
-5271130
# Output:
-5271130
0
N = int(input())
nums = list(map(int, input().split()))
sum_n = 0
before = 0
ans = 10*14
for n in [-1, 1]:
  cnt = 0
  before = n
  sum_n = nums[0]
  if sum_n * before >= 0:
    if before > 0:
      sum_n = -1
    else:
      sum_n = 1
    cnt += abs(sum_n - before)
  before = sum_n
  for num in nums[1:]:
    sum_n += num
    if before * sum_n >= 0:
      if before > 0:
        cnt += abs(-1-sum_n)
        sum_n = -1
      else:
        cnt += abs(1-sum_n)
        sum_n = 1
    before = sum_n
  ans = min(ans, cnt)
print(ans)


# Example run
# Input:
-84521052
-2
# Output:
0
n = int(input())
a = list(map(int, input().split()))
ans=0
if a[0]==0:
    a[0]+=1
    ans+=1
t=a[0]
if a[0]>0:
    for i in range(1,n):
        t+=a[i]
        if i%2==1:
            if t>=0:
                ans+=abs(t+1)
                t=-1
        else:
            if t<=0:
                ans+=abs(t-1)
                t=1
else:
    for i in range(1,n):
        t+=a[i]
        if i%2==1:
            if t<=0:
                ans+=abs(t-1)
                t=1
        else:
            if t>=0:
                ans+=abs(t+1)
                t=-1
print(ans)


# Example run
# Input:
-73864104
56
# Output:
0
# coding: utf-8
# Your code here!
n = int(input())
a = list(map(int,input().split()))
def operate(ls,x):
    sm = 0
    ans = 0
    ans += abs(ls[0]-x)
    k = x
    for i in range(1,len(ls)):
        sm += k
        if sm > 0:
            if abs(ls[i]) <= sm or sm < ls[i]:
                ans += abs(ls[i]+sm+1)
                k = -sm-1
            else:
                k = ls[i]
        if sm < 0:
            if abs(ls[i]) <= abs(sm) or sm > ls[i]:
                ans += abs(-sm+1-ls[i])
                k = -sm+1
            else:
                k = ls[i]
    return ans

anstot = []
if a[0] > 0:
    inv = -1
if a[0] < 0:
    inv = 1
if a[0] != 0:
    anstot.append(operate(a,a[0]))
    anstot.append(operate(a,inv))
if a[0] == 0:
    a[0] = 1
    anstot.append(1+operate(a,1))
    anstot.append(1+operate(a,-1))    
print(min(anstot))

# Example run
# Input:
-84
65962648
# Output:
0
n = int(input())
a = list(map(int,input().split()))
ans=10**15
for i in [1,-1]:
    b=0
    c=0
    for j in a:
        b+=j
        if b*i<=0:
            c+=abs(b-i)
            b=i
        i*=-1
    ans=min(ans,c)
print(ans)

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

def Cost(a, Sum):
    if Sum > 0:
        if Sum + a < 0:
            return 0
        else:
            return abs(Sum + a) + 1
    if Sum < 0:
        if Sum + a > 0:
            return 0
        else:
            return abs(Sum + a) + 1

Sum = lambda a, preSum:preSum + a if Cost(a, preSum) == 0 else (-1)**int(preSum > 0)

pCost = Cost(A[0],-1) -1
pSum = (lambda:A[0] if A[0] > 0 else 1)()
nCost = Cost(A[0],1) -1
nSum = (lambda:A[0] if A[0] < 0 else -1)()
for a in A[1:]:
    pCost += Cost(a, pSum)
    pSum = Sum(a, pSum)
    nCost += Cost(a, nSum)
    nSum = Sum(a, nSum)
print(min(pCost, nCost))


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

def check(f):
        flag = f 
        t = 0 
        c = 0 
        for i in range(n):
                if t + a[i] <= 0 and flag == 1:
                        c += 1 - t - a[i]
                        t = 1 
                elif t + a[i] >= 0 and flag == -1: 
                        c += 1 + t + a[i]
                        t = -1
                else:
                        t += a[i] 
                flag *= -1
                print(t)
        return c 
    
total_p = check(1)
total_m = check(-1)
print(min(total_p, total_m))

# Example run
# Input:
-57594492
-2243514
# Output:
0
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math

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

def main(c,temp):

    if temp>0:
        flag=1
    elif temp<0:
        flag=0
    for i in range(1,n):
        temp+=A[i]
        if flag:
            if temp>=0:
                c+=temp-(-1)
                temp=-1
            flag=0
        else:
            if temp<=0:
                c+=1-temp
                temp=1
            flag=1
    return(c)

temp=A[0]
if temp:
    a=main(0,temp)
    if temp>0:
        b=main(temp - (-1),-1)
    else:
        b=main(1-temp,1)
    print(min(a,b))
else:
    temp=1
    a=main(1,temp)
    temp=-1
    b=main(1,temp)
    print(min(a,b))


# Example run
# Input:
-3339504
3556893
# Output:
0
N = int(input())
nums = list(map(int, input().split()))
ans = 10**5+1
for start in [-1, 1]:
  before = start
  cnt = 0
  sum_n = 0
  for num in nums:
    sum_n += num
    if before*sum_n >= 0:
      if before < 0:
        cnt += abs(1-sum_n)
        sum_n = 1
      else:
        cnt += abs(-1-sum_n)
        sum_n = -1
    before = sum_n
  ans = min(ans, cnt)
print(ans)


# Example run
# Input:
-18086578
60
# Output:
0
import copy

n=int(input())
a=[int(x) for x in input().rstrip().split()]
ac=copy.deepcopy(a)

now=0
ans1=0
for i in range(n):
  now+=a[i]
  if i%2==0:
    if now<=0:
      ans1+=abs(now)+1
      now=1
  else:
    if 0<=now:
      ans1+=abs(now)+1
      now=-1

now=0
ans2=0
for i in range(n):
  now+=a[i]
  if i%2==0:
    if 0<=now:
      ans2+=abs(now)+1
      now=-1
  else:
    if now<=0:
      ans2+=abs(now)+1
      now=1
print(min(ans1,ans2))

# Example run
# Input:
-224960337
446
# Output:
0
n = int(input())
al = list(map(int, input().split())) 


ans1 = 0
curr_sum = 0
next_sign = 1
for a in al:
    next_sum = curr_sum + a
    if next_sum >= 0 and next_sign == -1: 
        ans1 += next_sum+1
        next_sum = -1
    elif next_sum <= 0 and next_sign == 1:
        ans1 += (1-next_sum)
        next_sum = 1
    curr_sum = next_sum
    next_sign *= -1


ans2 = 0
curr_sum = 0
next_sign = -1
for a in al:
    next_sum = curr_sum + a
    if next_sum >= 0 and next_sign == -1: 
        ans2 += next_sum+1
        next_sum = -1
    elif next_sum <= 0 and next_sign == 1:
        ans2 += (1-next_sum)
        next_sum = 1
    curr_sum = next_sum
    next_sign *= -1

print(min(ans1,ans2))

# Example run
# Input:
-240192
0
# Output:
1
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)  
    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(SL)
        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:
-75
57223618
# Output:
0
n = int(input())
a = list([int(i) for i in input().split()])
sum_a = []
count = 0

sum_a.append(a[0])
if len(a) != 1:
    if sum_a[0] == 0:
        count += 1
        if a[1] > 0:
            sum_a[0] = -1
        else:
            sum_a[0] = 1
else:
    if sum_a[0] == 0:
        count += 1
for i in range(1,n):
    sum_a.append(sum_a[i-1] + a[i])

    if sum_a[i] == 0:
        if sum_a[i-1] < 0:
            sum_a[i] += 1
            count += 1
        else:
            sum_a[i] -= 1
            count += 1
    elif sum_a[i-1] * sum_a[i] > 0:
        if sum_a[i] > 0:
            sum_a[i] = -1
            count += 1 + abs(sum_a[i-1]+a[i])
        else:
            sum_a[i] = 1
            count += 1 + abs(sum_a[i-1]+a[i])
print(count)

# Example run
# Input:
-831
110
# Output:
0
# -*- coding: utf-8 -*-
N = int(input())
a = [int(n) for n in input().split()]

count_a = 0
count_b = 0

nowsum = a[0]
if nowsum != 0:
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]
    print(count_a)

else:
    a[0] = 1
    count_a += 1
    nowsum = 1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]
    
    a[0] = -1
    count_b += 1
    nowsum = -1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_b += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]   
    print(min(count_a, count_b))

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

s = a[0]
count = 0
total_delta = 0
delta = 0

if a[0] == 0:
    i = 0
    while i < len(a):
        if a[i] != 0:
            break
        i += 1
    if i == len(a):
        delta = 1
        total_delta += delta
        count += 1
    else:
        delta = -1 * (a[i] // abs(a[i])) * ((1, -1)[(i + 1) % 2])
        total_delta += delta
        count += 1
for i in range(1, n):
    print('loop : ', i )
    print(s)
    sign = (s + total_delta) // abs(s + total_delta)
    if (s + a[i] + total_delta) * sign > 0 :
        delta  = (sign * -1) - (s + a[i] + total_delta)
        total_delta += delta
        count += abs(delta)
    elif (s + a[i] + total_delta) == 0:
        total_delta += sign * -1
        count += 1
    s += a[i]
print(count)




# Example run
# Input:
-224484380
171476207
# Output:
0
from itertools import accumulate

n = int(input())
lst = [int(x) for x in input().split()]
acm = list(accumulate(lst))

ret1 = 0
tmp = 0
for i, x in enumerate(acm):
    y = abs(x) + 1
    if i % 2 == 0:
        if x + tmp <= 0:
            ret1 += (x + tmp) * -1 + 1
            tmp += y
    elif i % 2 == 1:
        if x + tmp >= 0:
            ret1 += (x + tmp) + 1
            tmp -= y

ret2 = 0
tmp = 0
for i, x in enumerate(acm):
    y = abs(x) + 1
    if i % 2 == 0:
        if x + tmp >= 0:
            ret2 += (x + tmp) + 1
            tmp -= y
    elif i % 2 == 1:
        if x + tmp <= 0:
            ret2 += (x + tmp) * -1 + 1
            tmp += y

print(min(ret1, ret2))


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

even_is_negative = 0
odd_is_nagative = 0

for i in range(n):
    if i % 2 == 0 and a[i] < 0:
        even_is_negative += 1
    elif i % 2 == 1 and a[i] < 0:
        odd_is_nagative += 1

# print(even_is_negative)
# print(odd_is_nagative)

sum = a[0]
change = 0

if even_is_negative >= odd_is_nagative:
    for i in range(1, n):
        if i % 2 == 1 and sum + a[i] <= 0:
            change += abs(sum + a[i]) + 1
            sum = 1
            # print("a " + str(sum))
        elif i % 2 == 0 and sum + a[i] >= 0:
            change += sum + abs(a[i]) + 1
            sum = -1
            # print("b " + str(sum))
        else:
            sum += a[i]
            # print("c " + str(sum))

if even_is_negative < odd_is_nagative:
    for i in range(1, n):
        if i % 2 == 1 and sum + a[i] >= 0:
            change += sum + abs(a[i]) + 1
            sum = -1
            # print("a " + str(sum) + str(change))
        elif i % 2 == 0 and sum + a[i] <= 0:
            change += abs(sum + a[i]) + 1
            sum = 1
            # print("b " + str(sum)+ str(change))
        else:
            sum += a[i]
            # print("c " + str(sum)+ str(change))

if sum == 0:
    print(change + 1)
else:
    print(change)
             

# Example run
# Input:
-16371
-52564348
# Output:
0
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    x = sum(A) + a[i+1]
    if sum(A) > 0 and x > 0:
        y = abs(x)+1
        cnt += y
        a[i+1] -= y

    elif sum(A) < 0 and x < 0:
        y = abs(sum(A) - a[i+1])-1
        cnt += y
        a[i+1] += y

if sum(a) == 0:
    cnt += 1

print(cnt)

# Example run
# Input:
-56661351
981571
# Output:
0