Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n=int(input())
arr=list(map(int,input().split()))
ans=0
lsum=arr[0]
if arr[0]>0:
  for i in range(1,n):
    if i%2==1:
      if arr[i]<-lsum:
        lsum+=arr[i]
      else:
        ans+=(abs(lsum)+1)+arr[i]
        lsum=-1
    else:
      if abs(lsum)<arr[i]:
        lsum+=arr[i]
      else:
        ans+=(abs(lsum)+1)-arr[i]
        lsum=1
elif arr[0]<0:
  for i in range(1,n):
    if i%2==0:
      if arr[i]<-lsum:
        lsum+=arr[i]
      else:
        ans+=(abs(lsum)+1)+arr[i]
        lsum=-1
    else:
      if abs(lsum)<arr[i]:
        lsum+=arr[i]
      else:
        ans+=(abs(lsum)+1)-arr[i]
        lsum=1
else:
  ans1=1
  ans2=1
  lsum=1
  for i in range(1,n):
    if i%2==1:
      if arr[i]<-lsum:
        lsum+=arr[i]
      else:
        ans1+=(abs(lsum)+1)+arr[i]
        lsum=-1
    else:
      if abs(lsum)<arr[i]:
        lsum+=arr[i]
      else:
        ans1+=(abs(lsum)+1)-arr[i]
        lsum=1
  lsum=-1
  for i in range(1,n):
    if i%2==1:
      if arr[i]<-lsum:
        lsum+=arr[i]
      else:
        ans2+=(abs(lsum)+1)+arr[i]
        lsum=-1
    else:
      if abs(lsum)<arr[i]:
        lsum+=arr[i]
      else:
        ans2+=(abs(lsum)+1)-arr[i]
        lsum=1
  ans=min(ans1,ans2)
print(ans)

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

if a[0] == 0:
    a[0] += 1
    ans += 1
elif a[0] < 0:
    a = list(map(lambda x: x * (-1), a))

product = a[0]

for i in range(1, n):
    product += a[i]

    if i % 2 == 0:
        if product <= 0:
            ans += abs(product) + 1
            product = 1

    elif i % 2 == 1:
        if product >= 0:
            ans += abs(product) + 1
            product = -1

print(ans)


# Example run
# Input:
-813
-14382676
# Output:
0
input()
l=list(map(int,input().split()))
def f(s):
  c=t=0
  for i in l:
    t+=i
    if s*t<=0: c+=abs(t-s); t=s
    s*=-1
  return c
print(min(f(1),f(-1)))

# Example run
# Input:
#("Ua
463887247
# Output:
0
n = int(input())
A = list(map(int, input().split()))

A_csum = [0] * n
Sum = 0
for i in range(n):
    Sum += A[i]
    A_csum[i] = Sum

pat1 = 0
next_sign = 1
now = 0
for i in range(n):
    if (A_csum[i]+now) * next_sign <= 0:
        diff = next_sign-(A_csum[i]+now)
        pat1 += abs(diff)
        now += diff
    else:
        pass
    next_sign *= -1
    
pat2 = 0
next_sign = -1
now = 0
for i in range(n):
    if (A_csum[i]+now) * next_sign <= 0:
        diff = next_sign-(A_csum[i]+now)
        pat2 += abs(diff)
        now += diff
    else:
        pass
    next_sign *= -1

print(min(pat1,pat2))
    


# Example run
# Input:
-497
-15860207
# 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)

    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:
-496
-4
# Output:
5
n=int(input())
A=list(map(int,input().split()))
a,memo1,memo2=A[0],0,0
if a<0:
    memo1+=1-a
    a=1
for i in range(2,n):
    if a*(a+A[i])<=-1:a=a+A[i]
    else:
        memo1+=abs(a+A[i])+1
        if a>=1:a=-1
        else:a=-1
if a>0:
    memo2+=a+1
    a=-1
for i in range(2,n):
    if a*(a+A[i])<=-1:a=a+A[i]
    else:
        memo2+=abs(a+A[i])+1
        if a>=1:a=-1
        else:a=-1
print(min(memo1,memo2))

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

pos = 0
P = [0] * n
if A[0] > 0:
    P[0] = A[0]
else:
    P[0] = 1
    pos += 1 - A[0]
for i in range(1, n):
    P[i] = P[i - 1] + A[i]
    if i % 2 == 0 and P[i] <= 0:
        pos += 1 - P[i]
        P[i] = 1
    elif i % 2 == 1 and P[i] >= 0:
        pos += 1 + P[i]
        P[i] = -1

