CodeEff/ECCO huggingface dataset:
# Original solution
nums = int(eval(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)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
count = 0
check = 0

for i in range(n):
    check += a[i]
    if i%2==0 and check <= 0:
        count += 1-check
        check =  1
    elif i%2==1 and check >= 0:
        count += 1+check
        check = -1
ans = count
count = 0
check = 0

for i in range(n):
    check += a[i]
    if i%2==0 and check >= 0:
        count += 1+check
        check = -1
    if i%2==1 and check <= 0:
        count += 1-check
        check = 1
print((ans if ans < count else count))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

ans = 0
"""
if a[0] == 0:
  #a[1] とa[0]を足して|1|かつa[0]とa[1]+a[0]の符号を逆にしたい
  if a[1] > 0:
    a[0] = 1 - a[1]    
  elif a[1] < 0:
    a[0] = -1 - a[1]
  else: # a[0] a[1] 共に0の場合、a[2]に依存する　-> 両方やればいい
奇数番目と偶数ばんめのどちらを＋にするか  
"""
ans_odd = 0
total_odd = 0
ans_even = 0
total_even = 0
for i in range(n):
  if (i+1) % 2 == 1: #奇数ばんめ
    #奇数番目を＋、偶数番目を-にするパターン
    total_odd += a[i]
    if total_odd <= 0:
      ans_odd += abs(total_odd) + 1
      total_odd = 1
      
    #偶数番目を＋、奇数番目を-にするパターン
    total_even += a[i]
    if total_even >= 0:
      ans_even += (abs(total_even)+1)
      total_even = -1
      
  else: #偶数番目
    #奇数番目を＋、偶数番目を-にするパターン
    total_odd += a[i]
    if total_odd >= 0:
      ans_odd += abs(total_odd)+1
      total_odd = -1
      
    #偶数番目を＋、奇数番目を-にするパターン
    total_even += a[i]
    if total_even <= 0:
      ans_even += abs(total_even)+1
      total_even = 1
  """    
  print("total,ans_odd")    
  print(total_odd)
  print(ans_odd)
  print("total,ans_even")
  print(total_even)
  print(ans_even)
  """   
print((min([ans_odd, ans_even])))
#print()

# Optimized solution

N = int(eval(input()))

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


#奇数番目を負にする場合
odd = 0
total = 0
for i in range(N):
    total += A[i]
    if i % 2 == 0: #奇数番目の場合
        if total > -1:
            odd += 1 + total
            total = -1
    else:
        if total < 1:
            odd += 1 - total
            total = 1

#偶数番目を負にする場合
even = 0
total = 0
for i in range(N):
    total += A[i]
    if i % 2 == 0: #奇数番目の場合
        if total < 1:
            even += 1 - total
            total = 1
    else:
        if total > -1:
            even += 1 + total
            total = -1


print((min(odd, even)))
# Original solution
import sys
input = sys.stdin.readline

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

b = a[:]
acc = 0

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

c = a[:]
acc = 0

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

ans = min(sum(abs(ai-bi) for ai, bi in zip(a, b)), sum(abs(ai-ci) for ai, ci in zip(a, c)))

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
a = list(map(int, input().split()))
cnt1, now = 0, 0

for i in range(n):
    now += a[i]
    
    if i%2==0:
        if now<=0:
            cnt1 += 1-now
            now = 1
    else:
        if now>=0:
            cnt1 += now+1
            now = -1
    
cnt2, now = 0, 0

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

print((min(cnt1, cnt2)))
# Original solution
import copy
n = int(eval(input()))
a = list(map(int, input().split()))

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
tmp_sum = a1[0]
operate_num1 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num1 =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] += tmp_operate_num1
    else:
        tmp_operate_num1 = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] -= tmp_operate_num1
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
tmp_sum = a2[0]
operate_num2 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num2 =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] -= tmp_operate_num2
        tmp_sum -= tmp_operate_num2
    else:
        tmp_operate_num2 = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] += tmp_operate_num2
        tmp_sum += tmp_operate_num2
    tmp_sum += a2[i]
