Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
lst = [int(x) for x in input().split()]

total = [0, 0]
ret = [0, 0]
for i in range(2):
    for j in range(n):
        total[i] += lst[j]
        if (i + j) % 2 == 0:
            if total[i] >= 0:
                ret[i] += total[i] + 1
                total[i] = -1
        else:
            if total[i] <= 0:
                ret[i] += abs(total[i] - 1)
                total[i] = 1

print(min(ret))

# Example run
# Input:
-9225256
339175880
# Output:
0
import copy
n = int(input())
a = [int(i) for i in input().split()]
b=a.copy()
s0p = a[0]
s0n = b[0]
countp = 0
countn = 0

if a.count(0)==n:
  print(2*n+1)
  exit()

if s0p<=0:
  s0p+=(abs(s0p)+1)
  countp+=1

if s0n>=0:
  s0n-=(abs(s0n)+1)
  countn+=1

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

for i in range(1,n):
  s1 = s0n+b[i]
  if s0n*s1>=0:
    if s1>0:
      b[i]-=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1<0:
      b[i]+=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1==0:
      if s0n>0:
        b[i]-=1
        countn+=1
      elif s0n<0:
        b[i]+=1
        countn+=1
  s0n += b[i]

print(countp if countp<=countn else(countn))





# Example run
# Input:
-11989124
-407
# Output:
0
from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]


def n_op(a, p):
    s = accumulate(a)
    x = 0
    n = 0

    for si in s:
        if p and si + x <= 0:
            n += 1 - (si + x)
            x += 1 - (si + x)
        if (not p) and si + x >= 0:
            n += 1 + (si + x)
            x -= 1 + (si + x)
        p = not p

    return n


answer = min([n_op(a, True), n_op(a, False)])
print(answer)


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

def calc(flag_sign):
  temp_flag = flag_sign
  sum_a = 0
  count = 0
  for one_a in list_a:
    if temp_flag:
      if sum_a + one_a > 0:
        sum_a += one_a
      else:
        count += abs(sum_a) - one_a + 1
        sum_a = 1
      temp_flag = False
    else:
      if sum_a + one_a < 0:
        sum_a += one_a
      else:
        count += abs(sum_a) + one_a + 1
        sum_a = -1
      temp_flag = True
  return count
    
print(min(calc(True), calc(False)))

# Example run
# Input:
11756850
-18229
# Output:
0
n = int(input())
a = list(map(int, input().split()))
s1 = []
s2 = []
for i in range(n):
    s1.append(sum(a[:i+1]))
    s2.append(sum(a[:i+1]))
ans1 = 0 #偶数インデックスが正
for i in range(n):
    if i % 2 == 0:
        if s1[i] <= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i, n):
                s1[j] += x
        else:
            continue
    else:
        if s1[i] >= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i,n):
                s1[j] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    if i % 2 == 1:
        if s2[i] <= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i, n):
                s2[j] += x
        else:
            continue
    else:
        if s2[i] >= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i,n):
                s2[j] -= x

print(min(ans1, ans2))

# Example run
# Input:
0
-6956
# Output:
0
n = int(input())
a = list(map(int,input().split()))
ans=10**13
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:
3650
2147483647
# 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]
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:
1
90
# Output:
-2
n = int(input())
a = list(map(int, input().split()))

def solve(n):
    ans = 0
    cusm = []
    if n == -1 and a[0] > 0:
        cusm.append(-1)
        ans += abs(-1 - a[0])
    elif n == -1 and a[0] < 0:
        cusm.append(1)
        ans += abs(1 - a[0])
    elif a[0] == 0:
        cusm.append(n)
        ans += abs(n - a[0])
    else:
        cusm.append(a[0])

    for i, ai in enumerate(a):
        if i == 0: continue
        if (cusm[-1] + ai) * cusm[-1] < 0: #符号が逆なら
            cusm.append(cusm[-1] + ai)
        elif cusm[-1] > 0: #操作の必要があって前が正なら
            ans += abs(-1 - (cusm[-1] + ai))
            cusm.append(-1)
        else:  #操作の必要があって前が負なら
            ans += abs(1 - (cusm[-1] + ai))
            cusm.append(1)
    return ans

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

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

