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

ans0 = ans1 = 0
cs = 0
for i, ai in enumerate(a):
    cs += ai

    if i % 2 == 0:
        if cs < 1:
            ans0 += 1 - cs
            cs = 1
    else:
        if cs > -1:
            ans0 += cs + 1
            cs = -1

cs = 0
for i, ai in enumerate(a):
    cs += ai

    if i % 2 == 0:
        if cs > -1:
            ans1 += cs + 1
            cs = -1
    else:
        if cs < 1:
            ans1 += 1 - cs
            cs = 1

ans = min(ans0, ans1)
print(ans)


# Example run
# Input:
-597336700
-16112
# Output:
0
N = int(input())
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]

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

count = [0]*N
num = [0]*2
for i in range(2):
    value = 0
    for j in range(N):
        if (S[j]+value)*((-1)**(i+j)) <= 0:
            num[i] += abs(S[j] + value - (-1)**(i+j))
            value += (-1)**(i+j) - (S[j]+value)
        #print(i,num,value)

#print(S)
print(min(num))

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

y = [0, 0]
for k in range(2):
    s = 0
    x = (-1) ** k
    for ai in a:
        si = s + ai
        if si * x > 0:
            s = si
            x *= -1
        else:
            y[k] += abs(si) + 1
            s = x
            x *= -1
print(min(y))


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

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

# Example run
# Input:
237144
1761864
# Output:
0
N = int(input())
a_list = list(map(int,input().split()))

# def exec_cnt_and_s(s,i,one_is_pos):
#     if 

def count_operation(one_is_pos):
    cnt = 0
    s = 0
    for i, a in enumerate(a_list):
        s += a
        if one_is_pos:
            if i % 2 == 0:
                if s <= 0:
                    cnt += -s + 1
                    s = 1
            else:
                if s >= 0:
                    cnt += s + 1
                    s = -1
        else:
            if i % 2 == 1:
                if s <= 0:
                    cnt += -s + 1
                    s = 1
            else:
                if s >= 0:
                    cnt += s + 1
                    s = -1
    return cnt

print(min(count_operation(True),count_operation(False)))

# Example run
# Input:
-15860207
-54634663
# Output:
0
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int, input().split(' ')))

even_ans, odd_ans = 0, 0

s = 0
for i, a in enumerate(A):
    s += a

    if i % 2 == 0:
        if s > 0:
            pass
        else:
            even_ans += 1 - s
            s = 1
    else:
        if s < 0:
            pass
        else:
            pass
            even_ans += s + 1
            s = -1



s = 0
for i, a in enumerate(A):
    s += a

    if i % 2 == 1:
        if s > 0:
            pass
        else:
            odd_ans += 1 - s
            s = 1
    else:
        if s < 0:
            pass
        else:
            pass
            odd_ans += s + 1
            s = -1


print(min(even_ans, odd_ans))


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

# a[0] > 0
ans = 0
if a[0] <= 0:
    ans += -a[0] + 1
    s = 1
else:
    s = a[0]
for i in range(1, n):
    if s > 0:
        s += a[i]
        if s >= 0:
            ans += s + 1
            s = -1
    else:
        s += a[i]
        if s <= 0:
            ans += -s + 1
            s = 1
ans1 = ans

# a[0] < 0
ans = 0
if a[0] >= 0:
    ans += a[0] + 1
    s = -1
else:
    s = a[0]
for i in range(1, n):
    if s > 0:
        s += a[i]
        if s >= 0:
            ans += s + 1
            s = -1
    else:
        s += a[i]
        if s <= 0:
            ans += -s + 1
            s = 1

print(min([ans1, ans]))

# Example run
# Input:
-812896393
-97075663
# Output:
0
n = int(input())
A = list(map(int,input().split()))
ans = 10**15

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:
-412794
-447
# 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(ans1,ans2)


# Example run
# Input:
-17
-153163
# Output:
0 153164
n=int(input())

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

kp=0
asum=0
flag=-1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            kp=kp+asum+1
            asum=-1
    else:
        if asum<=0:
            kp=kp+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",kp)            
km=0
asum=0
flag=1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            km=km+asum+1
            asum=-1
    else:
        if asum<=0:
            km=km+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",km)            

print(min(kp,km))
        

# Example run
# Input:
-2458
18985674
# Output:
----- 0
----- 0
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)

print(ddd(temp,al,m,mm,res))

