Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
"""ABC059 C Sequence diff:
"""

N=int(input())
A=list(map(int,input().split()))
Acop = A.copy()

cum = [0]*N
cum[0] = A[0]
for i in range(1, N):
    cum[i] = cum[i-1] + A[i]
cumcop = cum.copy()
# + - + - ...
start = N
for i in range(N):
    if i % 2 == 0:
        if cum[i] <= 0:
            start = i
            break
    else:
        if cum[i] >= 0:
            start = i
            break

if start == N:
    print(0)
    exit()

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

# - + - + 
A = Acop.copy()
cum = cumcop.copy()
start = N
for i in range(N):
    if i % 2 == 1:
        if cum[i] <= 0:
            start = i
            break
    else:
        if cum[i] >= 0:
            start = i
            break

if start == N:
    print(0)
    exit()

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

# Example run
# Input:
1
-227348
# 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
z=b[0]
for i in range(1,n):
  w=z+b[i]
  if i%2==0:
    if w>=0:
      ct2+=w+1
      b[i]=-z-1
  else:
    if w<=0:
      ct2+=1-w
      b[i]=-z+1
  z+=b[i]

print(min(ct1,ct2))

# Example run
# Input:
1
4887419
# Output:
-2
n = int(input())
a = list(map(int, input().split()))
t = 1
cand1 = 0
tmp = 0
for ai in a:
    if (tmp + ai) * t <= 0:
        cand1 += abs(tmp + ai - t)
        tmp = t
    else:
        tmp += ai
    t *= -1
t = -1
cand2 = 0
tmp = 0
for ai in a:
    if (tmp + ai) * t <= 0:
        cand2 += abs(tmp + ai - t)
        tmp = t
    else:
        tmp += ai
    t *= -1

print(min(cand1, cand2))

# Example run
# Input:
-68
-31
# Output:
0
input()
seq = list(map(int, input().rstrip("\n").split()))

iter_ = iter(seq)
ans1 = 0
for i, num in enumerate(iter_):
    if i == 0:
        sum_ = num
        if sum_ > 0:
            pass
        else:
            ans1 += abs(sum_ - 1)
            sum_ = 1
    else:
        sum_ += num
        if i % 2:
            if sum_ < 0:
                pass
            else:
                ans1 += abs(sum_ + 1)
                sum_ = -1
        else:
            if sum_ > 0:
                pass
            else:
                ans1 += abs(sum_ - 1)
                sum_ = 1

iter_ = iter(seq)
ans2 = 0
for i, num in enumerate(iter_):
    if i == 0:
        sum_ = num
        if sum_ < 0:
            pass
        else:
            ans2 += abs(sum_ + 1)
            sum_ = -1
    else:
        sum_ += num
        if i % 2:
            if sum_ > 0:
                pass
            else:
                ans2 += abs(sum_ - 1)
                sum_ = 1
        else:
            if sum_ < 0:
                pass
            else:
                ans2 += abs(sum_ + 1)
                sum_ = -1

print(min(ans1, ans2))


# Example run
# Input:
9,h&KO
-255
# Output:
0
N = int(input())
A = [int(x) for x in input().split()]

def F(A, sgn):
  cnt_operation = 0
  cum = 0
  for a in A:
    sgn *= (-1)
    cum += a
    if cum * sgn > 0:
      continue
    if sgn > 0:
      cnt_operation += (1 - cum)
      cum = 1
    else:
      cnt_operation += (cum + 1)
      cum = -1
  return cnt_operation

answer = min(F(A,1), F(A,-1))
print(answer)

# Example run
# Input:
141725276
-109089799
# Output:
0
def solve(n, arr):
  a = [x for x in arr]
  res = 0
  s = [0 for i in range(n)]
  if a[0] <= 0:
    res += a[0] * (-1) + 1
    a[0] += a[0] * (-1) + 1
  s[0] = a[0]
  for i in range(1, n):
    s[i] = s[i - 1] + a[i]
    if s[i - 1] > 0 and s[i] >= 0:
      res += s[i - 1] + a[i] + 1
      a[i] -= s[i - 1] + a[i] + 1
    elif s[i - 1] < 0 and s[i] <= 0:
      res += 1 - s[i - 1] - a[i]
      a[i] += 1 - s[i - 1] - a[i]
    s[i] = s[i - 1] + a[i]
  return res

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

  print(min(solve(n, a), solve(n, list(map(lambda x: x * (-1), a)))))

if __name__ == "__main__":
  main()

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

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S >= 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-A[0] // A[0]) + abs(A[0]) + 1)
print(ans)


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

def f(isPosi):
    total = 0
    cnt = 0
    for i in a:
        total += i
        if isPosi:
            if total >= 0:
                cnt += 1 + total
                total = -1
            isPosi = False
        else:
            if total <= 0:
                cnt += 1 - total
                total = 1
            isPosi = True
    return cnt