SUM = 0
ans = 0
flag = 0 #0+,1-
for i in range(N):
    if i == 0:
        SUM = A[i]
        if SUM == 0:
            SUM+=1
            ans+=1
        elif SUM < 0:
            flag = 1
    else:
        SUM += A[i]
        if flag == 0:
            if SUM >= 0:
                ans += SUM+1
                SUM = -1
            flag = 1
        else:
            if SUM <= 0:
                ans += 1-SUM
                SUM = 1
            flag = 0
    #print(ans,SUM)

MIN = ans
ans = 0
flag = 1 #0+,1-
for i in range(N):
    if i == 0:
        SUM = A[i]
        if SUM == 0:
            SUM-=1
            ans+=1
        elif SUM > 0:
            flag = 0
    else:
        SUM += A[i]
        if flag == 0:
            if SUM >= 0:
                ans += SUM+1
                SUM = -1
            flag = 1
        else:
            if SUM <= 0:
                ans += 1-SUM
                SUM = 1
            flag = 0
    #print(ans,SUM)
                
ans = min(MIN,ans)
print(ans)

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

def solve(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(solve(a,True), solve(a,False)))

# Example run
# Input:
5182
0
# Output:
1
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
# a[0] == 0 のケース、要検証

n = int(input())
a = list(map(int, input().split()))
count_p = 0  # 操作回数(正)
count_m = 0  # 操作回数(負)
s = 0  # 現時点の和


def counter(a, s):
    if s * (s + a) < 0:
        return 0
    else:
        if s < 0:
            return 1 - (s + a)
        else:
            return -1 - (s + a)


# a[0]を+にする場合
if a[0] <= 0:
    count_p = 1 - a[0]
    s = 1
else:
    s = a[0]

for i in range(n-1):
    tmp = counter(a[i + 1], s)
    s = s + a[i+1]+tmp
    count_p = count_p + abs(tmp)

# a[0]を-にする場合
if a[0] >= 0:
    count_m = 1 - a[0]
    s = -1
else:
    s = a[0]


for i in range(n-1):
    tmp = counter(a[i + 1], s)
    s = s + a[i+1]+tmp
    count_m = count_m + abs(tmp)

print(str(min(count_p, count_m)))


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

#偶数番目を正にする場合

s = 0
t0 = 0

if a[0] > 0:
    s = a[0]
else:
    s = 1
    t0 = abs(a[0]) + 1

for i in range(1, n):
    if (s + a[i]) * (-1) ** i <= 0:
        t0 += abs(s + a[i]) + 1
        s = (-1) ** i
    else:
        s += a[i]

#偶数番目を負にする場合

s = 0
t1 = 0

if a[0] < 0:
    s = a[0]
else:
    s = -1
    t1 = abs(a[0]) + 1

for i in range(1, n):
    if (s + a[i]) * (-1) ** (i + 1) <= 0:
        t1 += abs(s + a[i]) + 1
        s = (-1) ** (i + 1)
    else:
        s += a[i]

ans = min(t0, t1)

print(ans)

# Example run
# Input:
-2503
10842
# Output:
0
n = int(input())
i = input()

i = i.split()
for item in range(len(i)):
    i[item] = int(i[item])

totn = 0
totp = 0

countp = 0
countn = 0

for x in range(len(i)):
    totp += i[x]
    totn += i[x]

    if x %2 == 1:
        if totn == 0:
            countn += 1
            totn = 1
        elif totn < 0:
            countn += abs(totn) + 1
            totn = 1

        if totp == 0:
            countp += 1
            totp = -1
        elif totp > 0:
            countp += abs(totp) + 1
            totp = -1

    if x %2 == 0:
        if totn == 0:
            countn += 1
            totn = -1
        elif totn > 0:
            countn += abs(totn) + 1
            totn = -1

        if totp == 0:
            countp += 1
            totp = 1
        elif totp < 0:
            countp += abs(totp) + 1
            totp = 1

count = min(countn, countp)
print(count)