neg = 0
N = [0] * n
if A[0] < 0:
    N[0] = A[0]
else:
    N[0] = -1
    neg += 1 + A[0]
for i in range(1, n):
    N[i] = N[i - 1] + A[i]
    if i % 2 == 0 and N[i] >= 0:
        neg += 1 + N[i]
        N[i] = -1
    elif i % 2 == 1 and N[i] <= 0:
        neg += 1 - N[i]
        N[i] = 1

print(min(pos, neg))


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

res = 10 ** 100

def f(fir):
    prv_pos = fir > 0
    margin = fir - a[0]
    ret = abs(margin)
    for i in range(1, n):
        cur = margin + acc[i]
        if prv_pos and cur < 0:
            prv_pos = not prv_pos
            continue
        if not prv_pos and cur > 0:
            prv_pos = not prv_pos
            continue
        if prv_pos:
            need = -1
            sa = need - cur
            margin += sa
            ret += abs(sa)
        else:
            need = 1
            sa = need - cur
            margin += sa
            ret += abs(sa)
        prv_pos = not prv_pos
    return ret


res = min(res, f(1))
res = min(res, f(-1))
if a[0] != 0:
    res = min(res, f(a[0]))
print(res)


# Example run
# Input:
-31
-58867430
# Output:
0
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0

for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count1 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count1 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count1 += 1
        currentSum = -1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count2 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count2 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count2 += 1
        currentSum = 1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count3 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] <= 0 and restSum == 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
        
currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count4 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] >= 0 and restSum == 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
        
print(count1, count2, count3, count4)


# Example run
# Input:
-579377
-21
# Output:
0 0 0 0
# 最初はa[0]がプラス、マイナスで場合分けしていたが、それだと最小にならない可能性があるため
# 偶数番目の和をプラス、奇数番目の和をプラスにする場合をやって最小になるほうを結果として出す

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

cnt = [0,0]

for i in [0,1]:
    tmp_sum = 0
    for index, value in enumerate(a):
        tmp_sum += value
        if (i + index) % 2 == 0:
            if tmp_sum <= 0:
                cnt[i] += abs(tmp_sum) + 1
                tmp_sum += abs(tmp_sum) + 1
        else:
            if tmp_sum >= 0:
                cnt[i] += tmp_sum + 1
                tmp_sum -= tmp_sum + 1


print(min(cnt))

# Example run
# Input:
-88464090
-1136688451
# 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 a[i-1]>0:
                    sum=-1
                    cnt+=1
                elif a[i-1]<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
    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 a[i-1]>0:
                    sum=-1
                    cnt+=1
                elif a[i-1]<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
    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 a[i-1]>0:
                sum=-1
                cnt+=1
            elif a[i-1]<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
print(cnt)

# 6
# 0 0 -1 3 5 0





# Example run
# Input:
-1893070
10823
# Output:
0
n = int(input())
a = list(int(i) for i in input().split())  
ctplus = 0
ctminu = 0
checksum = 0
for i in range(n):
  checksum += a[i]
  if i%2 ==0:
    if checksum <= 0:
      ctplus += abs(checksum)+1
      checksum += abs(checksum)+1
  else:
    if checksum >= 0:
      ctplus += abs(checksum)+1
      checksum -= (abs(checksum)+1)
checksum = 0
for j in range(n):
  checksum += a[j]
  if j%2 ==1:
    if checksum <= 0:
      ctminu += abs(checksum)+1
      checksum += abs(checksum)+1
  else:
    if checksum >= 0:
      ctminu += abs(checksum)+1
      checksum -= (abs(checksum)+1)      
print(min(ctplus,ctminu))

# Example run
# Input:
-9486
-1394868732
# Output:
0
n=int(input())
arr=list(map(int,input().split()))
ans1=0
ans2=0
if arr[0]>0:
  lsum=arr[0]
else:
  lsum=1
  ans1+=1-arr[0]
for i in range(1,n):
  if i%2==1:
    if arr[i]<-lsum:
      lsum+=arr[i]
    else:
      ans1+=(abs(lsum)+1)+arr[i]
      lsum=-1
  else:
    if abs(lsum)<arr[i]:
      lsum+=arr[i]
    else:
      ans1+=(abs(lsum)+1)-arr[i]
      lsum=1
if arr[0]<0:
  lsum=arr[0]
else:
  ans2+=arr[0]+1
  lsum=-1
for i in range(1,n):
  if i%2==0:
    if arr[i]<-lsum:
      lsum+=arr[i]
    else:
      ans2+=(abs(lsum)+1)+arr[i]
      lsum=-1
  else:
    if abs(lsum)<arr[i]:
      lsum+=arr[i]
    else:
      ans2+=(abs(lsum)+1)-arr[i]
      lsum=1
