Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
a = list(map(int,input().split()))

ttl = a[0]
cst = 0

if a[0]>0:
    flg = 1
elif a[0] == 0:
    cst += 1
    ttl += 1
    flg = 1
else:
    flg = -1

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

    if ttl*flg < 0:
        flg *= -1
    else:
        if flg > 0:
            memo = abs(ttl)+abs(-1)
            ttl -= memo
            cst += memo
        elif flg < 0:
            memo = abs(ttl)+abs(-1)
            ttl += memo
            cst += memo
        flg *= -1
    

print(cst)



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

ans1 = 0
ans2 = 0
cur1 = 0
cur2 = 0

for i in range(n):
    cun = a[i]
    # iが偶数のときプラス
    if i % 2 == 0:
        # プラスじゃないとき
        if a[i] + cur1 <= 0:
            ans1 += -(a[i] + cur1) + 1
            cun = -cur1 + 1
    # iが奇数のときマイナス
    else:
        # マイナスじゃないとき
        if a[i] + cur1 >= 0:
            ans1 += a[i] + cur1 + 1
            cun = -cur1 - 1
    cur1 += cun

for i in range(n):
    cun = a[i]
    # iが偶数のときマイナス
    if i % 2 == 0:
        # マイナスじゃないとき
        if a[i] + cur2 >= 0:
            ans2 += a[i] + cur2 + 1
            cun = -cur2 - 1
    # iが奇数のときプラス
    else:
        # プラスじゃないとき
        if a[i] + cur2 <= 0:
            ans2 += -(a[i] + cur2) + 1
            cun = -cur2 + 1
    cur2 += cun

print(min(ans1, ans2))

# Example run
# Input:
-740
1
# Output:
0
import copy
n=int(input())
a=[0]+list(map(int,input().split()))
b=copy.copy(a)
psum=0
nsum=0
sum1=0
sum2=0
for i in range(1,n+1):
    if i%2!=0:
        psum+=max([0,1-sum1-a[i]])
        a[i]+=max([0,1-sum1-a[i]])
        sum1+=a[i]
    else:
        psum+=max([0,1+sum1+a[i]])
        a[i]-=max([0,1+sum1+a[i]])
        sum1+=a[i]
for i in range(1,n+1):
    if i%2!=0:
        nsum+=max([0,1+sum2+b[i]])
        b[i]-=max([0,1+sum2+b[i]])
        sum2+=b[i]
    else:
        nsum+=max([0,1-sum2-b[i]])
        b[i]+=max([0,1-sum2-b[i]])
        sum2+=b[i]

print(min([psum,nsum]))


# Example run
# Input:
-42245
-2503
# Output:
0
n = int(input())
a = list(map(int, input().split()))
cnt1 = 0
s = 0
swc = 1
for i in a:
	s += i
	if swc == 1:
		swc = 0
		if s > 0:
			continue
		else:
			cnt1 += 1-s
			s = 1
	else:
		swc = 1
		if s < 0:
			continue
		else:
			cnt1 += s+1
			s = -1
swc = 0
cnt2 = 0
s= 0
for i in a:
	s += i
	if swc == 1:
		swc = 0
		if s > 0:
			continue
		else:
			cnt2 += 1-s
			s = 1
	else:
		swc = 1
		if s < 0:
			continue
		else:
			cnt2 += s+1
			s = -1
print (min(cnt1, cnt2))


# Example run
# Input:
2050418568
-1
# Output:
0
n=int(input())
A=list(map(int,input().split()))
def chk(A,t):
  ans=0
  s=0
  for i in A:
    s+=i
    if t==True and s<1:
      ans+=1-s
      s=1
    elif t==False and s>-1:
      ans+=1+s
      s=-1
    t=not t
  return ans
print(min(chk(A,True),chk(A,False)))