print((min(operate_num1, operate_num2)))        


# Optimized solution
import copy
n = int(eval(input()))
a = list(map(int, input().split()))

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
operate_num1 = 0
if a1[0]==0:
    a1[0] = 1
    operate_num1 += 1
tmp_sum = a1[0]
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num
        a1[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num
        a1[i] -= tmp_operate_num
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
operate_num2 = 0
if a2[0]<0:
    operate_num2 += 1 - a2[0]
    a2[0] += operate_num2
else:
    operate_num2 += a2[0] + 1
    a2[0] -= operate_num2

tmp_sum = a2[0]

for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num
        a2[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num
        a2[i] -= tmp_operate_num
    tmp_sum += a2[i]

print((min(operate_num1, operate_num2)))
# Original solution
N = int(eval(input()))
arr = list(map(int,input().split()))
def S1(a,b):
    c,last,ans = 0,0,0
    for t in range(N):
        c += 1
        if c % 2 == a:
            while last+arr[t] <= 0:
                ans += 1
                last += 1
        elif c % 2 == b:
            while last +arr[t] >= 0:
                ans +=1
                last -= 1
        last += arr[t]
    return ans
aa = S1(1,0)
bb = S1(0,1)
print((min(aa,bb)))

# Optimized solution
N = int(eval(input()))
arr = list(map(int,input().split()))
def S1(a,b):
    c,total,ans = 0,0,0
    for t in arr:
        c += 1
        if c % 2 == a:
            if total+t <= 0:
                ans += abs(total+t)+1
                total = 1
                continue
        elif c % 2 == b:
            if total+t >= 0:
                ans += abs(total+t)+1
                total = -1
                continue
        total += t
    return ans
print((min(S1(1,0),S1(0,1))))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = [a_ for a_ in a]
 
ans = 10**14
for a0 in [-1,a[0],1]:
    if a0 == 0:
        continue
    ans_ = abs(a[0]-a0)
    b[0] = a0
    sign = b[0] > 0
    for i in range(1,n):
        b[i] = a[i]+b[i-1]
        if sign:
            if b[i] >= 0:
                ans_ += b[i]+1
                b[i] = -1
        else:
            if b[i] <= 0:
                ans_ += 1-b[i]
                b[i] = 1
        sign = not sign
    ans = min(ans, ans_)
print(ans)

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
 
def adj(n, a ,flag):
    na = 0
    cnt = 0
    for i in range(n):
        na += a[i]
        if flag == 1:
            if na <= 0:
                cnt += 1 - na
                na = 1
            flag = -1
        
        elif flag == -1:
            if na >= 0:
                cnt += na + 1
                na = -1
            flag = 1
    return cnt            

print((min(adj(n, A, 1),adj(n, A, -1))))
# Original solution
n=int(eval(input()))
a=list(map(int, input().split()))
sum_now=a[0]
sum_before=-a[0]
count_1=0
count_2=0
for i in range(n):
    while sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=-a[1]/abs(a[1])
            count_1+=1
        else:
            count_1+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]

sum_now=a[0]
sum_before=-a[0]
if sum_before==0:
    sum_now=a[1]/abs(a[1])
    sum_before=-sum_now
    count_2+=1
else:
    count_2+=abs(int(sum_now))+1
    sum_now=-sum_now/abs(sum_now)
    sum_before=-sum_now
for i in range(n):
    while sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=a[1]/abs(a[1])
            count_2+=1
        else:
            count_2+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]
print((min(count_1, count_2)))

# Optimized solution
n=int(eval(input()))
a=list(map(int, input().split()))
sum_now=a[0]
sum_before=-a[0]
count_1=0
count_2=0
for i in range(n):
    if sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=-a[1]/abs(a[1])
            count_1+=1
        else:
            count_1+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]

sum_now=a[0]
sum_before=-a[0]
if sum_before==0:
    sum_now=a[1]/abs(a[1])
    sum_before=-sum_now
    count_2+=1
