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


def f(p):
    sa = 0
    ans = 0
    for ai in a:
        if p:
            sa += ai
            if sa >= 0:
                ans += sa + 1
                sa = -1
            p = False
        else:
            sa += ai
            if 0 >= sa:
                ans += 1 - sa
                sa = 1
            p = True
    return ans


def main():
    print(min(f(True), f(False)))


main()


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

def chk(a,t):     # t=True(奇数項が正), t=False(偶数項が正) 
    cnt=0   # 操作回数
    x=0     # 塁積和        
    for i in a:
        x+=i      
        if t==True and x<=0:       # 正項予定なのに累積が負か0
            cnt+=1-x                              
            x=x+(1-x)               # 今回のcntで符号変更
        elif t==False and x>=0:   # 負項予定なのに累積が正か0
            cnt+=1+x              
            x=x-(1+x)              # 今回のcntで符号変換
        t = not t                  # 次の項は符号が逆
    return cnt

print(min(chk(a,True),chk(a,False)))

# Example run
# Input:
7381
449660
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]

ans1 = ans2 = 0
s = s2 = a[0]
if a[0] <= 0:
    s = 1
    ans1 = -a[0] + 1
if a[0] >= 0:
    s2 = -1
    ans2 = a[0] + 1

for i in range(1, len(a)):
    s += a[i]
    if i % 2 == 1 and s >= 0:
        ans1 += s + 1
        s = -1
    elif i % 2 == 0 and s <= 0:
        ans1 += -s + 1
        s = 1
    s2 += a[i]
    if i % 2 == 0 and s2 >= 0:
        ans2 += s2 + 1
        s2 = -1
    elif i % 2 == 1 and s2 <= 0:
        ans2 += -s2 + 1
        s2 = 1

print(min(ans1, ans2))


# Example run
# Input:
72781634
-501810
# Output:
0
N = int(input())
A = tuple(map(int, input().split()))


def f(pm):
    ans, s = 0, 0
    for a in A:
        s += a
        if s * pm <= 0:
            d = abs(s - pm)
            ans += d
            s += d * pm
        pm *= -1
    return ans


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


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

ans1 = 0
s = A[0]
if s >= 0:
    ans1 = 1+s
    s = -1
for i in range(1, N):
    s += A[i]
    if i % 2 != 0:
        if s <= 0:
            ans1 += 1-s
            s = 1
    else:
        if s >= 0:
            ans1 -= -1-s
            s = -1

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


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

a_orig = a[:]

ans1 = 0
ans2 = 0
tot = [0 for i in range(n)]
tot[0] = a[0]

if a[0] <= 0:
    a[0] = 1
    tot[0] = 1


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

    else:
        if tot[i] >= 0:
            tot[i] = -1
            a[i] = tot[i] - tot[i-1]
print(tot)
print(a)
for i in range(n):
    ans1 += abs(a[i]-a_orig[i])



a = a_orig[:]
tot = [0 for i in range(n)]
tot[0] = a[0]

if a[0] >= 0:
    a[0] = -1
    tot[0] = -1

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

    else:
        if tot[i] >= 0:
            tot[i] = -1
            a[i] = tot[i] - tot[i-1]

for i in range(n):
    ans2 += abs(a[i]-a_orig[i])
print(tot)
print(a)
print(min(ans1, ans2))


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

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

    elif sum(A) < 0:
        while sum(A) + a[i+1] <= 0:
            a[i+1] += 1
            cnt += 1
            
if sum(a) == 0:
    cnt += 1

print(cnt)

# Example run
# Input:
-31
224
# 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))
    a[0] = -1
    anstot.append(1+operate(a,-1))    
print(min(anstot))

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

def ans(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))

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

print(ans(L))


# Example run
# Input:
815520
-75
# Output:
0
n = int(input())
a = list(map(int, input().split()))
s = [ sum(a[0:i+1]) for i in range(n)]
s2 = [ s[i]*(-1) for i in range(n)]
c1 = 0
for i in range(n):
    if s[i]*(-1)**i <= 0:
        c1 = c1 + s[i]*(-1)**(i+1) + 1
        s = [s[j] if j <= i-1 else s[j] - (s[i])*(-1)**i + (-1)**i for j in range(n)]
c2 = 0
for i in range(n):
    if s2[i]*(-1)**i <= 0:
        c2 = c2 + s2[i]*(-1)**(i+1) + 1
        s2 = [s2[j] if j <= i-1 else s2[j] - (s2[i])*(-1)**i + (-1)**i for j in range(n)]
print(min(c1,c2))

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