# Example run
# Input:
446
0
# Output:
None
n=input()
a=[int(i) for i in 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:
54C"
69
# Output:
0
input()
l=list(map(int,input().split()))
def f(b):
  c=s=0
  for i in l:
    if b:
      if s+i>0: s+=i
      else: c-=s+i-1; s=1
    else:
      if s+i<0: s+=i
      else: c+=s+i+1; s=-1
    b=1-b
  return c
print(min(f(0),f(1)))

# Example run
# Input:
a~SaT:n(B
5
# Output:
0
n = int(input())
a = list(map(int, input().split()))

s = a[0]
ans = 0

if s == 0:
	s += 1
	ans +=1

for i in range(n-1):
	if s > 0:
		s += a[i+1]
		if s >= 0:
			ans += abs(s) + 1
			s = -1
			"""
			print(i)
			print('s > 0')
			print(ans)
			print(s)
			"""
	elif s < 0:
		s += a[i+1]
		if s <= 0:
			ans += abs(s) + 1
			s = 1
			"""
			print(i)
			print('s < 0')
			print(ans)
			print(s)
			"""
print(ans)


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


def solve(A, N):
    S = [0]*N
    answer = 0
    total = 0
    for i in range(N):
        total += A[i]
        S[i] = total
        if total == 0:
            d = 1 if S[i-1] < 0 else -1
            A[i] += d
            answer += 1
            total += d
        else:
            # S[i-1] < 0 and S[i] > 0
            # S[i-1] > 0 and S[i] < 0
            # S[i-1] > 0 and S[i] > 0
            if S[i-1] < 0 and S[i] < 0:
                answer += -S[i]+1
                total += -S[i]+1
            elif S[i-1] > 0 and S[i] > 0:
                answer += S[i]+1
                total += -(S[i]+1)
        S[i] = total
        #print(i, answer, "S[i-1]=%d"%S[i-1], "S[i]=%d"%S[i], sep="\t")
    return answer

if A[0] == 0:
    A[0] = -1
    m1 = solve(A, N) + 1
    A[0] = +1
    m2 = solve(A, N) + 1
    print(min(m1, m2))
else:
    print(solve(A, N))



# Example run
# Input:
-2
-497
# Output:
0
nums = int(input())
ary = list(map(int,input().split()))

#puls no toki
count = 0
sum = ary[0]
if ary[0] < 0 :
    count += abs(ary[0])+1
    sum = 1
elif ary[0] == 0:
    sum = 1
    count += 1

for i in range (1,nums):
    sum += ary[i]

    if i % 2 == 1:
        if sum > 0 :
            count += abs(sum)+1
            sum = -1
        elif sum == 0:
            sum = -1
            count += 1
    elif i % 2 == 0:
        if sum < 0:
            count += abs(sum)+1
            sum  = 1
        elif sum == 0:
            sum = 1
            count += 1

result_plus = count

#minus no toki
count = 0
sum = ary[0]
if ary[0] > 0:
    count += abs(ary[0]) +1
    sum = -1
elif ary[0] == 0:
    sum = -1
    count += 1

for i in range(1,nums):
    sum += ary[i]
    if i % 2 == 1:
        if sum < 0:
            count += abs(sum)+1
            sum = 1
        elif sum == 0:
            count += 1
            sum = 1
    if i % 2 == 0:
        if sum > 0:
            count += abs(sum)+1
            sum = -1
        elif sum == 0:
            count += 1
            sum = -1

result_minus = count

if result_plus > result_minus:
    print(result_minus)
else:
    print(result_plus)

# Example run
# Input:
-13
367856
# Output:
0
import copy

n = int(input())
a = list(map(int,input().split()))
b = [0]

for i in range(len(a)):
    b.append(b[i] + a[i])

del b[0]

c = copy.copy(b)

first_minus = 0
first_plus = 0

for i in range(len(b)):
    if(i%2 == 0):
        if (b[i] >= 0):
            diff =  abs(b[i]) + 1
            first_minus = first_minus +  diff
            b = list(map(lambda x: x - diff, b))

        if (c[i] <= 0):
            diff =  abs(c[i]) + 1
            first_plus = first_plus +  diff
            c = list(map(lambda x: x + diff, c))
    else:
        if (b[i] <= 0):
            diff =  abs(b[i]) + 1
            first_minus = first_minus +  diff
            b = list(map(lambda x: x + diff, b))

        if (c[i] >= 0):
            diff =  abs(c[i]) + 1
            first_plus = first_plus +  diff
            c = list(map(lambda x: x - diff, c))

print(min(first_minus,first_plus))

# Example run
# Input:
-5363
1552
# Output:
0
from collections import deque

N = int(input())
A = [int(n) for n in input().split()]

def calc(a, positive):
    curr = 0
    ans = 0
    while a:
        curr += a.popleft()
        if (positive and curr <= 0) or\
           ((not positive) and curr >= 0):
            ans += abs(curr) + 1
            curr = 1 if positive else -1
        positive = not positive
    return ans

def main():
    ans = min(calc(deque(A), True), calc(deque(A), False))
    print(ans)

if __name__ == '__main__':
    main()

# Example run
# Input:
0
33729406
# Output:
0
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count3 = 0
count4 = 0
        
currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count4 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] >= 0 and restSum == 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
        
print(count4)


# Example run
# Input:
1
21507
# Output:
21508
# coding: utf-8
# Here your code



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

result_1 = 0
before_sum =a[0]
if a[0] == 0:
    before_sum = 1
    result_1 += 1
after_sum =a[0]

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if before_sum * after_sum > 0:
        if after_sum < 0:
            result_1 += 1 - after_sum
            after_sum = 1
        elif after_sum > 0:
            result_1 += 1 + after_sum
            after_sum = -1
    elif before_sum * after_sum == 0:
        result_1 += 2
        if before_sum < 0:
            after_sum = 1
        else:
            after_sum = -1

if a[0] < 0:
    before_sum = 1
elif a[0] >= 0:
    before_sum = -1
after_sum =before_sum
result_2 = 1 + abs(before_sum)

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if before_sum * after_sum > 0:
        if after_sum < 0:
            result_2 += 1 - after_sum
            after_sum = 1
        elif after_sum > 0:
            result_2 += 1 + after_sum
            after_sum = -1
    elif before_sum * after_sum == 0:
        result_2 += 2
        if before_sum < 0:
            after_sum = 1
        else:
            after_sum = -1
    print(after_sum)
    
print(min(result_1,result_2))


# Example run
# Input:
-3550
-11385106
# Output:
0
def c(ints):
    
    for i in range(len(ints)):
        if ints[i] != 0:
            sig = 1 if ints[i] > 0 else -1
            total = ints[i]
            mov = i
            j = i
            break
        if i == len(ints) - 1:
            return i + 1
    
    for i_ in ints[j+1:]:
        tmp = total + i_
        if tmp == 0:
            mov +=1
            tmp = -sig
            
        elif sig * tmp > 0:
            mov += abs(tmp) + 1
            tmp = -sig
            
        sig *= -1
        total = tmp
        
    return mov
 
_ = input()
inp = input()
inp = inp.split(' ')
inp = [int(i_) for i_ in inp]
print(c(inp))

# Example run
# Input:
SE\wL
-3978447
# 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]

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(min(ans1, ans2))


# Example run
# Input:
1
-1
# 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:
  while s0p<=0:
    s0p+=1
    countp+=1

if s0n>=0:
  while s0n>=0:
    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:
1
-255
# Output:
0
n = int(input())
a = list(map(int, input().split()))

S = 0
C = 0
S = a[0]
if S > 0:
    pm = 1
elif S < 0:
    pm = 0
else:
    S += 1
    C += 1
    pm = 1
for i in range(1, n):
    S += a[i]
    if pm == 1 and S >= 0:
        C += S + 1
        S -= S + 1
    elif pm == 0 and S <= 0:
        C += -S + 1
        S += -S + 1
    pm = 1 - pm 

T = 0
D = 0
T = a[0]
if T > 0:
    D += T + 1
    T -= T + 1
    pm = 0
elif T < 0:
    D += -T + 1
    T += -T + 1
    pm = 1
else:
    T -= 1
    D += 1
    pm = 0
for i in range(1, n):
    T += a[i]
    if pm == 1 and T >= 0:
        D += T + 1
        T -= T + 1
    elif pm == 0 and T <= 0:
        D += -T + 1
        T += -T + 1
    pm = 1 - pm

print(min(C, D))

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

sm = a[0]


def f(sm):
    ret = 0
    for e in a[1:]:
        if sm * (sm + e) < 0:
            sm += e
            continue

        else:
            if sm > 0:
                a_mx = -sm - 1
                ret += e - a_mx
                sm += a_mx
            else:
                a_mn = -sm + 1
                ret += a_mn - e
                sm += a_mn

    return ret


if sm > 0:
    ans = min(f(sm), f(-1) + sm + 1)
elif sm < 0:
    ans = min(f(sm), f(1) + sm + 1)
else:
    ans = min(f(1), f(-1)) + 1

print(ans)


# Example run
# Input:
386945
3485
# 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 += abs(now_sum) + 1
            now_sum = -1 * pre_sum / abs(pre_sum)
        pre_sum = now_sum
    return int(count)

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

# Example run
# Input:
230
-32460
# Output:
0
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 15:51:53 2018

@author: maezawa
"""
def f(n, a0, cnt, sa, sign):
    a = a0[:]
    if sign == -1:
        a[0] = -a[0]
        cnt += 2*a[0]
    for i in range(n-1):
        sa += a[i]
        na = -sa//abs(sa)*(abs(sa)+1)
        if abs(a[i+1]) > abs(na) and a[i+1]*na > 0:
            continue
        else:
            cnt += abs(na-a[i+1])
            a[i+1] = na
    return cnt

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

cnt0 = f(n, a, cnt, sa, -1)

cnt1 = f(n, a, cnt, sa, 1)
cnt = min([cnt0,cnt1])
print(cnt)
    

# Example run
# Input:
-8951
11
# Output:
-22
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    target = {1, -1}
    results = set()
    for sign in target:
        total = 0
        ans = 0
        for an in a:
            total += an
            if sign != ((total > 0) - (total < 0)):
                ans -= (total - sign) * sign
                total = sign
            sign *= -1
        results.add(ans)

    print(min(results))


if __name__ == "__main__":
    main()


# Example run
# Input:
38
-52564348
# Output:
0
n = int(input())
a = list(map(int,input().split()))
A = a[:]
count_plus=0
count_minus=0
x = 0
y = 0
for i in range(n):
  if i%2==0:
    x+=a[i]
    if x<0:
      count_plus+=-1*x+1
      a[i]+=-1*x+1
      x+=-1*x+1
  else:
    x+=a[i]
    if x>0:
      count_plus+=x+1
      a[i]+=-1*x-1
      x+=-1*x-1   
for i in range(n):
  if i%2==0:
    y+=A[i]
    if y>0:
      count_minus+=y+1
      A[i]+=-1*y-1
      y+=-1*y-1
  else:
    y+=A[i]
    if y<0:
      count_minus+=-1*y+1
      A[i]+=-1*y+1
      y+=-1*y+1
if x==0:
  count_plus+=1
if y==0:
  count_minus+=1
print(min(count_plus,count_minus))

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

sum = a[0]
count = 0

for i in range(1, n) :
    temp = sum
    sum += a[i]
    if temp > 0 and sum > 0 :
        count += sum + 1
        sum = -1
    elif temp < 0 and sum < 0 :
        count += -sum + 1
        sum = 1

if sum == 0 :
    count += 1

print(count)


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

def search(x):#x=0,1
    tmp=0
    cnt=0
    for i in range(n):
        tmp+=a[i]
        if i%2==x:
            if tmp<=0:
                cnt+=1-tmp
                tmp=1              
        else:
            if tmp>=0:
                cnt+=tmp+1
                tmp=-1
    return cnt

print(min(search(0),search(1)))

# Example run
# Input:
0
605260
# Output:
0
def solve():

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

    i = 0
    sum = 0

    ans = 0

    for i in range(n-1):
        sum += a[i]
        if sum > 0 and sum+a[i+1] > 0:
            tmp = -1 - sum
            ans += abs(tmp - a[i+1])
            a[i+1] = tmp
        elif sum < 0 and sum+a[i+1] < 0:
            tmp = 1 - sum
            ans += abs(tmp - a[i+1])
            a[i+1] = tmp

    print(ans)
    print(a)            

if __name__ ==  "__main__":
    solve()


# Example run
# Input:
-525059
89101055
# Output:
0
[89101055]
def sign(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    else:
        return 0


n = int(input())
a = [int(i) for i in input().split()]
s = [sum(a[:i+1]) for i in range(n)]
sp = [s[i] for i in range(n)]
sm = [s[i] for i in range(n)]
P0=0
M0=0
if s[0]==0:
    P0+=1
    M0+=1
    for j in range(n):
        sp[j]+=1
        sm[j]+=1
elif s[0]>0:
    M0+=abs(s[0]+1)
    for j in range(n):
        sm[j]-=(abs(s[0])+1)
else:
    P0+=abs(s[0]+1)
    for j in range(n):
        sp[j]+=(abs(s[0])+1)
for i in range(1,n):
    if sm[i-1]*sm[i]>=0:
        M0+=abs(sm[i])+1
        h=sign(sm[i-1])*(-1)*(abs(sm[i])+1)
        for j in range(i,n):
            sm[j]+=h
    if sp[i-1]*sp[i]>=0:
        P0+=abs(sp[i])+1
        h=sign(sp[i-1])*(-1)*(abs(sp[i])+1)
        for j in range(i,n):
            sp[j]+=h
print(min([M0,P0]))


# Example run
# Input:
1288
-11392175
# Output:
11394748
n = int(input())
A = list(map(int, input().split()))

ans1 = 0
sum = A[0]
for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        fugo = sum // abs(sum)
        nextsum = - fugo
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum += a_should_be
        ans1 += dif

#print(ans1)

#A[0]を反転したほうがいいパターンの処理
ans2 = A[0] + 1
sum = - (A[0] // abs(A[0]))

for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        fugo = sum // abs(sum)
        nextsum = - fugo
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum += a_should_be
        ans2 += dif
        
#print(ans2) 
print(min(ans1, ans2))


# Example run
# Input:
2563
2147483647
# Output:
0