# Example run
# Input:
-18229
-16112
# Output:
0
n = int(input())
alst = list(map(int, input().split()))
ans = []
for pm in range(2):
    total = 0
    tmp = 0
    for j, num in enumerate(alst):
        total += num
        if (j + pm) % 2 == 0:
            if total > 0:
                pass
            else:
                tmp += abs(1 - total)
                total = 1
        else:
            if total < 0:
                pass
            else:
                tmp += abs(-1 - total)
                total = -1
    ans.append(tmp)
print(min(ans))

# Example run
# Input:
37269982
104773
# Output:
0
N = int(input())
src = list(map(int, input().split()))

sum1 = sum2 = src[0]
op1 = op2 = 0
if sum1 < 1:
    op1 += (1 - sum1)
    sum1 = 1
if sum2 > -1:
    op2 += (sum2 + 1)
    sum2 = -1

for i in range(1,N):
    if i%2 == 1:
        if sum1 + src[i] > -1:
            op1 += (sum1 + src[i] + 1)
            sum1 = -1
        else:
            sum1 += src[i]
        if sum2 + src[i] < 1:
            op2 += (1 - sum2 - src[i])
            sum2 = 1
        else:
            sum2 += src[i]
    else:
        if sum2 + src[i] > -1:
            op2 += (sum2 + src[i] + 1)
            sum2 = -1
        else:
            sum2 += src[i]
        if sum1 + src[i] < 1:
            op1 += (1 - sum1 - src[i])
            sum1 = 1
        else:
            sum1 += src[i]

print(min(op1,op2))


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

times = 0
previous = a[0]
for i in range(1, n):
    if previous < 0:
        if previous + a[i] > 0:
            previous = previous + a[i]
        else:
            times += 1 - (previous + a[i])
            previous = 1      
    elif previous > 0:
        if previous + a[i] < 0:
            previous = previous + a[i]
        else:
            times += abs(-1 - (previous + a[i]))
            previous = -1


times2 = 0
if a[0] > 0:
    times2 += abs(-1 - a[0])
    previous = -1
else:
    times2 += 1 - a[0]
    previous = 1
for i in range(1, n):
    if previous < 0:
        if previous + a[i] > 0:
            previous = previous + a[i]
        else:
            times2 += 1 - (previous + a[i])
            previous = 1      
    elif previous > 0:
        if previous + a[i] < 0:
            previous = previous + a[i]
        else:
            times2 += abs(-1 - (previous + a[i]))
            previous = -1

times3 = 0
if a[0] > 0:
    times3 += abs(1 - a[0])
    previous = 1
else:
    times3 += -1 - a[0]
    previous = -1
for i in range(1, n):
    if previous < 0:
        if previous + a[i] > 0:
            previous = previous + a[i]
        else:
            times3 += 1 - (previous + a[i])
            previous = 1      
    elif previous > 0:
        if previous + a[i] < 0:
            previous = previous + a[i]
        else:
            times3 += abs(-1 - (previous + a[i]))
            previous = -1

print(min(times, times2, times3))



# Example run
# Input:
-27928965
7381
# Output:
0
# ARC072C - Sequence (ABC059C)
def seq_modifier(lst: list, flg: bool) -> int:  # true: positive
    """
    ARC072C - Sequence
    https://atcoder.jp/contests/abc072/tasks/arc072_a
    """
    cur, cnt = 0, 0
    for i in lst:
        cur += i
        if flg and cur <= 0:
            cnt += abs(cur) + 1
            cur = 1
        elif not flg and cur >= 0:
            cnt += abs(cur) + 1
            cur = -1
        flg = not flg
    return cnt


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    print(min(seq_modifier(lst, True), seq_modifier(lst, False)))


if __name__ == "__main__":
    main()

# Example run
# Input:
42339391
-80
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
cur = 0
ans1, ans2 = 0,0
for i, x in enumerate(a):
    cur += x
    if i%2 == 0:
        if cur >= 1:
            continue
        else:
            ans1 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans1 += abs(-1-cur)
            cur = -1