print(min(f(True), f(False)))

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


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


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

print(min(ans1,ans2))

# Example run
# Input:
34
-27
# Output:
-27
import itertools
n = int(input())
a = list(map(int,input().split()))
#'+-+-...'と'-+-+...'でそれぞれ求める
res1 = 0
res2 = 0
dif1 = 0
dif2 = 0
for i,j in enumerate(itertools.accumulate(a)):
    s = j + dif1
    t = j + dif2
    if i%2==0:
        if s<1:
            dif1 += 1 - s
            res1 += 1 - s
        if t>-1:
            dif2 -= 1 + t
            res2 += 1 + t
    else:
        if s>-1:
            dif1 -= 1 + s
            res1 += 1 + s
        if t<1:
            dif2 += 1 - t
            res2 += 1 - t
print(min(res1,res2))


# Example run
# Input:
-161
20
# Output:
0
def f():
  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


n = int(input())
a = list(map(int, input().split()))
cost = (a[0] == 0)
c = a[0] + (a[0] == 0)
f()
tmp = cost
cost = 0
if a[0] >= 0:
  cost = a[0] + 1
  c = -1
else:
  cost = -a[0] + 1
  c = 1
f()
print(min(cost, tmp))


# Example run
# Input:
-2503
10842
# Output:
False
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+=(abs(s0p)+1)

if s0n>=0:
  s0n-=(abs(s0n)+1)
  countn+=(abs(s0n)+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:
-14
2
# Output:
0
def solve():
  ans = 0
  N = int(input())
  A = list(map(int, input().split()))
  total = A[0]
  if total==0:
    for i in range(1,N):
      if A[i]!=0:
        total = pow(-1,i)*A[i]//abs(A[i])
        break
    else:
      return N
  for i in range(1,N):
    new_total = total+A[i]
    if total*(new_total)>=0:
      new_total = (-1)*total//abs(total)
      ans += abs(new_total-(total+A[i]))
    total = new_total
  return ans
print(solve())

# Example run
# Input:
-4
-1008
# Output:
0
def resolve(SL):
    # L[0]!=0を起点とする
    cnt = 0
    for i in range(len(SL)-1):
        s0 = SL[i]
        s1 = SL[i+1]
        if(s0>0 and s1>=0):
            SL[(i+1):] = [s-(s1+1) for s in SL[(i+1):]]
            cnt += (s1+1)
        elif(s0<0 and s1<=0):
            SL[(i+1):] = [s+(-s1+1) for s in SL[(i+1):]]
            cnt += (-s1+1)  
        print(SL)
    return cnt
            
    
def ans(L):
    SL = [sum(L[:(i+1)]) for i in range(len(L))]
    c0,c1=0,0
    
    if (L[0]>0):
        c0 = resolve(SL)
        c1 = (L[0]+1) + resolve(list(map(lambda x:x-(L[0]+1), SL)))
    elif (L[0]<0):
        c0 = resolve(SL)
        c1 = (-L[0]+1) + resolve(list(map(lambda x:x+(-L[0]+1), SL)))
    else:
        c0 = 1 + resolve(list(map(lambda x:x+1, SL)))
        c1 = 1 + resolve(list(map(lambda x:x-1, SL)))
    
    return(min(c0,c1))
  
N = int(input())
L = [int(x) for x in input().split(' ')]

print(ans(L))

# Example run
# Input:
2147483647
-1
# Output:
0
import copy

n = int(input())
A = list(map(int,input().split()))
sums = [0 for _ in range(n)]

sums[0] = A[0]

for i in range(1,n):
    sums[i] = A[i] + sums[i-1]
sums2 = copy.copy(sums)
tyousei = 0
ans1 = 0
for i in range(n):
    if i%2 ==0:
        if sums[i]+tyousei <=0:
            ans1 += abs(sums[i]+tyousei) +1
            tyousei += abs(sums[i]+tyousei) +1
    if i%2 ==1:
        if sums[i]+tyousei >=0:
            ans1 += abs(sums[i]+tyousei) +1
            tyousei -= sums[i]+tyousei +1

ans2 = 0
tyousei =0
for i in range(n):
    if i%2 ==1:
        if sums[i]+tyousei <=0:
            ans2 += abs(sums[i]+tyousei) +1
            tyousei += abs(sums[i]+tyousei) +1
    if i%2 ==0:
        if sums[i]+tyousei >=0:
            ans2 += sums[i]+tyousei +1
            tyousei -= sums[i]+tyousei +1

print(min(ans1,ans2))

# Example run
# Input:
1
8030667
# Output:
0
import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

signs = [-1,1]
a_sum = 0
changes_1 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_1 += abs(a_sum) + 1
        a_sum = signs[i%2]

signs = [1,-1]
a_sum = 0
changes_2 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_2 += abs(a_sum) + 1
        a_sum = signs[i%2]

print(min(changes_1,changes_2))

# Example run
# Input:
e3zvshd]
45580
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