ans=min(ans1,ans2)
print(ans)

# Example run
# Input:
-2556
-80246
# Output:
0
def solve():

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

    b = [a[i] for i in range(n)]

   # print(a)
   # print(b)

    #Even
    sum_e = 0
    ans_e = 0

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

    #Odd
    sum_o = 0
    ans_o = 0

    for i in range(n):
        sum_o += b[i]
        if i%2 == 1:
            if sum_o <= 0:
                ans_o += abs(sum_o) + 1
                sum_o += abs(sum_o) + 1
        else:
            if sum_o >= 0:
                ans_o += abs(sum_o) + 1
                sum_o -= abs(sum_o) + 1

    if ans_o <= ans_e:
        ans = ans_o
    else:
        ans = ans_e


    print(ans)

if __name__ ==  "__main__":
    solve()


# Example run
# Input:
-74270783
2147483647
# Output:
0
n=int(input())
lista=list(map(int,input().split()))
updown=""
goukei=0
count=0
if lista[0]<0:
    updown="up"
else:
    updown="down"
goukei=goukei+lista[0]
print(goukei,count,updown)
for i in range(1,n):
    if updown=="down":
        if lista[i]+goukei<0:
            goukei+=lista[i]
            updown="up"
            print(goukei,count,updown)
        elif lista[i]+goukei>0:
            count=count+abs(lista[i]+goukei)+1
            goukei=-1
            down="up"
            print(goukei,count,updown)
            
    elif updown=="up":
        if lista[i]+goukei>0:
            goukei+=lista[i]
            updown="down"
            print(goukei,count,updown)
            
        elif lista[i]+goukei<0:
            count=count+abs(lista[i]+goukei)+1
            goukei=1
            updown="down"
            print(goukei,count,updown)    
print(count)

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

result = []

for i in range(1):
    num = 0
    r = 0
    for j in range(len(a)):
        num += a[j]
        if (j + i) % 2 == 0:
            if num <= 0:
                r -= num - 1
                num = 1

        else:
            if num >= 0:
                r += num + 1
                num = -1

    result.append(r)

print(min(result))


# Example run
# Input:
-84564737
-18579092
# Output:
18579093
n = int(input())
l = list(map(int, input().split()))
last_sum = l[0]
ans_l = []
for j in range(2):
    ans = 0
    if j == 0:
        if last_sum <= 0:
            ans += 1 - last_sum
            last_sum += 1 - last_sum
    else:
        if last_sum >= 0:
            ans += -1 - last_sum
            last_sum += -1 - last_sum
    for i in range(n - 1):
        # print(last_sum)
        if last_sum > 0:
            if last_sum + l[i + 1] < 0:
                last_sum += l[i + 1]
            else:
                a = -1 - last_sum - l[i + 1]
                ans += abs(a)
                last_sum += a + l[i + 1]
        else:
            if last_sum + l[i + 1] > 0:
                last_sum += l[i + 1]
            else:
                a = 1 - last_sum - l[i + 1]
                ans += abs(a)
                last_sum += a + l[i + 1]
    ans_l.append(ans)
print(min(ans_l))


# Example run
# Input:
-18579092
21643
# Output:
-21644
N = int(input())
a =list(map(int,input().split()))
a1=[0]*N
a2=[0]*N

s1 =a[0]
s2 =a[0]
#正の数から始まるパターン
c1 = 0
if s1 ==0:
    s1 = 1
    c1 = 1
elif s1 <0:
    a1[0]=1
    c1 = -s1+1

for i in range(1,N):
    if s1*(s1+a[i])>=0 and s1>0:
        a1[i] = -(s1+1)
        c1 +=a[i]-a1[i]
    elif s1*(s1+a[i])>=0 and s1<0:
        a1[i] = -s1+1
        c1 +=a1[i]-a[i]
    else:
        a1[i]=a[i]
    s1 = s1+a1[i]
#負の数から始まるパターン

c2=0
if s2 ==0:
    s2 = 1
    c2 =1
elif s2 >0:
    a2[0]=-1
    c2 = s2+1
    
for i in range(1,N):
    if s2*(s2+a[i])>=0 and s2>0:
        a2[i] = -(s2+1)
        c2 +=a[i]-a2[i]
    elif s2*(s2+a[i])>=0 and s2<0:
        a2[i] = -s2+1
        c2 +=a2[i]-a[i]
    else:
        a2[i]=a[i]
    s2 = s2+a2[i]    
    


