qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
n = int(input())
sa = input().split()

a = [0 for i in range(n)]
sumeven = 0
sumodd = 0
for i,sai in enumerate(sa):
    a[i] = int(sai)

    if i % 2 == 0:
        sumeven += a[i]
    else:
        sumodd += a[i]

ret = 0
sm = 0
for i,ai in enumerate(a):
    if i % 2 == 1:
            ret += max(-sm+1-ai,0)
            sm += max(ai, -sm+1)
        else:
            ret += max(sm+1 + ai, 0)
            sm += min(ai, -(sm+1))
ret2 = 0
sm = 0
for i,ai in enumerate(a):
    if i % 2 == 0:
        ret2 += max(-sm+1-ai,0)
        sm += max(ai, -sm+1)
    else:
        ret2 += max(sm+1 + ai, 0)
        sm += min(ai, -(sm+1))
        
print(max(ret,ret2))
    

# Fixed code:
n = int(input())
sa = input().split()

a = [0 for i in range(n)]
sumeven = 0
sumodd = 0
for i,sai in enumerate(sa):
    a[i] = int(sai)

    if i % 2 == 0:
        sumeven += a[i]
    else:
        sumodd += a[i]

ret = 0
sm = 0
for i,ai in enumerate(a):
    if i % 2 == 1:
        ret += max(-sm+1-ai,0)
        sm += max(ai, -sm+1)
    else:
        ret += max(sm+1 + ai, 0)
        sm += min(ai, -(sm+1))
ret2 = 0
sm = 0
for i,ai in enumerate(a):
    if i % 2 == 0:
        ret2 += max(-sm+1-ai,0)
        sm += max(ai, -sm+1)
    else:
        ret2 += max(sm+1 + ai, 0)
        sm += min(ai, -(sm+1))
        
print(min(ret,ret2))
# Buggy code:
n = int(input())
a = list(map(int,input().split()))

ttl = a[0]
cst = 0

if a[0]>0:
    flg = 1

elif a[0]<0:
    flg = -1

for i in range(1,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
   


ttl = a[0]
cst2 = 0


   

print(min(cst,cst2))



# Fixed code:
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))
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

s_pos = 0
s_neg = 0

# start neg val
cum = 0
for i in range(n):
    cum += a[i]
    if i % 2 == 0 and cum >= 0:
        s_neg += abs(cum) + 1
        cum = -1
    if i % 2 != 0 and cum <= 0:
        s_neg += abs(cum) + 1
        cum = 1

# start pos val
cum = 0
for i in range(n):
    cum += a[i]
    if i % 2 == 0 and cum <= 0:
        s_pos += abs(cum) + 1
        cum = -1
    if i % 2 != 0 and cum >= 0:
        s_pos += abs(cum) + 1
        cum = 1

ans = min(s_pos, s_neg)
print(ans)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))

s_pos = 0
s_neg = 0

# start neg val
cum = 0
for i in range(n):
    cum += a[i]
    if i % 2 == 0 and cum >= 0:
        s_neg += abs(cum) + 1
        cum = -1
    if i % 2 != 0 and cum <= 0:
        s_neg += abs(cum) + 1
        cum = 1

# start pos val
cum = 0
for i in range(n):
    cum += a[i]
    if i % 2 == 0 and cum <= 0:
        s_pos += abs(cum) + 1
        cum = 1
    if i % 2 != 0 and cum >= 0:
        s_pos += abs(cum) + 1
        cum = -1

ans = min(s_pos, s_neg)
print(ans)
# Buggy code:
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))


# Fixed code:
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))
# Buggy code:
n = int(input())
a = [int(a) for a in input().split()]

def f(times, prefix_sum):
    for i in range(1, n):
        if prefix_sum < 0:
            if prefix_sum + a[i] > 0:
                prefix_sum += a[i]
            else:
                times += 1 - (prefix_sum + a[i])
                prefix_sum = 1      
        elif prefix_sum > 0:
            if prefix_sum + a[i] < 0:
                prefix_sum += a[i]
            else:
                times += abs(-1 - (prefix_sum + a[i]))
                prefix_sum = -1
    
    return times

t1 = 0
p1 = a[0]

t2 = 0
if a[0] > 0:
    t2 += abs(-1 - a[0])
    p2 = -1
elif a[0] < 0:
    t2 += 1 - a[0]
    p2 = 1
else:  # a[0] == 0
    t1 = 1
    p1 = -1
    t2 = 1
    p2 = 1