# a_1 > 0 の場合を試す
res, sum = 0, 0
if 0 < A[0]: sum = A[0]
else: res, sum = -A[0] + 1, 1

for i in range(1, N):
    if 0 < sum:
        if -1 < sum + A[i]: # a_i を足して、符号が変わらない
            res += abs((sum + 1) - A[i])
            sum = -1
        else: # a_i を足して符号が変わる
            sum += A[i]
    else:
        if sum + A[i] < 1:
            res += abs((sum + 1) - A[i])
            sum = 1
        else:
            sum += A[i]

ans = res

# a_1 < 0 の場合を試す
res, sum = 0, 0
if A[0] < 0: sum = A[0]
else: res, sum = A[0] + 1, -1

for i in range(1, N):
    if 0 < sum:
        if -1 < sum + A[i]: # a_i を足して、符号が変わらない
            res += abs((sum + 1) - A[i])
            sum = -1
        else: # a_i を足して符号が変わる
            sum += A[i]
    else:
        if sum + A[i] < 1:
            res += abs((sum + 1) - A[i])
            sum = 1
        else:
            sum += A[i]

ans = min(ans, res)
print(ans)

# Example run
# Input:
-7
67130195
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

A_sum = 0
res0 = 0
for i,j in enumerate(A):
    A_sum += j
    if (i+1) % 2 != 0 and A_sum >= 0:
        res0 += A_sum + 1
        A_sum = -1
    if (i+1) % 2 == 0 and A_sum <= 0:
        res0 += abs(A_sum - 1)
        A_sum = 1
#     print("A_sum", A_sum)
#     print("res0", res0)
# print(res0)

A_sum = 0
res1 = 0
for i,j in enumerate(A):
    A_sum += j
    if (i+1) % 2 != 0 and A_sum <= 0:
        res1 += abs(A_sum - 1)
        A_sum = 1
    if (i+1) % 2 == 0 and A_sum >= 0:
        res1 += A_sum + 1
        A_sum = -1
#     print("A_sum", A_sum)
#     print("res1", res1)
# print(res1)

print(min(res0, res1))

# Example run
# Input:
-579377
-21
# Output:
0
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    count=0
    suml=l[0]
    for i in range(1,n):
        if suml>0 and suml+l[i]<0:
            suml+=l[i]
        elif suml<0 and suml+l[i]>0:
            suml+=l[i]
        elif suml>0 and suml+l[i]>=0:
            count+=suml+l[i]+1
            suml=-1
        else:
            count+=-suml-l[i]+1
            suml=1
    print(count)
else:
    count=1
    suml1=1
    for i in range(1,n):
        if suml1>0 and suml1+l[i]<0:
            suml1+=l[i]
        elif suml1<0 and suml1+l[i]>0:
            suml1+=l[i]
        elif suml1>0 and suml1+l[i]>=0:
            count+=suml1+l[i]+1
            suml1=-1
        else:
            count+=-suml1-l[i]+1
            suml1=1
    k1=count
    count=1
    suml2=-1
    for i in range(1,n):
        if suml2>0 and suml2+l[i]<0:
            suml2+=l[i]
        elif suml2<0 and suml2+l[i]>0:
            suml2+=l[i]
        elif suml2>0 and suml2+l[i]>=0:
            count+=suml2+l[i]+1
            suml2=-1
        else:
            count+=-suml2-l[i]+1
            suml2=1
    k2=count
    print(min(k1,k2))
    

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

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

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

# Example run
# Input:
1
0
# Output:
1
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)]
al = [(-1)**i for i in range(n)]
c1 = 0
for i in range(n):
    if s[i]*al[i] <= 0:
        c1 = c1 - s[i]*al[i] + 1
        s = [s[j] if j <= i-1 else s[j] + (s[i])*al[i] + al[i] for j in range(n)]
c2 = 0
for i in range(n):
    if s2[i]*al[i] <= 0:
        c2 = c2 - s2[i]*al[i] + 1
        s2 = [s2[j] if j <= i-1 else s2[j] - (s2[i])*al[i] + al[i] for j in range(n)]
print(min(c1,c2))

# Example run
# Input:
-1
-3439167
# Output:
0
n = int(input())
i = input()

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

if i[0] > 0:
    signN = 'neg'
else:
    signN = 'pos'
signM = None
tot = 0
count = 0