cur = 0
for i, x in enumerate(a):
    cur += x
    if i%2 != 0:
        if cur >= 1:
            continue
        else:
            ans2 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans2 += abs(-1-cur)
            cur = -1
print(min(ans1, ans2))

# Example run
# Input:
8659255
-29749547
# Output:
0
import copy
n = int(input())
*A, = map(int, input().split())


def solve(p):
    r = 0
    t = 0
    for a in A:
        t += a
        if t * p <= 0:
            r += abs(p - t)
            t = p
        p *= -1
    return r


print(min(solve(1), solve(-1)))


# Example run
# Input:
-8164991
-14
# Output:
0
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  ad1=0
  f=True
  sm=0
  for x in l:
    if f:
      sm+=x
      if sm<=0:
        ad1+=abs(sm)+1
        sm=1
      f=False
    else:
      sm+=x
      if sm>=0:
        ad1+=abs(sm)+1
        sm=-1
      f=True

  ad2=0
  f=False
  sm=0
  for x in l:
    if not f:
      sm+=x
      if sm>=0:
        ad2+=abs(sm)+1
        sm=-1
      f=True
    else:
      sm+=x
      if sm<=0:
        ad2+=abs(sm)+1
        sm=1
      f=False

  return min(ad1,ad2)

print(main())


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

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

for i,val in enumerate(a):#-
	sm2+=val
	if 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:
-213
-5
# Output:
6
N = int(input())
a = list(map(int, input().split()))

def calc_tmp_ans(tmp_ans, cum_sum):
    for i in range(1, N):
        #print(i, tmp_ans)
        prev_cum_sum = cum_sum
        cum_sum += a[i]
        if cum_sum * prev_cum_sum >= 0:
            tmp_ans += abs(cum_sum) + 1
            if prev_cum_sum > 0:
                cum_sum = -1
            else:
                cum_sum = 1
    return tmp_ans

ans = 1000000000000000
if a[0] == 0:
    ans = min(ans, calc_tmp_ans(1, 1))
    ans = min(ans, calc_tmp_ans(1, -1))
else:
    ans = min(ans, calc_tmp_ans(0, a[0]))
    if a[0] > 0:
        ans = min(ans, calc_tmp_ans(a[0] + 1, -1))
    else:
        ans = min(ans, calc_tmp_ans(abs(a[0]) + 1, 1))
print(ans)

# Example run
# Input:
-31
224
# Output:
0
N = int(input())
a = [int(x) for x in input().split()]

A = a[0]
asum = [A]
if A == 0:
    ansp,ansm,tempp,tempm = 1,1,1,-1
elif A < 0:
    ansp,ansm,tempp,tempm = -A + 1, 0, -A + 1, 0
else:
    ansp,ansm,tempp,tempm = 0, A + 1, 0, -A - 1

for i in range(1,N):
    A = asum[i-1] + a[i]
    asum += [A]

    A1 = A + tempp
    if A1 == 0:
        ansp += 1
        tempp += ((i%2)*2-1)
    elif i%2==0 and A1 < 0:
        ansp += -A1 + 1
        tempp += -A1 + 1
    elif i%2!=0 and A1 > 0:
        ansp += A1 + 1
        tempp += -A1 - 1

    A2 = A + tempm
    if A2 == 0:
        ansm += 1
        tempm += -((i%2)*2-1)
    elif i%2!=0 and A2 < 0:
        ansm += -A2 + 1
        tempm += -A2 + 1
    elif i%2==0 and A2 > 0:
        ansm += A2 + 1
        tempm += -A2 - 1

print(min(ansp,ansm))

# Example run
# Input:
-6
30
# Output:
0
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i])

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

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

print(min(ct1,ct2))

# Example run
# Input:
1
2
# Output:
-2
n = int(input())
a = [int(i) for i in input().split()]
#pattern1
temp = a[0]
ans1 = 0
if temp <= 0:
    ans1 += abs(temp) + 1
    temp = 1