print(min(c1,c2))

# Example run
# Input:
-14
0
# Output:
1
N = int( input())
A = list( map( int, input().split()))
ans = 10**15
for i in [1, -1]:
    ansi, sums = 0, 0
    for a in A:
        sums += a
        if sums*i <= 0:
            ansi += abs(sums-i)
            sums = i
        i *= -1
    ans = min( ans, ansi)
print(ans)

# Example run
# Input:
-242313086
10823
# Output:
0
n = int(input())
a = list(map(int,input().split()))
num = a[0]
ans = 0
if a[0]>0:
    for i in range(1,n):
        num += a[i]
        if i%2==1:
            if num>=0:
                ans += num+1
                num = -1
        else:
            if num<=0:
                ans += 1-num
                num = 1
elif a[0]<0:
    for i in range(1,n):
        num += a[i]
        if i%2==1:
            if num <= 0:
                ans += 1-num
                num = 1
        else:
            if num >= 0:
                ans += num+1
                num = -1
else:
    num = 0
    ansp = 1
    ansm = 1
    for i in range(1,n):
        num += a[i]
        if i%2==1:
            if num>=0:
                ansp += num+1
                num = -1
        else:
            if num<=0:
                ansp += 1-num
                num = 1
    for i in range(1,n):
        num += a[i]
        if i%2==1:
            if num <= 0:
                ansm += 1-num
                num = 1
        else:
            if num >= 0:
                ansm += num+1
                num = -1
    ans = min(ansp,ansm)
print(ans)

# Example run
# Input:
-22328
-489
# Output:
0
from itertools import accumulate
import copy

def sol(acmA, sign=1):
  add = 0
  ans = 0
  sumA = acmA[0]
  for i in range(1,N):
    acmA[i] += add
    if sign == 1:
      if (i%2==0 and acmA[i-1]<0 and 0<acmA[i]) or (i%2==1 and 0<acmA[i-1] and acmA[i]<0) :continue
    else:
      if (i%2==1 and acmA[i-1]<0 and 0<acmA[i]) or (i%2==0 and 0<acmA[i-1] and acmA[i]<0) :continue
  
    tmp_add = -acmA[i]-1 if acmA[i] > 0 else -acmA[i]+1
    #print(i, tmp_add, acmA[i])
    acmA[i] += tmp_add
    sumA += acmA[i]
    add +=  tmp_add
    ans +=abs(tmp_add)
  if sumA == 0: return ans +1
  else: return ans

N = int(input())
A = list(map(int,input().split()))
acmA = list(accumulate(A))
acmA2 = copy.deepcopy(acmA)
print(min(sol(acmA, 1),sol(acmA2,-1)))
#print(acmA)


# Example run
# Input:
-1406309
-967
# Output:
0
import copy
n=int(input())
a=list(map(int,input().split()))
b=copy.copy(a)

ct1=0
if a[0]<=0:
  a[0]=1
  ct1+=1-a[0]
for i in range(1,n):
  if i%2==1:
    if sum(a[0:i+1])>=0:
      ct1+=sum(a[0:i+1])+1
      a[i]=-sum(a[0:i])-1
  else:
    if sum(a[0:i+1])<=0:
      ct1+=1-sum(a[0:i+1])
      a[i]=-sum(a[0:i])+1

ct2=0
if b[0]>=0:
  b[0]=-1
  ct2+=b[0]-1
for i in range(1,n):
  if i%2==0:
    if sum(b[0:i+1])>=0:
      ct2+=sum(b[0:i+1])+1
      b[i]=-sum(b[0:i])-1
  else:
    if sum(b[0:i+1])<=0:
      ct2+=1-sum(b[0:i+1])
      b[i]=-sum(b[0:i])+1

print(min(ct1,ct2))

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

def solve(A, mode=0):
  # mode = 0 : +-+-+-...
  # mode = 1 : -+-+-+...
  res = 0
  pre_a = 0
  for i, a in enumerate(A):
    a += pre_a
    if a * (-1)**(i+mode) > 0: # 符号がmatchしている
      pre_a = a
      continue
    # 符号がmatchしていない
    res += abs(a) + 1
    pre_a = (-1) ** (i + mode)
  return res
  
ans = solve(A, mode=0)
ans = min(ans, solve(A, mode=1))
print(ans)

# Example run
# Input:
128410
1
# Output:
0
n = int(input())
A = list(map(int, input().split()))
def test(L, sgn):
  count = 0
  s = 0
  for i in L:
    sgn *= -1
    s += i
    if s*sgn > 0:
      continue
    if sgn > 0:
      count += (1 - s)
      s = 1
    else:
      count += (s + 1)
      s = -1
  return count