print(min(f(t1, p1), t2))

# Fixed code:
n = int(input())
a = [int(a) for a in input().split()]

def f(times, prefix_sum):
    for i in range(1, n):
        if prefix_sum < 0:
            if prefix_sum + a[i] > 0:
                prefix_sum += a[i]
            else:
                times += 1 - (prefix_sum + a[i])
                prefix_sum = 1      
        elif prefix_sum > 0:
            if prefix_sum + a[i] < 0:
                prefix_sum += a[i]
            else:
                times += abs(-1 - (prefix_sum + a[i]))
                prefix_sum = -1
    
    return times

if a[0] > 0:
    t1 = 0
    p1 = a[0]
else:
    t1 = 1 - a[0]
    p1 = 1


if a[0] < 0:
    t2 = 0
    p2 = a[0]
else:
    t2 = abs(-1 - a[0])
    p2 = -1
    

print(min(f(t1, p1), f(t2, p2)))
# Buggy code:
from functools import lru_cache
n = int(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()))


# Fixed code:
from functools import lru_cache
n = int(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()))
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
rui = [0] * n
cnt = 0
if a[0] > a[1]:
    rui[0] = a[0]
else:
    if a[0] >= 0:
        rui[0] = -1
        cnt += a[0] + 1
    else:
        rui[0] = 1
        cnt += abs(a[0]) + 1

for i in range(1, n):
    tmp = rui[i - 1] + a[i]
    if tmp == 0:
        if rui[i - 1] > 0:
            rui[i] = tmp - 1
            cnt += 1
        else:
            rui[i] = tmp + 1
            cnt += 1
    else:
        if rui[i - 1] > 0 and tmp > 0:
            rui[i] = -1
            cnt += abs(tmp) + 1
        elif rui[i - 1] < 0 and tmp < 0:
            rui[i] = 1
            cnt += abs(tmp) + 1
        else:
            rui[i] = tmp

print(cnt)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
rui = [0] * n
cnt = 0
if a[0] > 0:
    rui[0] = a[0]
else:
    rui[0] = 1
    cnt += abs(a[0]) + 1
for i in range(1, n):
    tmp = rui[i - 1] + a[i]
    if tmp == 0:
        if rui[i - 1] > 0:
            rui[i] = tmp - 1
            cnt += 1
        else:
            rui[i] = tmp + 1
            cnt += 1
    else:
        if rui[i - 1] > 0 and tmp > 0:
            rui[i] = -1
            cnt += abs(tmp) + 1
        elif rui[i - 1] < 0 and tmp < 0:
            rui[i] = 1
            cnt += abs(tmp) + 1
        else:
            rui[i] = tmp

cnt1 = 0
if a[0] < 0:
    rui[0] = a[0]
else:
    rui[0] = -1
    cnt1 += abs(a[0]) + 1
for i in range(1, n):
    tmp = rui[i - 1] + a[i]
    if tmp == 0:
        if rui[i - 1] > 0:
            rui[i] = tmp - 1
            cnt1 += 1
        else:
            rui[i] = tmp + 1
            cnt1 += 1
    else:
        if rui[i - 1] > 0 and tmp > 0:
            rui[i] = -1
            cnt1 += abs(tmp) + 1
        elif rui[i - 1] < 0 and tmp < 0:
            rui[i] = 1
            cnt1 += abs(tmp) + 1
        else:
            rui[i] = tmp

print(min(cnt, cnt1))
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

# +, -, +, -, ...
sum = 0
count = 0
for i in range(n):
    sum += a[i]
    if i % 2 == 0:
        if sum <= 0:
            sum = 1
            count += abs(sum) + 1
    else:
        if sum >= 0:
            sum = -1
            count += abs(sum) + 1

# -, +, -, +, ...
sum2 = 0
count2 = 0
for i in range(n):
    sum2 += a[i]
    if i % 2 == 0:
        if sum2 >= 0:
            sum2 = -1
            count2 += abs(sum2) + 1
    else:
        if sum2 <= 0:
            sum2 = 1
            count2 += abs(sum2) + 1
            
print(min(count, count2))


# Fixed code:
n = int(input())
a = list(map(int, input().split()))

# +, -, +, -, ...
sum = 0
count = 0
for i in range(n):
    sum += a[i]
    if i % 2 == 0:
        if sum <= 0:
            count += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            count += abs(sum) + 1
            sum = -1