for i in range(1, n):
    if temp*(temp + a[i]) < 0:
        temp += a[i]
    else:
        if temp > 0:
            ans1 += (temp + a[i] + 1)
            temp = -1
        elif temp < 0:
            ans1 += abs(temp + a[i]) + 1
            temp = 1
#pattern2
temp = a[0]
ans2 = 0
if temp >= 0:
    ans2 += abs(temp) + 1
    temp = -1
for i in range(1, n):
    if temp*(temp + a[i]) < 0:
        temp += a[i]
    else:
        if temp > 0:
            ans2 += (temp + a[i] + 1)
            temp = -1
        elif temp < 0:
            ans2 += abs(temp + a[i]) + 1
            temp = 1
ans = min(ans1, ans2)
print(ans)

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

count_a = 0 #+start
count_b = 0 #-start

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]

    count_b += nowsum + 1
    a[0] = -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))
    
elif 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]

    count_b += abs(nowsum) + 1
    a[0] = 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))    

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:
0
-5
# Output:
0
n = int(input())
a = list(map(int, input().split()))
i = 0
sum_before = 0
sum_after = 0
count = 0
while i < n:
    sum_after = sum_before + a[i]
    if sum_after * sum_before > 0 or sum_after == 0:
        count += 1
        if sum_after < 0:
            a[i] += 1
        elif sum_after > 0:
            a[i] -= 1
        elif sum_before < 0:
            a[i] += 1
        else:
            a[i] -= 1
    else:
        i += 1
        sum_before = sum_after

print(count)
 




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

def f(A, op, acc = 0, cnt = 0):
    for i in range(n):
        acc += A[i]
        
        if i % 2 == 0 and acc * op >= 0:
            cnt += op * acc + 1
            acc = - op
            
        if i % 2 == 1 and acc * op <= 0:
            cnt += - op * acc + 1
            acc = op
            
    if acc == 0:
        cnt += 1
        
    return cnt
        
print(min(f(A, -1), f(A, 1)))

# Example run
# Input:
-47268285
-256018
# Output:
1
n=int(input())
A=list(map(int,input().split()))
if A[0]>0:
  S=A[0]
  ans_1=0
else:
  S=1
  ans_1=1-A[0]
for i in A[1:]:
  if S*(S+i)<0:
    S+=i
  else:
    ans_1+=abs(S+i)+1
    if S<0:
      S=1
    else:
      S=-1
if A[0]<0:
  S=A[0]
  ans_2=0
else:
  S=-1
  ans_2=A[0]+1
for i in A[1:]:
  if S*(S+i)<0:
    S+=i
  else:
    ans_2+=abs(S+i)+1
    if S<0:
      S=1
    else:
      S=-1
print(min(ans_1,ans_2))

# Example run
# Input:
41286958
19928
# Output:
0
# ARC072C - Sequence (ABC059C)
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = [0] * 2
    
    # start with positive number
    cur = 0
    for i, j in enumerate(lst):
        cur += j
        if i % 2 == 0 and cur <= 0:
            cnt[0] += abs(cur) + 1
            cur = 1
        elif i % 2 == 1 and cur >= 0:
            cnt[0] += abs(cur) + 1
            cur = -1

    # start with negative number
    cur = 0
    for i, j in enumerate(lst):
        cur += j
        if i % 2 == 0 and cur >= 0:
            cnt[1] += abs(cur) + 1
            cur = -1
        elif i % 2 == 1 and cur <= 0:
            cnt[1] += abs(cur) + 1
            cur = 1

    print(min(cnt))


if __name__ == "__main__":
    main()

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