# Example run
# Input:
793
439273
# Output:
0
def inpl(): return input().split()
n = int(input())
a = list(map(int, inpl()))

ans = float('inf')
for sgn in [1, -1]:
    s = 0
    cnt = 0
    for i in range(n):
        s += a[i]
        if s * sgn > 0:
            pass
        else:
            #s <= 0 and sgn = 1
            #s >= 0 and sgn = -1
            cnt += abs(sgn - s)
            s = sgn
        sgn *= (-1)
    ans = min(ans, cnt)
print(ans)

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

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

cnt = [0,0]

for i in [0,1]:
    tmp_sum = 0
    for j, a in enumerate(A):
        tmp_sum += a
        if (i + j) % 2 == 0 and tmp_sum <= 0:
            cnt[i] += abs(tmp_sum) + 1
            tmp_sum += abs(tmp_sum) + 1
        elif (i + j) % 2 == 1 and tmp_sum >= 0:
            cnt[i] += tmp_sum + 1
            tmp_sum -= tmp_sum + 1

print(min(cnt))
            

# Example run
# Input:
-1
27795
# Output:
0
def c(ints):
        
    sig = -1
    sig_ = +1
    total = 0
    total_ = 0
    mov = 0
    mov_ = 0
    
    for i_ in ints:
        tmp = total + i_
        tmp_ = total_ + i_
        if tmp == 0:
            mov +=1
            tmp = -sig
        elif sig * tmp > 0:
            mov += abs(tmp) + 1
            tmp = -sig
            
        if tmp_ == 0:
            mov_ +=1
            tmp_ = -sig_
        elif sig_ * tmp_ > 0:
            mov_ += abs(tmp_) + 1
            tmp_ = -sig_
            
        sig *= -1
        total = tmp
        sig_ *= -1
        total_ = tmp_

    return min(mov, mov_)

_ = input()
inp = input()
inp = inp.split(' ')
inp = [int(i_) for i_ in inp]
print(c(inp))

# Example run
# Input:
d;.u
-1893070
# Output:
0
n = int(input())
b = [int(x) for x in input().split()]
a = list()
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:
-877447
8312590
# Output:
0
# -*- coding: utf-8 -*-

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


def solve(bl):
    if bl:
        tmp = -1
    else:
        tmp = 0
    sm = 0
    cnt = 0
    for i, ele in enumerate(a):
        sm += ele
        if i % 2 + tmp:
            if sm < 1:
                cnt += 1 - sm
                sm = 1
        else:
            if sm > -1:
                cnt += sm + 1
                sm = -1

    return cnt


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


# Example run
# Input:
-28
187
# Output:
0
n = int(input())

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


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:
-80
-7517
# Output:
0
n = int(input())
an = list(map(int,input().split()))

def f(x):
    ans = 0
    count = 0
    for a in an:
        count += a
        if count * x >= 0:
            ans += abs(count)+1
            count = -x
        x *= -1
    return ans


print(min(f(1),f(-1)))


# Example run
# Input:
-4198582
98020
# Output:
0
n = int(input())
i = input()

i = i.split()
for item in range(len(i)):
    i[item] = int(i[item])

totn = 0
totp = 0

countp = 0
countn = 0

for x in range(len(i)):
    totp += i[x]
    totn += i[x]

    if x %2 == 1:
        if totn == 0:
            countn += 1
            totn = 1
        elif totn < 0:
            countn += abs(totn) + 1
            totn = 1

        if totp == 0:
            countp += 1
            totp = -1
        elif totp > 0:
            countp += abs(totp) + 1
            totp = -1

    if x %2 == 0:
        if totn == 0:
            countn += 1
            totn = -1
        elif totn > 0:
            countn += abs(totn) + 1
            totn = -1

        if totp == 0:
            countp += 1
            totp = 1
        elif totp < 0:
            countp += abs(totp) + 1

count = min(countn, countp)
print(count)