def check(TF):
    wa = 0
    flag = TF
    count = 0
    for i in a:
        if flag: #正にしたい時  
            if wa + i> 0:
                wa += i
            else:
                count += abs(wa) + 1 - i
                wa = 1
            flag = False
        else: #負にしたい場合
            if wa + i < 0:
                wa += i
            else:
                count += abs(wa) + 1  + i
                wa = -1
            flag = True
    return count

# print (check(True))
# print (check(False))
            
print (min(check(True), check(False)))


# Example run
# Input:
-1596917
-2
# Output:
0
def resolve():
    n=int(input())
    A=[int(i) for i in input().split()]
    def check(A,flag): # flag=Trueなら上から、Falseなら下から
        cumsum=0
        ans=0
        for a in A:
            cumsum+=a
            if cumsum<=0 and flag:
                ans+=1-cumsum
                cumsum=1
            elif cumsum>=0 and (not flag):
                ans+=1+cumsum
                cumsum=-1
            flag = (not flag)
        return ans
    print(min(check(A,True),check(A,False)))
resolve()

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

m_count = 0
p_count = 0

s = [0]*n
s[0] = a[0]

# // - start
if a[0] >= 0:
    tmp = -a[0] -1
    s[0] += tmp
    m_count += abs(tmp)

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

    if s[i] == 0:
        tmp = -s[i-1]//abs(s[i-1])
        s[i] += tmp
        m_count += abs(tmp)
    elif s[i] * s[i-1] > 0:
        tmp = (-s[i]) + (-s[i]//abs(s[i]))
        s[i] += tmp
        m_count += abs(tmp)

# // + start
s[0] = a[0]

if a[0] <= 0:
    tmp = -a[0] +1
    s[0] += tmp
    p_count += abs(tmp)

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

    if s[i] == 0:
        tmp = -s[i-1]//abs(s[i-1])
        s[i] += tmp
        p_count += abs(tmp)
    elif s[i] * s[i-1] > 0:
        tmp = (-s[i]) + (-s[i]//abs(s[i]))
        s[i] += tmp
        p_count += abs(tmp)

print(min(p_count,m_count))


# Example run
# Input:
1
-755
# Output:
0
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = INF

    cost = 0
    total = 0
    for i, a in enumerate(A):
        total += a
        if i % 2 == 0 and total <= 0:
            cost += abs(total) + 1
            total = 1
        elif i % 2 == 1 and total >= 0:
            cost += abs(total) + 1
            total = -1
    ans = min(ans, cost)

    cost = 0
    total = 0
    for i, a in enumerate(A):
        total += a
        if i % 2 == 1 and total <= 0:
            cost += abs(total) + 1
            total = 1
        elif i % 2 == 0 and total >= 0:
            cost += abs(total) + 1
            total = -1

    ans = min(ans, cost)
    print(ans)


if __name__ == '__main__':
    main()


# Example run
# Input:
-3249
901872
# Output:
0
N = int(input())
A = [int(_) for _ in input().split()]

#positive
pos_count = 0
sign = 1
cumsum = 0
for a in A:
    cumsum += a
    if cumsum * sign <= 0:
        pos_count += abs(sign - cumsum)
        cumsum = sign
    sign *= -1

#negative
neg_count = 0
sign = -1
cumsum = 0
for a in A:
    cumsum += a
    if cumsum * sign <= 0:
        neg_count += abs(sign - cumsum)
        cumsum = sign
    sign *= -1

print(min(pos_count, neg_count))


# Example run
# Input:
-1
-3439167
# Output:
0
n = int(input())
a = list(map(int, input().split()))
l = len(a)
b = []
for i in range(l):
  b.append(a[i])
  
ans = 0
Ans = 0
summary = a[0]

if(summary == 0):
  summary = 1
  ans+= 1
  Summary = -1
  Ans+= 1
else:
  b[0] = int(-a[0]/ abs(a[0]))
  Ans+= abs(a[0]- b[0])
  Summary = b[0]  
  
for i in range(1, l):
  if(summary* (summary+ a[i])>= 0):
    if(summary > 0):
      ans+= a[i]+ summary+ 1
      a[i] = -summary- 1 
      summary= -1
    else:
      ans+= -summary+ 1- a[i]
      a[i] = -summary+ 1
      summary= 1
  else:
    summary+= a[i]

for i in range(1, l):
  if(Summary* (Summary+ b[i])>= 0):
    if(Summary > 0):
      Ans+= b[i]+ Summary+ 1
      b[i] = -Summary- 1 
      Summary= -1
    else:
      Ans+= -Summary+ 1- b[i]
      b[i] = -Summary+ 1
      Summary= 1
  else:
    Summary+= b[i]
    
print(min(ans, Ans))

# Example run
# Input:
-3528
-5900
# Output:
0
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
cnt1, cnt2 = 0, 0
cur = 1
for i in a:
    cnt1 += i
    if cnt1 * cur <= 0:
        ans1 += abs(cnt1 - cur)
        cnt1 = cur
    cur *= -1
cur = -1
for i in a:
    cnt2 += i
    if cnt2 * cur <= 0:
        ans2 += abs(cnt2 - cur)
        cnt2 = cur
    cur *= -1
print(min(ans1, ans2))

# Example run
# Input:
1
87
# Output:
0
def check1(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
    else:
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
  return True

def check2(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
    else:
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
  return True



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = 0
ans2 = 0

while(True):
  c = check1(a)
  if(c == True):
    break

  a[c[0]] += c[1]
  ans1 += abs(c[1])


while(True):
  c = check2(a2)
  if(check2(a2) == True):
    break
  a2[c[0]] += c[1]
  ans2 += abs(c[1])


print(ans1) if(ans1<ans2) else print(ans2)

# Example run
# Input:
xgI8vLA
-81206326
# Output:
0
n = int(input())
a = list(map(int, input().split()))
cost = (a[0] == 0)
c = a[0] + (a[0] == 0)
for i in a[1:]:
	if c > 0:
		if c + i >= 0:
			cost += c + i + 1
			c = -1
		else:
			c += i
	else:
		if c + i <= 0:
			cost += 1 - c - i
			c = 1
		else:
			c += i
tmp = cost
cost = 0
if a[0] >= 0:
	cost = a[0] + 1
	c = -1
else:
	cost = -a[0] + 1
	c = 1
for i in a[1:]:
	if c > 0:
		if c + i >= 0:
			cost += c + i + 1
			c = -1
		else:
			c += i
	else:
		if c + i <= 0:
			cost += 1 - c - i
			c = 1
		else:
			c += i
print(int(min(tmp, cost)))


# Example run
# Input:
-3108573
51
# Output:
0
n = int(input())
A = list(map(int,input().split()))
a = [A,A]
res = [0,0]
sum = 0
for check in range(2):
  sum = 0
  if a[check][0] == 0:
    if check == 0:
      a[0][0] += 1
    else:
      a[1][0] -= 1
    res[check] += 1
  if check == 1:
    if a[1][0] > 0:
      temp = -1 - a[1][0]
      a[1][0] += temp
      res[1] += temp * -1
    elif a[1][0] < 0:
      temp = 1 - a[1][0]
      a[1][0] += temp
      res[1] += temp
  for i in range(n-1):
    sum += a[check][i]
    if sum * (sum + a[check][i+1]) >= 0:
      if sum > 0:
        temp = -1 - sum - a[check][i+1]
        a[check][i+1] += temp
        res[check] += temp * -1
      else:
        temp = 1 - sum - a[check][i+1]
        a[check][i+1] += temp
        res[check] += temp
print(min(res[0],res[1]))

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

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

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

# Example run
# Input:
-4
1363926
# Output:
0 1363927
n = int(input())
a = [int(i) for i in input().split(" ")]

s = 0
num1 = 0
for i, x in enumerate(a):
    if i == 0:
        if x > 0:
            s = x
        else:
            s = 1
            num1 += abs(1-x)
    else:
        if s > 0:
            if s + x < 0:
                s += x
            else:
                num1 += abs(-s-x-1)
                s = -1
        else:
            if s + x > 0:
                s += x
            else:
                num1 += abs(-s-x+1)
                s = 1
s = 0
num2 = 0
for i, x in enumerate(a):
    if i == 0:
        if x < 0:
            s = x
        else:
            s = -1
            num2 += abs(-1-x)
    else:
        if s > 0:
            if s + x < 0:
                s += x
            else:
                num2 += abs(-s-x-1)
                s = -1
        else:
            if s + x > 0:
                s += x
            else:
                num2 += abs(-s-x+1)
                s = 1
print(min([num1, num2]))

# Example run
# Input:
-233
-48
# Output:
0
input()
*A,=map(int,input().split())
f=True
s1=0;r1=0
s2=0;r2=0
for a in A:
  s1+=a;s2+=a
  if f and s1<=0:r1+=1-s1;s1=1
  elif not(f) and s1>=0:r1+=s1+1;s1=-1
  if not(f) and s2<=0:r2+=1-s2;s2=1
  elif f and s2>=0:r2+=s2+1;s2=-1
  f=not(f)
print(min(r1,r2))

# Example run
# Input:
h?]i8&
344177
# Output:
0
n=int(input())
a=map(int,input().split())
ans1,ans2=0,0
m1,m2=0,0
k=1
for i in a:
  m1+=i
  m2+=i
  if k:
    k=0
    if m1>=0:
      ans1+=m1+1
      m1=-1
    if m2<=0:
      ans2+=1-m2
      m2=1
  else:
    k=1
    if m1<=0:
      ans1+=1-m1
      m1=1
    if m2>=0:
      ans2+=m2+1
      m2=-1
print(min(ans1,ans2))

# Example run
# Input:
-226728064
-196
# Output:
0
n = int(input())
A = list(map(int,input().split()))
B = A[:]
for i in range(1,n):
    B[i] += B[i-1]
C = B[:]
cnt1 = 0
cnt2 = 0
if B[0]<=0:
    cnt1 += abs(1-B[0])
    cnt2 += 1-B[0]
    B[0] += cnt2
for i in range(1,n):
    if i%2==0:
        if B[i]+cnt2<=0:
            cnt1 += abs(1-B[i]-cnt2)
            cnt2 += 1-B[i]-cnt2
            B[i] += cnt2
    else:
        if B[i]+cnt2>=0:
            cnt1 += abs(-1-B[i]-cnt2)
            cnt2 += -1-B[i]-cnt2
            B[i] += cnt2
cnt3 = 0
cnt4 = 0
if C[0]>=0:
    cnt3 += abs(-1-C[0])
    cnt4 += -1-C[0]
    C[0] += cnt4
for i in range(1,n):
    if i%2==0:
        if C[i]+cnt4>=0:
            cnt3 += abs(-1-C[i]-cnt4)
            cnt4 += -1-C[i]-cnt4
            C[i] += cnt4
    else:
        if C[i]+cnt4<=0:
            cnt3 += abs(1-C[i]-cnt4)
            cnt4 += 1-C[i]-cnt4
            C[i] += cnt4
print(min(cnt1,cnt3))

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

cnt = 0
sum_a = 0

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

if A[0] < 0:
    cnt -= abs(A[0]) + 1
    print(cnt)
else:
    print(cnt)
    

# Example run
# Input:
-2
1973033
# Output:
0
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    iL = len(aA)


    iStart = 0
    if sum(aA[0::2]) < sum(aA[1::2]):
        iStart = 1


    iC = 0
    aD = [0]*iL
    if 0 % 2 == iStart :
        if aA[0] <= 0:
            iC += -1 * aA[0] + 1
            aA[0] = 1
    else:
        if 0 <= aA[0] :
            iC += aA[0] + 1
            aA[0] = -1

    aD[0] = aA[0]
    for i in range(1,iL):
        aD[i] = aD[i-1]+aA[i]
        if i % 2 == iStart :
            if aD[i] <= 0 :
                iC += -1*aD[i] +1
                aD[i] = 1
        else:
            if 0 <= aD[i] :
                iC += aD[i] +1
                aD[i] = -1
    print(iC)
解()


# Example run
# Input:
-1
30456987
# Output:
0
N=int(input())
A=list(map(int,input().split()))
cur=A[0]
ans=0
isplus=True
ind=1
if cur<0:
  isplus=False
if cur==0:
  # すべて0の場合
  allzero=True
  firstNotZero=0
  firstNotZeroInd=0
  for i in range(N):
    if A[i]!=0:
      firstNotZero=A[i]
      firstNotZeroInd=i
      allzero=False
      break
  if allzero:
    print(2*N-1)
    exit(0)
  # 0以外が出てくる場合
  ans+=(firstNotZeroInd)*2-1
  if firstNotZero>0:
    cur=-1
    ind=firstNotZeroInd
    isplus=False
  else:
    cur=1
    ind=firstNotZeroInd
    isplus=True

for i in range(ind,N):
  if isplus:
    if cur+A[i]>=0:
      diff=abs((cur+A[i])-(-1))
      ans+=diff
      cur=-1
    else:
      cur+=A[i]
    isplus=False
  else:
    if cur+A[i]<=0:
      diff=abs((cur+A[i])-1)
      ans+=diff
      cur=1
    else:
      cur+=A[i]
    isplus=True
  
print(ans)


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

def calc(A):
  ans = 0
  s = A[0]
  if s > 0:
    flag = 1
  elif s < 0:
    flag = -1
  for i in range(1,N):
    s += A[i]
    if flag == 1 and s >= 0:
      ans += s + 1
      s = -1
    elif flag == -1 and s <= 0:
      ans += 1 - s
      s = 1
    flag *= -1
  return ans

if A[0] > 0:
  print(min(calc(A),calc([-1]+A[1:])+A[0]+1))
elif A[0] < 0:
  print(min(calc(A),calc([1]+A[1:])-A[0]+1))
else:
  print(min(calc([1]+A[1:]),calc([-1]+A[1:]))+1)


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

ans = 1e16
for s in (1, -1):
    res, acc = 0, 0
    for a in A:
        acc += a
        if acc * s <= 0:
            res += abs(acc-s)
            acc = s
        s *= -1
        print("%d " % acc, end="")
    print()
    ans = min(ans, res)

print(ans)


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

def chk(a,t):
  ans = 0
  x = 0
  for i in a:
    x += i
    if t==True and x<1:
      ans += 1-x
      x = 1
    elif t==False and x>-1:
      ans += x+1
      x = -1
    t=not t
  return ans
print(min(chk(a,True),chk(a,False)))
    
  
  


# Example run
# Input:
-32152
1612446667
# Output:
0
n = int(input())
A = list(map(int,input().split()))
def func(list1,op,acc = 0,count = 0):
    for i in range(n):
        acc += list1[i]
        if i % 2 == 1 and acc * op >= 0:
            count += op * acc + 1
            acc = -op
        elif i % 2 == 0 and acc * op <= 0:
            count += -op * acc + 1
            acc = op
    if acc == 0:
        count += 1
    return count
if A[0] > 0:
    ans = func(A,1)
elif A[0] < 0:
    ans = func(A,-1)
elif A[0] == 0:
    ans = min(func(A,1),func(A,-1))
print(ans)

# Example run
# Input:
-296641124
-21
# Output:
1
def op(pos, n, a):
    if pos:
        S = 1 if a[0] == 0 else a[0]
    else:
        S = -1 if a[0] == 0 else a[0]
    count = 1 if a[0] == 0 else 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(True, n, a)
    c2 = op(False, n, a)
    print(min(c1, c2))


if __name__ == "__main__":
    main()

# Example run
# Input:
1947279
-4
# Output:
0
n = int(input())
a = list(map(int, input().split()))
 
r_even = 0  # 偶数桁を＋にする場合の値
a_even = a[:]
sum_even = 0
for i in range(len(a)):
    sum_even += a_even[i]
    if i % 2 == 0:
        if sum_even <= 0:
            r_even += 1 - sum_even
            a_even[i] += 1 - sum_even
            sum_even += 1 - sum_even
    else:
        if sum_even >= 0:
            r_even += sum_even + 1
            a_even[i] -= sum_even + 1
            sum_even -= sum_even + 1

r_odd = 0   #奇数桁を＋にする場合の値
a_odd = a[:]
sum_odd = 0
for i in range(len(a)):
    sum_odd += a_odd[i]
    if i % 2 != 0:
        if sum_odd <= 0:
            r_odd += 1 - sum_odd
            a_odd[i] += 1 - sum_odd
            sum_odd += 1 - sum_odd
    else:
         if sum_odd >= 0:
            r_odd += sum_odd + 1
            a_odd[i] -= sum_odd + 1
            sum_odd -= sum_odd + 1

print(min(r_odd, r_even))


# Example run
# Input:
4082171
1
# Output:
0
n=int(input())
N=list(map(int,input().split()))
emptylists=[]
number=0
for i in range(n):
    number+=N[i]
    emptylists.append(number)

emptylists.append(1)
ans1=0
i=0
use=0

while i<n:
    #偶数番が正、奇数番が負の時
    if i%2==0:
        #奇数番め
       # if emptylists[i]+use<0:
        if emptylists[i]+use>=0:
            ans1+=emptylists[i]+use+1  
            use=-1-emptylists[i]

    if i%2!=0:
        #偶数番め
       # if emptylists[i]+use>0: 
        if emptylists[i]+use<=0:
            ans1+=1-emptylists[i]-use
            use=1-emptylists[i]

    i+=1           
ans2=0
j=0
uses=0

while j<n:
    #偶数番が正、奇数番が負の時
    if j%2==0:
        #奇数番め
       # if emptylists[i]+uses<0:
        if emptylists[j]+uses>=0:
            ans2+=emptylists[j]+uses+1  
            uses=-1-emptylists[j]

    if j%2!=0:
        #偶数番め
       # if emptylists[j]+uses>0:       
        if emptylists[j]+uses<=0:
            ans2+=1-emptylists[j]-uses
            uses=1-emptylists[j]

    j+=1           
print(min(ans1,ans2))


# Example run
# Input:
0
141176
# Output:
0