else:
    count_2+=abs(int(sum_now))+1
    sum_now=-sum_now/abs(sum_now)
    sum_before=-sum_now
for i in range(n):
    if sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=a[1]/abs(a[1])
            count_2+=1
        else:
            count_2+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]
print((min(count_1, count_2)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = A.copy()

gokei = 0
ans1 = 0

for i in range(N):
    gokei = sum(A[:i+1])
    # 偶数番目を負に
    if i % 2 == 0:
        if gokei >= 0:
            ans1 += abs(-1 - gokei)
            A[i] -= abs(-1 - gokei)
    if i % 2 == 1:
        if gokei <= 0:
            ans1 += 1 - gokei
            A[i] += (1 - gokei)


gokei = 0
ans2 = 0
for i in range(N):
    gokei = sum(B[:i+1])
    # 偶数番目を正に
    if i % 2 == 0:
        if gokei <= 0:
            ans2 += 1 - gokei
            B[i] += (1 - gokei)
    else:
        if gokei >= 0:
            ans2 += abs(-1 - gokei)
            B[i] -= abs(-1 - gokei)

print((min(ans1, ans2)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

gokei = 0
ans1 = 0

for i in range(N):
    gokei += A[i]
    # 偶数番目を負に
    if i % 2 == 0:
        if gokei >= 0:
            ans1 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)
    if i % 2 == 1:
        if gokei <= 0:
            ans1 += 1 - gokei
            gokei += (1 - gokei)


gokei = 0
ans2 = 0
for i in range(N):
    gokei += A[i]
    # 偶数番目を正に
    if i % 2 == 0:
        if gokei <= 0:
            ans2 += 1 - gokei
            gokei += (1 - gokei)
    else:
        if gokei >= 0:
            ans2 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)

print((min(ans1, ans2)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

gokei = 0
ans1 = 0

for i in range(N):
    gokei += A[i]
    # 偶数番目を負に
    if i % 2 == 0:
        if gokei >= 0:
            ans1 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)
    if i % 2 == 1:
        if gokei <= 0:
            ans1 += 1 - gokei
            gokei += (1 - gokei)


gokei = 0
ans2 = 0
for i in range(N):
    gokei += A[i]
    # 偶数番目を正に
    if i % 2 == 0:
        if gokei <= 0:
            ans2 += 1 - gokei
            gokei += (1 - gokei)
    else:
        if gokei >= 0:
            ans2 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)

print((min(ans1, ans2)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

c = A[0]
ans1 = 0
for a in A[1:]:
    if c > 0 and c + a >= 0:
        ans1 += c + a + 1
        c = -1

    elif c < 0 and c + a <= 0:
        ans1 += -(c + a) + 1
        c = 1

    else:
        c = c + a


c = 1
ans2 = abs(A[0] - 1)
for a in A[1:]:
    if c > 0 and c + a >= 0:
        ans2 += c + a + 1
        c = -1

    elif c < 0 and c + a <= 0:
        ans2 += -(c + a) + 1
        c = 1

    else:
        c = c + a


c = -1
ans3 = abs(A[0] + 1)
for a in A[1:]:
    if c > 0 and c + a >= 0:
        ans3 += c + a + 1
        c = -1

    elif c < 0 and c + a <= 0:
        ans3 += -(c + a) + 1
        c = 1

    else:
        c = c + a

print((min(ans1, ans2, ans3)))
# Original solution
#!/usr/bin/env python3
from itertools import accumulate

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

    ans = 10**18

    for j in range(2):# 偶数行が正か奇数行が正
        ans2 = 0
        diff = 0
        for i in range(n):
            p = a[i] + diff
            # print(a[i],diff)
            if (i+j) % 2 == 0 and p <= 0:# 正になる
                ans2 += abs(p)+1
                diff += abs(p)+1
            elif (i+j) % 2 == 1 and p >= 0:# 負になる
                ans2 += abs(p)+1
                diff -= abs(p)+1

        ans = min(ans, ans2)
    print(ans)

if __name__ == "__main__":
    main()


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

# 方針:正負正...と負正負...の両方を試す
ans = 0
now = 0
for i in range(N):
    if i % 2 == 0:# 正にする
        if now+A[i] <= 0:
            ans += 1 - (now+A[i])
            now = 1
        else:
            now += A[i]
    else:
        if now+A[i] >= 0:
            ans += 1 + (now+A[i])
            now = -1
        else:
            now += A[i]
ans2 = 0
now = 0
for i in range(N):
    if i % 2 == 1:# 正にする
        if now+A[i] <= 0:
            ans2 += 1 - (now+A[i])
            now = 1
        else:
            now += A[i]
    else:
        if now+A[i] >= 0:
            ans2 += 1 + (now+A[i])
            now = -1
        else:
            now += A[i]

print((min(ans,ans2)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
sun = 0
ans1 = 0
for i in range(n):
  if i == 0:
    SUN = 1
  else:
    SUN = sun
  now = a[i]
  if SUN * (sun+now) >= 0:
    ans1 += abs(sun+now) + 1
    if SUN > 0:
      sun = -1
    else:
      sun = 1
  else:
    sun += now
sun = 0
ans2 = 0
for i in range(n):
  now = a[i]
  if i == 0:
    SUN = -1
  else:
    SUN = sun
  if SUN * (sun+now) >= 0:
    ans2 += abs(sun+now) + 1
    if SUN > 0:
      sun = -1
    else:
      sun = 1
  else:
    sun += now
#print(ans1,ans2)
print((min(ans1,ans2)))

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
can = []
ans = 0
now = 0
for i in range(n):
  now += a[i]
  if i % 2 == 0:
    if now <= 0:
      ans += 1 - now
      now = 1
  else:
    if now >= 0:
      ans += 1 + now
      now = -1
can.append(ans)
ans = 0
now = 0
for i in range(n):
  now += a[i]
  if i % 2 == 1:
    if now <= 0:
      ans += 1 - now
      now = 1
  else:
    if now >= 0:
      ans += 1 + now
      now = -1
can.append(ans)
print((min(can)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
fg=[1,-1]
ret = [0]*2
tot = [0]*2
for i in range(n):
  for j in range(2):
    tot[j]+=a[i]
    if tot[j]*fg[j]<=0:
      ret[j] += abs(fg[j] - tot[j])
      tot[j] += fg[j] - tot[j]
    fg[j]*=-1
print((min(ret)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
fg=[1,-1]
ret = [0]*2
tot = [0]*2
il = list(range(n))
jl = list(range(2))
for i in il:
  for j in jl:
    tot[j]+=a[i]
    if tot[j]*fg[j]<=0:
      ret[j] += abs(fg[j] - tot[j])
      tot[j] += fg[j] - tot[j]
    fg[j]*=-1
print((min(ret)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
fg=[1,-1]
ret = [0]*2
tot = [0]*2
il = list(range(n))
jl = list(range(2))
for i in il:
  for j in jl:
    tot[j]+=a[i]
    if tot[j]*fg[j]<=0:
      ret[j] += abs(fg[j] - tot[j])
      tot[j] += fg[j] - tot[j]
    fg[j]*=-1
print((min(ret)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
def ma():
  fg=[1,-1]
  ret = [0]*2
  tot = [0]*2
  il = list(range(n))
  jl = list(range(2))
  for i in il:
    for j in jl:
      tot[j]+=a[i]
      if tot[j]*fg[j]<=0:
        ret[j] += abs(fg[j] - tot[j])
        tot[j] += fg[j] - tot[j]
      fg[j]*=-1
  return min(ret)
print((ma()))
# Original solution
eval(input())
l=list(map(int,input().split()))
def f(s):
  c=t=0
  for i in l:
    t+=i
    if s*t<=0: c+=abs(t-s); t=s
    s*=-1
  return c
print((min(f(1),f(-1))))

# Optimized solution
_,*l=list(map(int,open(0).read().split()))
def f(s):
  c=t=0
  for i in l:
    t+=i
    if s*t<=0: c+=abs(t-s); t=s
    s*=-1
  return c
print((min(f(1),f(-1))))
# Original solution
from functools import lru_cache
n = int(eval(input()))
s = list(map(int, input().split()))


@lru_cache(maxsize=None)
def cost_e():
    res = 0
    sum = 0
    for j, y in enumerate(s, 1):
        tmp = sum + y
        if j & 1 and tmp >= 0:
            sum = -1
            res += abs(tmp) + 1
        elif not j & 1 and tmp <= 0:
            sum = 1
            res += abs(tmp) + 1
        else:
            sum = tmp
    return res


@lru_cache(maxsize=None)
def cost_o():
    res = 0
    sum = 0
    for j, y in enumerate(s, 1):
        tmp = sum + y
        if j & 1 and tmp <= 0:
            sum = 1
            res += abs(tmp) + 1
        elif not j & 1 and tmp >= 0:
            sum = -1
            res += abs(tmp) + 1
        else:
            sum = tmp
    return res


print((min(cost_e(), cost_o())))


# Optimized solution
n = int(eval(input()))
s = list(map(int, input().split()))


def cost(t):
    res = 0
    sum = 0
    for y in s:
        sum += y
        if sum * t <= 0:
            res += abs(sum - t)
            sum = t
        t *= -1
    return res


print((min(cost(1), cost(-1))))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
import copy
a2 = copy.copy(a)

ans1 = 0 #偶数インデックスが正
for i in range(n):
    s1 = sum(a[:i+1])
    if i % 2 == 0:
        if s1 <= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] += x
        else:
            continue
    else:
        if s1 >= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    s2 = sum(a2[:i+1])
    if i % 2 == 1:
        if s2 <= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] += x
        else:
            continue
    else:
        if s2 >= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] -= x

print((min(ans1, ans2)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

ans = 0
sm = 0
for i in range(n):
    if i % 2 == 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
    if i % 2 != 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
print((min(ans, ans1)))


# Optimized solution
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
sm = 0
for i in range(n):
    if i % 2 == 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
    if i % 2 != 0:
        if sm + A[i] > 0:
            sm += A[i]
        elif sm + A[i] <= 0:
            num = -(sm + A[i]) + 1
            sm += A[i] + num
            ans += num
    else:
        if sm + A[i] < 0:
            sm += A[i]
        elif sm + A[i] >= 0:
            num = -(sm + A[i]) - 1
            sm += A[i] + num
            ans += -num
print((min(ans, ans1)))
# Original solution
n,a=int(eval(input())),list(map(int,input().split()));ans=0
if a[0]==0:
  bol=True
  for i in range(1,n):
    if a[i-1]!=a[i]:
      bol=False
      if a[i]>0:a[0]=(1if i%2==0else-1)
      else:a[0]=(1if i%2!=0else-1)
    ans+=1;break
  if bol:print((n*2-1));exit()
b=[a[0]];m=("+"if a[0]<0else"-")
for i in range(1,n):
  while b[-1]*(b[-1]+a[i])>=0:
    ans+=1
    a[i]+=eval(m+"1")
  b.append(b[-1]+a[i])
  m=("+"if b[i]<0else"-")
print(ans)

# Optimized solution
n=int(eval(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)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
count=0
if a[0]>0:
  for i in range(n):
    if i%2==0:
      if sum(a[:i+1])<0:
        count+=-1*sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])+1
    else:
      if sum(a[:i+1])>0:
        count+=sum(a[:i+1])+1
        a[i]-=sum(a[:i+1])-1
else:
  for i in range(n):
    if i%2==0:
      if sum(a[:i+1])>0:
        count+=sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])-1
    else:
      if sum(a[:i+1])<0:
        count+=-1*sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])+1
if sum(a)==0:
  count+=1
print(count)

# Optimized solution
n=eval(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))))