# Example run
# Input:
-877447
8312590
# Output:
0
def op(sign, n, a):
    if sign * a[0] <= 0:
        count = abs(a[0]) + 1
        S = sign
    else:
        count = 0
        S = a[0]

    for i in a[1:]:
        if S * (S + i) > 0:
            count += abs(S + i) + 1
            S = -1 if S > 0 else 1
        elif S + i == 0:
            count += 1
            S = -1 if S > 0 else 1
        else:
            S += i

    return count


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c1 = op(1, n, a)
    c2 = op(-1, n, a)
    print(min(c1, c2))


if __name__ == "__main__":
    main()


# Example run
# Input:
-1596917
-2
# Output:
0
def sequence(lis, first_value):
    count = 0
    now_sum = first_value
    pre_sum = first_value
    for num in lis[1:]:
        now_sum += num
        if now_sum == 0 or pre_sum * (now_sum) > 0:
            count += int(abs(now_sum) + 1)
            now_sum = -pre_sum/abs(pre_sum)
        pre_sum = now_sum
    return count

n = int(input())
a = [int(i) for i in input().split()]
if a[0] == 0:
    print(min(sequence(a, 1), sequence(a, -1))+1)
else:
    print(sequence(a, a[0]))

# Example run
# Input:
981571
-6163826
# Output:
0
n = int(input())
A = list(map(int,input().split()))
ans = 10**20

for i in[-1,1]:
    ansi,sum = 0,0
    for a in A:
        sum += a
        if sum*i <= 0:
            ansi +=abs(sum-i)
            sum = i
        i *= -1
    ans = min(ans,ansi)
print(ans)


# Example run
# Input:
7381
449660
# Output:
0
def solve(asum, a, ans):
    for i in range(1, n):
        # print(asum)
        asumplus = asum + a[i]
        if asumplus == 0 and asum > 0:
            asumplus -= 1
            ans += 1
        elif asumplus == 0 and asum < 0:
            asumplus -= 1
            ans += 1
        elif asumplus > 0 and asum > 0:
            ans += asumplus + 1
            asumplus = -1
        elif asumplus < 0 and asum < 0:
            ans += -asumplus + 1
            asumplus = 1
        asum = asumplus
    return ans

n = int(input())
a = list(map(int,input().split()))
asum = a[0]
if asum != 0:
    ans = solve(asum,a,0)
else:
    ans = min(solve(1,a,1),solve(-1,a,1))
print(ans)

# Example run
# Input:
-219310
-696
# 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):
    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:
-24
-35784
# Output:
0
N = int(input())
A = list(map(int, input().split()))


def solve(isPosi,N,A):
    ans = 0
    sm = 0
   
    for a in A:
        if isPosi:
            sm += a
            if sm >= 0:
                ans += abs(-1-sm)
                sm = -1
            isPosi = False
        
        else:
            sm += a
            if sm <= 0:
                ans += abs(1-sm)
                sm = 1
            isPosi = True
        
    return ans

ans_p = solve(True,N,A)
ans_n = solve(False,N,A)

print(min(ans_p,ans_n))

# Example run
# Input:
499561877
9
# Output:
0
n = int(input())
xs = list(map(int, input().split()))

# +-+-...
t1 = 0
s1 = 0
for (i, x) in enumerate(xs):
    s1 += x
    if i % 2 == 0:
        if s1 < 1:
            t1 += (1 - s1)
            s1 = 1
    else:
        if s1 > -1:
            t1 += (s1 + 1)
            s1 = -1

# -+-+...
t2 = 0
s2 = 0
for (i, x) in enumerate(xs):
    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:
493
471
# Output:
0
n=int(input())
a=list(map(int,input().split()))
sum=a[0]
if(sum==0):
  opp=1
  sum=1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opp+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  opm=1
  sum=-1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opm+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  op=min(opm,opp)
else:
  opp=0
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opp+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  opm=abs(sum)+1
  if(sum>0):sum=-1
  else:sum=1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opm+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  op=min(opp,opm)
    
print(op)

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


def judge(A,t):
    a_sum = 0
    cnt = 0
    for i in range(len(A)):
        a_sum += A[i]
        if i % 2 == 0:
            if t*a_sum  <= 0:
                cnt += 1-t*a_sum
                a_sum = t
        
        else:
            if t*a_sum >= 0:
                cnt += 1 + t*a_sum
                a_sum = -t
    
    return cnt
    