# -, +, -, +, ...
sum2 = 0
count2 = 0
for i in range(n):
    sum2 += a[i]
    if i % 2 == 0:
        if sum2 >= 0:
            count2 += abs(sum2) + 1
            sum2 = -1
    else:
        if sum2 <= 0:
            count2 += abs(sum2) + 1
            sum2 = 1

print(min(count, count2))
# Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
tmp1 = 0
tmp2 = 0
S = [0]*n

if a[0] > 0:
  S[0] = a[0]
else:
  S[0] = 1
  tmp1 += abs(1-a[0])
  
for i in range(1,n):
  tmpS = a[i] + S[i-1]
  if tmpS*S[i-1] < 0:
    S[i] = tmpS
    continue
  else:
    if i%2 == 0:
      S[i] = 1
      tmp1 += abs(1 - tmpS)
    else:
      S[i] = -1
      tmp1 += abs(-1-tmpS)
if a[0] < 0:
  S[0] = a[0]
else:
  S[0] = -1
  tmp2 += abs(-1-a[0])

for i in range(1,n):
  tmpS = a[i] + S[i-1]
  if tmpS*S[i-1] < 0:
    continue
  else:
    if i%2 == 1:
      S[i] = -1
      tmp2 += abs(-1 - tmpS)
    else:
      S[i] = 1
      tmp2 += abs(1-tmpS)
print(min(tmp1,tmp2))

# Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
tmp1 = 0
tmp2 = 0
S = [0]*n

if a[0] > 0:
  S[0] = a[0]
else:
  S[0] = 1
  tmp1 += abs(1-a[0])
  
for i in range(1,n):
  tmpS = a[i] + S[i-1]
  if tmpS*S[i-1] < 0:
    S[i] = tmpS
    continue
  else:
    if i%2 == 0:
      S[i] = 1
      tmp1 += abs(1 - tmpS)
    else:
      S[i] = -1
      tmp1 += abs(-1-tmpS)
if a[0] < 0:
  S[0] = a[0]
else:
  S[0] = -1
  tmp2 += abs(-1-a[0])
for i in range(1,n):
  tmpS = a[i] + S[i-1]
  if tmpS*S[i-1] < 0:
    S[i] = tmpS
    continue
  else:
    if i%2 == 0:
      S[i] = -1
      tmp2 += abs(-1 - tmpS)
    else:
      S[i] = 1
      tmp2 += abs(1-tmpS)
print(min(tmp1,tmp2))
# Buggy code:
n=int(input())
b=list(map(int,input().split()))
a=b[:]
condition=''
cnt=0
wa=0
for i in range(n):
  wa+=a[i]
  if i == 0:
    if a[i]>0:
      condition='minus'
    else:
      condition='plus'
  elif condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt1=cnt
a=b[:]
condition=''
cnt=0
wa=0
for i in range(n):
  a[i]=a[i]/abs(a[i])*(-1)
  cnt+=abs(a[i])+1
  wa+=a[i]
  if i == 0:
    if a[i]>0:
      condition='minus'
    else:
      condition='plus'
  elif condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt2=cnt
print(min(cnt1,cnt2))

# Fixed code:
n=int(input())
b=list(map(int,input().split()))
a=b[:]

cnt=0
wa=0
condition='plus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt1=cnt
a=b[:]
cnt=0
wa=0
condition='minus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt2=cnt
print(min(cnt1,cnt2))
# Buggy code:
n = int(input())
a = list(map(int, input().split(' ')))
result = 0
h = 0
if a[0] == 0:
    counter += 1
    result += 1
else:
    counter += a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result +=1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result += 1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out = []
out.append(result)
result = 0
counter = 0
if a[0] == 0:
    counter -= 1
    result +=1
elif a[0]< 0:
    counter += 1
    result += 1-a[0]
else:
    counter -= 1
    result += 1+a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result += 1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result +=1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out.append(result)
print(min(out))

# Fixed code:
n = int(input())
a = list(map(int, input().split(' ')))
result = 0
counter = 0
if a[0] == 0:
    counter += 1
    result += 1
else:
    counter += a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result +=1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result += 1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out = []
out.append(result)
result = 0
counter = 0
if a[0] == 0:
    counter -= 1
    result +=1
elif a[0]< 0:
    counter += 1
    result += 1-a[0]
else:
    counter -= 1
    result += 1+a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result += 1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result +=1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out.append(result)