ans = min(test(A, 1), test(A, -1))
print(ans)

# Example run
# Input:
55
941
# Output:
0
N = int(input())
A = list(map(int,input().split()))

def dfs(sign):
  cnt = 0
  tmp = 0
  for a in A:
    tmp += a
    if(tmp*sign >= 0):
      cnt += abs(tmp) + 1
      tmp = -sign
    sign *= -1
  return cnt

print(min(dfs(1), dfs(-1)))

# Example run
# Input:
-358903
-4422
# Output:
0
n = int(input())

numbers = list(map(int, input().split()))
counter = 0
sum_i_n = 0
sum_i_n_1 = numbers[0]

for i in range(len(numbers) - 1):
    # sum_i_n = sum(numbers[:i + 1])
    # sum_i_n_1 = sum(numbers[:i + 2])
    sum_i_n += numbers[i]
    sum_i_n_1 += numbers[i + 1]

    if sum_i_n == 0:
        numbers[i] += 1
        sum_i_n += 1
        sum_i_n_1 += 1
        counter += 1
    if sum_i_n * sum_i_n_1 >= 0:
        sub = abs(sum_i_n_1) + 1
        counter += sub
        if sum_i_n_1 > 0:
            numbers[i + 1] -= sub
            sum_i_n_1 -= sub
        else:
            numbers[i + 1] += sub
            sum_i_n_1 += sub

if sum_i_n_1 == 0:
    counter += 1

print(counter)


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

a = b

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

a = b

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:
-24
3469
# Output:
0
n=int(input())
a=[int(x) for x in input().split()]
def arrange(a0_is_plus):
    r=0 if a0_is_plus==True else 1
    sumNum=0
    ans=0
    for i,an in enumerate(a):
        sumNum+=an
        if i%2==r and sumNum<=0:
            ans+=1-sumNum
            sumNum=1
        elif i%2!=r and sumNum>=0:
            ans+=sumNum+1
            sumNum=-1
    return ans
print(min(arrange(True),arrange(False)))

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

def solve(a,t):
  ans,x=0,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(solve(A,True),solve(A,False)))

# Example run
# Input:
-66
-929
# Output:
0
#結局これもパターン全列挙(2パターン)か。
#判別しようと無駄な努力をしてしまった。
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    def buildDiff(bF):
        iC = 0
        iS = 0
        for a in aA:
            iS += a
            if bF:
                if iS >= 0:
                    iC += iS + 1
                    iS = -1
                bF = 0
            else:
                if iS <= 0:
                    iC += -1 * iS + 1
                    iS = 1
                bF = 1
        return iC
    print(min(buildDiff(1),buildDiff(0)))
解()


# Example run
# Input:
0
-84521052
# Output:
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:
      cnt += abs(-1-sum_n)
      sum_n = -1
    else:
      cnt += abs(1-sum_n)
      sum_n = 1
  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:
-2540
-1836
# Output:
0
N=int(input())
A=[int(i) for i in input().split()]
S1,S2=[],[]
if A[0]>0:
  S1.append(A[0])
  S2.append(-1)
  a1,a2=0,A[0]+1
elif A[0]==0:
  S1.append(1)
  S2.append(-1)
  a1,a2=1,1
else:
  S1.append(1)
  S2.append(A[0])
  a1,a2=-A[0]+1,0
for i in range(1,N):
  if S1[i-1]>0:
    if S1[i-1]+A[i]<0:
      S1.append(S1[i-1]+A[i])
    elif S1[i-1]+A[i]>=0:
      S1.append(-1)
      a1+=S1[i-1]+A[i]+1
  elif S1[i-1]<0:
    if S1[i-1]+A[i]>0:
      S1.append(S1[i-1]+A[i])
    elif S1[i-1]+A[i]<=0:
      S1.append(-1)
      a1+=-S1[i-1]-A[i]+1
  if S2[i-1]>0:
    if S2[i-1]+A[i]<0:
      S2.append(S2[i-1]+A[i])
    elif S2[i-1]+A[i]>=0:
      S2.append(-1)
      a2+=S2[i-1]+A[i]+1
  elif S2[i-1]<0:
    if S2[i-1]+A[i]>0:
      S2.append(S2[i-1]+A[i])
    elif S2[i-1]+A[i]<=0:
      S2.append(-1)
      a2+=-S2[i-1]-A[i]+1
print(min(a1,a2))

# Example run
# Input:
-18991721
465
# Output:
0