print(min(judge(A,1),judge(A,-1)))

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

# Example run
# Input:
-126905272
28016
# 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

if idx==n:
    ans=2*n-1
elif idx>0:
    ans=2*n-1
    if a[idx]>0:
        sum_last=-1
    else:
        sum_last=1
else:
    sum_last=a[0]
    ans=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:
1892351448
25627025
# Output:
0
n = int(input())
A = list(map(int, input().split()))
ans1 = 0
sign = True
total = 0
for i in range(len(A)):
    if sign:
        if total + A[i] >= 0:
            ans1 += total + A[i] + 1
            total = -1
        else:
            total += A[i]
    else:
        if total + A[i] <= 0:
            ans1 += 1 - (total + A[i])
            total = 1
        else:
            total += A[i]
    sign = total > 0
ans2 = 0
sign = False
total = 0
for i in range(len(A)):
    if sign:
        if total + A[i] >= 0:
            ans2 += total + A[i] + 1
            total = -1
        else:
            total += A[i]
    else:
        if total + A[i] <= 0:
            ans2 += 1 - (total + A[i])
            total = 1
        else:
            total += A[i]
    sign = total > 0
print(min(ans1, ans2))


# Example run
# Input:
4743227
-135
# Output:
0
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans1 = scan(a, -1)
    ans2 = scan(a, 1)

    ans = min(ans1, ans2)

    print(ans)

def scan(a, sgn):
    if a[0] * sgn > 0:
        res = 0
        v = a[0]
    else:
        res = abs(a[0] - sgn)
        v = sgn

    for ai in a[1:]:
        if v * (v + ai) < 0:
            v += ai
        else:
            if v > 0:
                res += abs(v + ai + 1)
                v = -1
            else:
                res += abs(v + ai - 1)
                v = 1

    return res

if __name__ == '__main__':
    solve()

# Example run
# Input:
1049999
4
# Output:
0
n = int(input())
al = list(map(int, input().split()))
m = n//2
mm = n % 2

temp = al[0]
res = 0

def ddd(temp,al,m,mm,res):   
    if temp > 0 and mm ==1:
        for i in range(1,m+1):
            temp +=al[i*2-1]
            if temp <0:
                pass
            else:
                res += temp+1
                temp = -1
            
            temp +=al[i*2]
            if temp >0:
                pass
            else:
                res +=1-temp
                temp = 1
        return(res)
        
    if temp > 0 and mm ==0:
        for i in range(1,m):
            temp +=al[i*2-1]
            if temp <0:
                pass
            else:
                res += temp+1
                temp = -1
            
            temp +=al[i*2]
            if temp >0:
                pass
            else:
                res +=1-temp
                temp = 1
        temp += al[n-1]
        if temp <0:
            pass
        else:
             res += temp+1
             temp = -1
        return(res)
        
    if temp < 0 and mm ==1:
        for i in range(1,m+1):
            temp +=al[i*2-1]
            if temp >0:
                pass
            else:
                res += 1-temp
                temp = 1
            
            temp +=al[i*2]
            if temp <0:
                pass
            else:
                res +=temp+1
                temp = -1
        return(res)
        
    if temp < 0 and mm ==0:
        for i in range(1,m):
            temp +=al[i*2-1]
            if temp >0:
                pass
            else:
                res += 1-temp
                temp = 1
            
            temp +=al[i*2]
            if temp <0:
                pass
            else:
                res +=temp+1
                temp = -1
        temp += al[n-1]
        if temp >0:
            pass
        else:
             res += 1-temp
             temp = 1
        return(res)

if al[0]==0:
    temp = 1
    res = 1
    dpl =ddd(temp,al,m,mm,res)
    temp = -1
    res = 1
    dmi =ddd(temp,al,m,mm,res)
    print(min(dpl,dmi))
else:
    print(ddd(temp,al,m,mm,res))

# Example run
# Input:
-525059
89101055
# Output:
0