for x in range(len(i)):
    tot += i[x]
    
    if tot > 0:
        signM = 'pos'
    elif tot < 0:
        signM = 'neg'
    elif tot == 0:
        signM = 'z'

    if signN != signM and signM != 'z':
        signN = signM
    elif signN == 'pos' and signM == 'pos':
        count += (tot + 1)
        tot -= tot
        tot -= 1
        signM = 'neg'
    elif signN == 'neg' and signM == 'neg':
        count -= (tot - 1)
        tot = 1
        signM = 'pos'
        
    if tot == 0:
        count += 1
        if signN == 'neg':
            tot += 1
            signM = 'pos'
        elif signN == 'pos':
            tot -= 1
            signM = 'neg'

    signN = signM
            
print(count)

# Example run
# Input:
395620
1
# Output:
0
def z(s,l):
	for i in range(n-1):
		r=l+a[i+1]
		if r*l>=0:
			if l<=0:
				s+=1-r
				r=1
			else:
				s+=1+r
				r=-1
		l=r
	return s

n=int(input())
a=list(map(int,input().split()))
s1=0
l1=a[0]
if a[0]<=0:
	s1=1-a[0]
	l1=1
s2=0
l2=a[0]
if a[0]>=0:
	s1=a[0]-1
	l1=-1
print(min(z(s1,l1),z(s2,l2)))

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

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

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


if a[0]>0:
    count = countA(a)
elif a[0]<0:
    count = countB(a)
else:
    a[0] = 1
    count_ = countA(a) + 1
    a[0] = -1
    count = min(countB(a)+1, count_)
    
print(count)

# Example run
# Input:
-2540
-1836
# Output:
0
N = int(input())
a = list(map(int,input().split()))

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

# Example run
# Input:
-15303
-412794
# 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):
  a[0] = 1
  ans+= 1
  b[0] = -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))
print(a, b)

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

def wh(cst,ttl,flg):
    for i in range(n):
        ttl += a[i]

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

        
    return cst




ttl = 0
cst = 0



cst = wh(cst,ttl,1)
ttl = 0
cst2 = 0
cst2 = wh(cst2,ttl,-1)
   

print(min(cst,cst2))



# Example run
# Input:
-997466
6783
# Output:
0
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  Cost = 0
  # 符号 positive?
  #po_ = True 
  # 変わったか変わってないか
  if A[0] > 0: # if positive
    po_ = True
  elif A[0] == 0: # negative
    po_ = True
    A[0] += 1
    Cost += 1
  else:
    po_ = False
  ANS = [0] * (n+1)
  ANS[0] = A[0]
  
  for i in range(1,n):
    #print(ANS[i-1],po_,ANS[i-1] + A[i],Cost)
    if ANS[i-1]+A[i] > 0 and not po_: # sumがpositiveで前がnegativeだった
      po_ = True 
      ANS[i] = ANS[i-1] + A[i]
      # これで終わり
    elif ANS[i-1]+A[i] > 0 and po_: # posi : posi ?
      # 負にしなければならない
      Cost += abs(-1 - (ANS[i-1]+A[i])) # 先にこれやれ
      A[i] += -1 - (ANS[i-1] + A[i])
      # -4
      ANS[i] = ANS[i-1] + A[i]
      po_ = False
    elif ANS[i-1]+A[i] < 0 and not po_: #nega : nega
      # -1 はここ
      # print(A[i])
      Cost += abs(1 - (ANS[i-1]+A[i])) # 先にこれやれ
      A[i] += 1 - (ANS[i-1] + A[i])
      ANS[i] = ANS[i-1] + A[i]
      
      po_ = True
    elif ANS[i-1]+A[i] == 0 and po_: # nega: pos
      po_ = False
      A[i] -= 1
      Cost += 1
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1]+A[i] < 0 and po_:
      po_ = False
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1]+A[i] == 0 and not po_:
      po_ = True
      A[i] += 1
      Cost += 1
      ANS[i] = ANS[i-1] + A[i]
  print(Cost)
if __name__ == '__main__':
  main()

# Example run
# Input:
0
-6956
# Output:
0
import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = getint()
values = getints()

def solve(values, prev):
    res = 0
    for v in values:
        s = prev + v
        add = 0
        if prev > 0 and s >= 0:
            add = -s - 1
        if prev < 0 and s <= 0:
            add = -s + 1
        res += abs(add)
        prev = s + add
    return res

res1, res2 = 0, 0
if values[0] <= 0:
    add = abs(values[0]) + 1
    res1 = solve(values[1:], values[0] + add) + abs(add)
    add = -1 if values[0] == 0 else 0
    res2 = solve(values[1:], values[0] + add) + abs(add)
else:
    add = 1 if values[0] == 0 else 0
    res1 = solve(values[1:], values[0] + add) + abs(add)
    add = -(values[0] + 1)
    res2 = solve(values[1:], values[0] + add) + abs(add)

print(min(res1, res2))


# Example run
# Input:
10026
70800
# Output:
0