def simulate_operation(tgt_list):
  answer = 0
  N = len(tgt_list)
  previous_sum = tgt_list[0] # total to i - 1
  for i in range(1, N):
    # if prev_sum is plus and tgt_lis[i] is more minus than prev_sum, no action.
    # if prev_sum is plus and minus of tgt_lis[i] is larger than or equal to prev_sum.
    if previous_sum > 0 and previous_sum + tgt_list[i] >= 0:
      # the number that need to be subtracted to meet the requirements.
      require_subtraction = previous_sum + tgt_list[i] + 1
      # correcting the current number.
      tgt_list[i] -= require_subtraction
      answer += require_subtraction
    # if prev_sum is minus and tgt_lis[i] is more plus than prev_sum, no action.
    # if prev_sum is minus and minus of tgt_lis[i] is more smaller than or equal to prev_sum.
    elif previous_sum < 0 and previous_sum + tgt_list[i] <= 0:
      # the number that need to be added to meet the requirements.
      require_addition = -(previous_sum + tgt_list[i] - 1)
      # correcting the current number.
      tgt_list[i] += require_addition
      answer += require_addition
    previous_sum += tgt_list[i]
  return answer

ans_list = []
# simulate two options of starting with a positive or negative.
# positive, the first item is 1.
ans_pos = 0
A_pos = A[:]
init_cost = A_pos[0] - 1
ans_pos += abs(init_cost)
A_pos[0] -= init_cost
ans_pos += simulate_operation(A_pos)
ans_list.append(ans_pos)
# negative, the first item is -1.
ans_neg = 0
A_neg = A[:]
init_cost = A_neg[0] + 1
ans_neg += abs(init_cost)
A_neg[0] -= init_cost
ans_neg += simulate_operation(A_neg)
ans_list.append(ans_neg)
# simulate straight
ans_straight = 0
if A[0] != 0:
  ans_straight = simulate_operation(A)
  ans_list.append(ans_straight)

print(min(ans_list))

# Example run
# Input:
-554740
65444
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
s0 = a[0]
count=0
flag = False
if a.count(0)==n:
  print(2*n+1)
  exit()
i=0
while a[i]==0 and i<n:
  i+=1
  flag=True
if flag:
  if a[i]>0:
    if i%2==0:s0+=1
    else:s0-=1
    count+=1
  else:
    if i%2==0:s0-=1
    else:s0+=1
    count+=1

for i in range(1,n):
  s1 = s0+a[i]
  if s0*s1>=0:
    if s1>0:
      a[i]-=(abs(s1)+1)
      count+=(abs(s1)+1)
    elif s1<0:
      a[i]+=(abs(s1)+1)
      count+=(abs(s1)+1)
    elif s1==0:
      if s0>0:
        a[i]-=1
        count+=1
      elif s0<0:
        a[i]+=1
        count+=1
  s0 += a[i]
print(count)

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

def calc(sgn):
    ans = 0
    sum = 0
    for ai in a:
        sum += ai
        sgn *= -1
        if sum == 0:
            ans += 1
            sum = sgn
        elif sum * sgn < 0:
            ans += abs(sum) + 1
            sum = sgn
    return ans

print(min(calc(1), calc(-1)))


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

count1 = 0
now = A[0]
if now <= 0:
  count1 += (1-A[0])
  now = 1
for i in range(1, N):
  if i%2 == 0:
    if now+A[i] <= 0:
      count1 += 1-(now+A[i])
      now = 1
    else:
      now += A[i]
  else:
    if now+A[i] >= 0:
      count1 += 1+(now+A[i])
      now = -1
    else:
      now += A[i]
      
count2 = 0
now = A[0]
if now >= 0:
  count2 += (1+A[0])
  now = -1
for i in range(1, N):
  if i%2 == 1:
    if now+A[i] <= 0:
      count2 += 1-(now+A[i])
      now = 1
    else:
      now += A[i]
  else:
    if now+A[i] >= 0:
      count2 += 1+(now+A[i])
      now = -1
    else:
      now += A[i]
      
print(min(count1, count2))