print(min(out))
# Buggy code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = -max(0, ~a[0])
sm = 1
if a[0] > 1: sm = a[0]
for i in range(1, N):
  if sm > 0:
    res += max(0, a[i] + sm + 1)
    sm = min(-1, a[i])
  else:
    res += max(0, sm - a[i] + 1)
    sm = max(1, a[i])
res2 = max(0, a[0] + 1)
sm = -1
if a[0] < -1: sm = a[0]
for i in range(1, N):
  if sm > 0:
    res2 += max(0, a[i] + sm + 1)
    sm = min(-1, a[i])
  else:
    res2 += max(0, sm - a[i] + 1)
    sm = max(1, a[i])
print(min(res, res2))

# Fixed code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = max(0, -a[0] + 1)
sm = 1
if a[0] >= 1:
  res = 0
  sm = a[0]
#print(res, sm)
for i in range(1, N):
  if sm > 0:
    res += max(-1, a[i] + sm) + 1
    sm = min(-1, sm + a[i])
  else:
    res += -min(1, sm + a[i]) + 1
    sm = max(1, sm + a[i])
  #print(res, sm)
res2 = max(0, a[0] + 1)
sm = -1
if a[0] <= -1:
  res2 = 0
  sm = a[0]
for i in range(1, N):
  if sm > 0:
    res2 += max(-1, a[i] + sm) + 1
    sm = min(-1, sm + a[i])
  else:
    res2 += -min(1, sm + a[i]) + 1
    sm = max(1, sm + a[i])
  #print(res2, sm)
#print(res, res2)
print(min(res, res2))
# Buggy code:
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)

# Fixed code:
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))
# Buggy code:
n = int(input())
a = [int(x) for x in input().split()]

def odd_positive(List, n):
    sum_a = 0
    cost = 0
    for a in List:
        nextsum = sum_a + a
        if i & 1 and nextsum <= 0:
            cost = - nextsum + 1
            sum_a = 1
        elif (not i & 1) and nextsum >= 0:
            cost = nextsum + 1
            sum_a = -1
    return cost


def odd_negative(List, n):
    sum_a = 0
    cost = 0
    for a in List:
        nextsum = sum_a + a
        if i & 1 and nextsum >= 0:
            cost = nextsum + 1
            sum_a = -1
        elif (not i & 1) and nextsum <= 0:
            cost = - nextsum + 1
            sum_a = 1
    return cost
    
ans = min(odd_positive(a,n), odd_negative(a,n)) 
print(ans)


# Fixed code:
n = int(input())
a = [int(x) for x in input().split()]

def odd_positive(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
        elif (not i & 1) and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
    return cost


def odd_negative(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
        elif (not i & 1) and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
    return cost
    
ans = min(odd_positive(a), odd_negative(a)) 
print(ans)
# Buggy code:
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
ans = [0, 0]
s = li[0]
for j in range(2):
    code = j
    for i in range(n - 1):
        code = 1 - code
        if code:
            if s + li[i + 1] > 0:
                s += li[i + 1]
            else:
                ans[j] += abs(s * (-1) + 1 - li[i + 1])
                s = 1
        else:
            if s + li[i + 1] < 0:
                s += li[i + 1]
            else:
                ans[j] += abs(s * (-1) - 1 - li[i + 1])
                s = -1
print(min(ans))




# Fixed code:
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
ans = [0, 0]
for j in range(2):
    tmp = j
    s = 0
    for i in range(n):
        tmp = 1 - tmp
        s += li[i]
        if tmp:
            if s <= 0:
                d = abs(s - 1)
                ans[j] += d
                s = 1
        else:
            if s >= 0:
                d = abs(s - (-1))
                ans[j] += d
                s = -1
print(min(ans))
# Buggy code:
N = int(input())
*A, = map(int,input().split())
ans1 = 0
S = A[0]
if S <= 0:
    S = 1
    ans1 = -S+1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans1 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
ans2 = 0
S = A[0]
if S >= 0:
    S = -1
    ans1 = -S+1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans2 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
print(min(ans1,ans2))

# Fixed code:
N = int(input())
*A, = map(int,input().split())
ans1 = 0
S = A[0]
if S <= 0:
    ans1 = abs(S)+1
    S = 1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans1 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
ans2 = 0
S = A[0]
if S >= 0:
    ans2 = abs(S)+1
    S = -1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans2 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
print(min(ans1,ans2))