# Example run
# Input:
-124978655
-23909
# Output:
0
n = int(input())
a = list(map(int,input().split()))
count=0
x = 0
if a[0]>0:
  for i in range(n):
    if i%2==0:
      x+=a[i]
      if x<0:
        count+=-1*x+1
        a[i]+=-1*x+1
        x+=-1*x+1
    else:
      x+=a[i]
      if x>0:
        count+=x+1
        a[i]+=-1*x-1
        x+=-1*x-1
else:
  for i in range(n):
    if i%2==0:
      x+=a[i]
      if x>0:
        count+=x+1
        a[i]+=-1*x-1
        x+=-1*x-1
    else:
      x+=a[i]
      if x<0:
        count+=-1*x+1
        a[i]+=-1*x+1
        x+=-1*x+1
if x==0:
  count+=1
print(count)

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

b = [0]*n
b[0]=a[0]
pt = 0
m = 0
ans = 0
for i in range(1,n):
    b[i]=b[i-1]+a[i]
bo = b[::2]
be = b[1::2]
if sum(bo)>sum(be):
    pt=0
else:
    pt=1

if pt==0:
    for i in range(n):
        if i%2==0 and b[i]+m<=0:
            ans+=1-b[i]-m
            m+=1-b[i]-m
        elif i%2==1 and b[i]+m>=0:
            ans+=1+b[i]+m
            m+=-1-b[i]-m
if pt==1:
    for i in range(n):
        if i%2==1 and b[i]+m<=0:
            ans+=1-b[i]-m
            m+=1-b[i]-m
        elif i%2==0 and b[i]+m>=0:
            ans+=1+b[i]+m
            m+=-1-b[i]-m
print(ans)

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


# first : positive case
a_sum = seq[0]
op = 0

if a_sum > 0:
    pass
else:
    a_sum = 1
    op += abs(a_sum) + 1

for a in seq[1:]:
    tmp = a_sum + a
    if tmp * a_sum < 0:
        a_sum = tmp
    elif a_sum < 0:
        #diff = 1 - a_sum - a
        a_sum = 1
        op += abs(tmp) + 1
    elif a_sum > 0:
        #diff = -1 - a_sum - a
        a_sum = -1
        op += abs(tmp) + 1

op1 = op

# first : negative case

a_sum = seq[0]
op = 0

if a_sum < 0:
    pass
else:
    a_sum = -1
    op += abs(a_sum) + 1

for a in seq[1:]:
    tmp = a_sum + a
    if tmp * a_sum < 0:
        a_sum = tmp
    elif a_sum < 0:
        #diff = 1 - a_sum - a
        a_sum = 1
        op += abs(tmp) + 1
    elif a_sum > 0:
        #diff = -1 - a_sum - a
        a_sum = -1
        op += abs(tmp) + 1
op2 = op
print(min(op1, op2))


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

INF = float('inf')

ans = INF

for sign in (1, -1):
    res, total_a = 0, 0
    for a in A:
        total_a += a
        if total_a * sign <= 0:
            res += abs(total_a - sign)
            total_a = sign
        sign *= -1
    ans = min(ans, res)

print(ans)

# Example run
# Input:
16591977
-127034
# Output:
0
def resolve(L):
    # L[0]!=0を起点とする
    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(L):
    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:
386831
-68037
# Output:
0
# -*- coding: utf-8 -*-

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

ans1 = 0
sum1 = 0
sign1 = 1
for a in A:
    sum1 += a
    if sign1 == 1:
        ans1 += max(0, 1-sum1)
        sum1 += max(0, 1-sum1)
    else:
        ans1 += -min(0, -1-sum1)
        sum1 += min(0, -1-sum1)
    sign1 *= -1

ans2 = 0
sum2 = 0
sign2 = -1
for a in A:
    sum2 += a
    if sign2 == 1:
        ans2 += max(0, 1-sum2)
        sum2 += max(0, 1 - sum2)
    else:
        ans2 += -min(0, -1-sum2)
        sum2 += min(0, -1 - sum2)
    sign2 *= -1

print(min(ans1, ans2))


# Example run
# Input:
2199169
-1595467139
# Output:
0