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

ans = 0
ans_2 = 0
o = 0
for i in range(n):
    if i == 0:
        if a[i] == 0:
            f = "+"
            a[i] = 1
        elif a[0] > 0:
            f = "+"
        elif a[0] < 0:
            f = "-"
    else:
        o += a[i-1]
        if f == "+":
            if a[i] + o > 0:
                c = -1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "-"
            else:
                if a[i] + o == 0:
                    a[i] -= 1
                    ans += 1
                f = "-"
        elif f == "-":
            if a[i] + o < 0:
                c = 1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "+"
            else:
                if a[i] + o == 0:
                    a[i] += 1
                    ans += 1
                f = "+"
a = a_1
for i in range(n):
    if i == 0:
        if a[i] == 0:
            f = "+"
            a[i] = 1
        elif a[0] > 0:
            f = "-"
        elif a[0] < 0:
            f = "+"
    else:
        o += a[i-1]
        if f == "+":
            if a[i] + o > 0:
                c = -1 - o
                ans_2 += abs(c - a[i])
                a[i] = c
                f = "-"
            else:
                if a[i] + o == 0:
                    a[i] -= 1
                    ans += 1
                f = "-"
        elif f == "-":
            if a[i] + o < 0:
                c = 1 - o
                ans_2 += abs(c - a[i])
                a[i] = c
                f = "+"
            else:
                if a[i] + o == 0:
                    a[i] += 1
                    ans += 1
                f = "+"
print(a)
print(min(ans,ans_2))


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

# a[0]の符号を正にするか負にするかの2択で
# 後は一意に決まる

_sum = 0
count = 0
out = 0
# a[0]の符号を正にする場合
if a[0] <= 0:
    count += a[0] - (-1)
    _sum = 1
else:
    _sum = a[0]
# print("count:{} sum:{}".format(count, _sum))
for i in range(1, len(a)):
    if i % 2 == 1:
        # a[i]までの和を負にする
        # a[i] >= 0なら「-1」にする
        if _sum + a[i] >= 0:
            count += _sum + a[i] - (-1)
            _sum = -1
        else:
            _sum += a[i]
    else:
        # a[i]までの和を正にする
        # a[i] <= 0なら「1」にする
        if _sum + a[i] <= 0:
            count += 1 - (_sum + a[i])
            _sum = 1
        else:
            _sum += a[i]
    # print("count:{} sum:{}".format(count, _sum))
# print()
out = count
_sum = 0
count = 0
# a[0]の符号を負にする場合
if a[0] >= 0:
    count += 1 - a[0]
    _sum = -1
else:
    _sum = a[0]
# print("count:{} sum:{}".format(count, _sum))
for i in range(1, len(a)):
    if i % 2 == 0:
        # a[i]までの和を負にする
        # a[i] >= 0なら「-1」にする
        if _sum + a[i] >= 0:
            count += _sum + a[i] - (-1)
            _sum = -1
        else:
            _sum += a[i]
    else:
        # a[i]までの和を正にする
        # a[i] <= 0なら「1」にする
        if _sum + a[i] <= 0:
            count += 1 - (_sum + a[i])
            _sum = 1
        else:
            _sum += a[i]
    # print("count:{} sum:{}".format(count, _sum))
print(min(out, count))




# Example run
# Input:
-568126729
-117864
# Output:
-117863
n = int(input())
al = list(map(int, input().split())) 

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

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

    print(min(ans1,ans2))

else:
    ans3 = 0
    curr_sum = al[0]
    for a in al[1:]:
        next_sum = curr_sum + a
        if next_sum >= 0 and curr_sum > 0:
            ans3 += next_sum+1
            next_sum = -1
        elif next_sum <= 0 and curr_sum < 0:
            ans3 += (1-next_sum)
            next_sum = 1
        curr_sum = next_sum
    print(ans3)

# Example run
# Input:
295
216361
# Output:
0
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

sum = an[0]
ans = 0
for i in range(1,n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1
ans1 = ans

if an[0] > 0:
    sum = -1
else:
    sum = 1
ans = abs(an[0])+1

for i in range(1, n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1

print(ans1, ans)
print(min([ans1, ans]))


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

ans = 0
sum = A[0]
if sum == 0:
    ans = 1
    for i in range(1, len(A)):
        a = A[i]
        if a != 0:
            if i % 2 == 0:
                if a > 0:
                    sum = 1
                else:
                    sum = -1
            else:
                if a > 0:
                    sum = -1
                else:
                    sum = 1
            break

for i in range(1, len(A)):
    a = A[i]
    prev_sum = sum
    sum += a
    if sum * prev_sum >= 0:
        ans += abs(prev_sum+a)+1

        if prev_sum > 0:
            sum = -1
        else:
            sum = 1


print(ans)


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

wa=a[0]
ans1,ans2=0,0
if a[0]==0:
    ans1+=1
    wa=-1

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

if a[0]>0:
    ans2+=a[0]+1
    wa=-1
else:
    ans2+=-a[0]+1
    wa=1

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

# Example run
# Input:
-14
2
# Output:
0
if __name__ == '__main__':
    n = int(input())
    a0 = input().split()
    a = [int(i) for i in a0]
    s1 = 0
    s2 = 0
    m1 = 0
    m2 = 0
    o = 1
    e = -1
    for i in a:
        s1 += i
        if s1 == 0:
            m1 += 1
        elif o * s1 < 0:
            m1 += abs(s1) + 1
            s1 = o
        o *= -1

        s2 += i
        if s2 == 0:
            m2 += 1
        elif e * s2 < 0:
            m2 += abs(s2) + 1
            s2 = e
        e *= -1
    print(min(m1, m2))

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

sums = 0
ans = 0
# プラスがはじめ
for itr, val in enumerate(a):
  sums += val
  if itr % 2 == 0:
    if sums <= 0:
      ans += 1 - sums
      sums = 1
  else:
    if sums >= 0:
      ans += sums + 1
      sums = - 1
gans = ans

sums = 0
ans = 0
# マイナスがはじめ
for itr, val in enumerate(a):
  sums += val
  if itr % 2 != 0:
    if sums <= 0:
      ans += 1 - sums
      sums = 1
  else:
    if sums >= 0:
      ans += sums + 1
      sums = - 1
kans = ans
print(min(gans, kans))

# Example run
# Input:
-274078593
-28418
# Output:
0
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()))


# Example run
# Input:
4603979
-55009
# Output:
0
def sequence(N: int, A: list) -> int:
    op1, op2 = 0, 0
    s1, s2 = 0, 0

    for i, a in enumerate(A):
        s1, s2 = s1 + a, s2 + a

        if i % 2 > 0:  # odd
            if s1 <= 0:
                op1 += abs(s1) + 1
                s1 += abs(s1) + 1
            if s2 >= 0:
                op2 += abs(s2) + 1
                s2 -= abs(s2) + 1
        else:  # even
            if s1 >= 0:
                op1 += abs(s1) + 1
                s1 -= abs(s1) + 1
            if s2 <= 0:
                op2 += abs(s2) + 1
                s2 += abs(s2) + 1

    return min(op1, op2)


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = sequence(N, A)
    print(ans)


# Example run
# Input:
-2166
65444
# Output:
0
n=int(input())
l=[int(i) for i in input().split()]
chk1=ans1=chk2=ans2=0

for a,i in enumerate(l):
    chk1+=i
    chk2+=i
    if a%2:
        if chk1<=0:
            ans1+=1-chk1
            chk1=1
        if chk2>=0:
            ans2+=chk2+1
            chk2=-1
    else:
        if chk1>=0:
            ans1+=1+chk1
            chk1=-1
        if chk2<=0:
            ans2+=1-chk2
            chk2=1
print(min(ans1,ans2))


# Example run
# Input:
157
647084
# 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:
  s0p+=(abs(s0p)+1)
  countp+=abs(s0p)
  print(countp,abs(s0p)+1,s0p,a[0])

if s0n>=0:
  s0n-=(abs(s0n)+1)
  countn+=abs(s0n)

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:
-2264732
-112650803
# Output:
1 2 1 -112650803
0
n = int(input())
A = list(map(int, input().split()))
ans = float('inf')
# 各Aiを見ていく時 iが奇数、偶数どちらの時の和を負の数にするか
for case in range(2):
    count = 0  # 操作回数
    sum_a = 0  # Ai までの数の和
    up = case  # 和を正整数にするか
    for a in A:
        sum_a += a
        diff = 0  # a をどの程度操作するか。
        if up:  # 正整数であるべき
            if sum_a < 1:  # 1未満の数(0か負数)
                diff = 1 - sum_a
        else:  # 負整数であるべき
            if -1 < sum_a:  # -1より大きい数(0か正整数)
                diff = -1 - sum_a
        sum_a += diff  # Ai までの和に操作後の値を適用する
        count += abs(diff)  # 操作回数を加算する
        up ^= 1  # 次回は今回とは逆の符号にする
    ans = min(count, ans)  # 最小操作回数を更新
print(ans)


# Example run
# Input:
-1057486868
10366
# Output:
0
n=int(input())
count=0
A=[int(i) for i in input().split()]
if A[0]==0:
  A[0]+=1
  count+=1
elif A[0]<0:
  for i in range(len(A)):
    A[i]*=(-1)
for i in range(1,len(A)):
  if i%2==0:
    while sum(A[:i+1])<=0:
      A[i]+=1
      count+=1
  else:
    while sum(A[:i+1])>=0:
      A[i]-=1
      count+=1
print(count)

# Example run
# Input:
-5
43544301
# Output:
0
from collections import defaultdict


def solve(pre_is_positive, a_list):
    total = 0
    ans = 0
    for a in a_list:
        total += a
        if pre_is_positive and total >= 0:
            ans += abs(total) + 1
            total = -1
        elif not pre_is_positive and total <= 0:
            ans += abs(total) + 1
            total = 1
        pre_is_positive = total > 0

    return ans


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    print(min(solve(True, a_list), solve(False, a_list)))


if __name__ == '__main__':
    main()


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



res1 = 0
sum = 0
# sei, hu, sei, hu....
# guu, ki, guu, ki
for i in range(n):
    sum += a[i]
    if sum <= 0 and i%2 == 0:
        res1 += abs(sum) + 1
        sum = 1
    elif sum >= 0 and i%2 == 1:
        res1 += abs(sum) + 1
        sum = -1
    # hutuunitoku


res2 = 0
sum = 0
# hu, sei, hu, sei....
# guu, ki, guu, ki
for i in range(n):
    sum += a[i]
    if sum <= 0 and i%2 == 1:
        res2 += abs(sum) + 1
        sum = 1
    elif sum >= 0 and i%2 == 0:
        res2 += abs(sum) + 1
        sum = -1
    # hutuunitoku

print(min(res1, res2))


# Example run
# Input:
-1
-3439167
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
num,answer1= a[0],0
if a[0]==0:
	num,answer1 = 1,1
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer1 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
if a[0]==0: num,answer2 = -1,1
else: num,answer2 = -a[0]//abs(a[0]),abs(a[0]-(-a[0]//abs(a[0])))
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer2 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
print(min(answer1,answer2))


# Example run
# Input:
-3043
422
# Output:
0
n=int(input())
a=list(map(int,input().split()))
sum=a[0]
if(sum==0):
  opp=1
  sum=1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opp+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  opm=1
  sum=-1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opm+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  op=min(opm,opp)
else:
  op=0
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      op+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
print(op)

# Example run
# Input:
-16733
-18850
# Output:
0
# -*- coding: utf-8 -*-
N = int(input())
a = [int(n) for n in input().split()]

count_a = 0 #+start
count_b = 0 #-start

nowsum = a[0]
if nowsum > 0:
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]

    count_b += abs(a[0]) + 1
    a[0] = a[0] / abs(a[0]) * -1
    nowsum = a[0]

    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_b += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n] 

    print(min(count_a, count_b))

else:
    a[0] = 1
    count_a += 1
    nowsum = 1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_a += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]
    
    a[0] = -1
    count_b += 1
    nowsum = -1
    for n in range(1, N):
        if nowsum * (nowsum + a[n]) >= 0:
            count_b += abs(nowsum + a[n]) + 1
            if nowsum < 0:
                nowsum = 1
            else:
                nowsum = -1
        else:
            nowsum += a[n]   
    print(min(count_a, count_b))

# Example run
# Input:
-28940937
14
# Output:
0
n = int(input())
A = [int(i) for i in input().split()]

def f(A, op, acc = 0, cnt = 0):
    for i in range(n):
        acc += A[i]
        
        if i % 2 == 0:
            if op * acc <= 0:
                cnt += - op * acc + 1
                acc = 1
                
        if i % 2 == 1:
            if op * acc >= 0:
                cnt += op * acc + 1
                acc = -1
                
    if acc == 0:
        cnt += 1
        
    return cnt

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

# Example run
# Input:
-5271130
19
# Output:
1
n = int(input())
al = list(map(int, input().split()))


def is_diff_sign(s, t):
    return (s > 0 > t) or (s < 0 < t)


def count(_list, first):
    cnt = abs(first - _list[0])
    prev_sum = first
    prev_positive = first > 0
    for a in _list[1:]:
        _sum = prev_sum + a
        if is_diff_sign(prev_sum, _sum):
            prev_sum = _sum
            prev_positive = prev_sum > 0
            continue
        if prev_positive:
            prev_sum = -1
        else:
            prev_sum = 1
        prev_positive = not prev_positive
        cnt += abs(_sum) + 1
    return cnt


ans = 0
if al[0] == 0:
    ans = min(count(al, 1), count(al, -1))
else:
    ans = min(count(al, al[0]), count(al, -al[0] // abs(al[0])))
print(ans)


# Example run
# Input:
-3122
424
# Output:
0
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def cc(al, start):
	mc = 0
	is_m = start
	pre_total_sum=0
	for v in al:
		pre_total_sum += v
		if is_m*pre_total_sum <= 0:
			mc += abs(pre_total_sum-is_m)
			pre_total_sum = is_m
		is_m *= -1
	#pa(mc)
	return mc

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	ret = min(cc(al, -1), cc(al, 1))
	return ret
	
	
	
#+++++
isTest=False

def pa(*vl):
	if not isTest:
		return
	for v in vl:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

# Example run
# Input:
255
131163226
# Output:
0
n=int(input())
a_list=[int(i) for i in input().split()]

ans=10**20
for flg in (-1,1):
    c=0
    s=0
    for a in a_list:
        s+=a
        if s==0:
            c+=1
            s=flg
        if s//abs(s)!=flg:
            c+=abs(s)+1
            s=flg
        flg*=-1
    ans=min(ans,c)
print(ans)

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

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


# Example run
# Input:
-15
3431161
# Output:
[3431161]
0
n = int(input())
a = list(map(int, input().split()))
L = [0 for _ in range(n)]
L[0] = a[0]
for i in range(1, n):
  L[i] = L[i-1] + a[i]
delay = 0
all_over = 0
if a[0] != 0:
  sign = (a[0] > 0) - (a[0] < 0)
  for i in range(1, n):
    L[i] += delay
    if L[i] <= 0 and sign == -1:
      delay += 1 - L[i]
      all_over += 1 - L[i]
      L[i] = 1
    elif L[i] >= 0 and sign == 1:
      delay -= L[i] + 1
      all_over += L[i] + 1
      L[i] = -1
    sign *= -1
  print(all_over)
else:
  posL = L[:]
  negL = L[:]
  pos_delay, neg_delay = 1, -1
  pos_all_over, neg_all_over = 1, 1
  sign = 1
  for i in range(1, n):
    posL[i] += pos_delay
    if posL[i] <= 0 and sign == -1:
      pos_delay += 1 - posL[i]
      pos_all_over += 1 - posL[i]
      posL[i] = 1
    elif posL[i] >= 0 and sign == 1:
      pos_delay -= posL[i] + 1
      pos_all_over += posL[i] + 1
      posL[i] = -1
    sign *= -1
  sign = -1
  for i in range(1, n):
    negL[i] += neg_delay
    if negL[i] <= 0 and sign == -1:
      neg_delay += 1 - negL[i]
      neg_all_over += 1 - negL[i]
      negL[i] = 1
    elif negL[i] >= 0 and sign == 1:
      neg_delay -= negL[i] + 1
      neg_all_over += negL[i] + 1
      negL[i] = -1
    sign *= -1
  print(min(pos_all_over, neg_all_over))

# Example run
# Input:
1
0
# Output:
1
N = int(input())
*A, = map(int,input().split())
ans1 = 0
S = A[0]
if S <= 0:
    S = 1
    ans1 = abs(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
    ans2 = abs(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))

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

def Cost(a, Sum):
    if Sum > 0:
        if Sum + a < 0:
            return 0
        else:
            return abs(Sum + a) + 1
    if Sum < 0:
        if Sum + a > 0:
            return 0
        else:
            return abs(Sum + a) + 1

Sum = lambda a, preSum:preSum + a if Cost(a, preSum) == 0 else (-1)**int(preSum > 0)

pCost, pSum = (lambda:(0, A[0]) if A[0] > 0 else (abs(A[0])+1, 1))()
nCost, nSum = (lambda:(0, A[0]) if A[0] < 0 else (abs(A[0])+1,-1))()
for a in A[1:]:
    pCost += Cost(a, pSum)
    pSum = Sum(a, pSum)
    nCost += Cost(a, nSum)
    nSum = Sum(a, nSum)
print(min(pCost, nCost))


# Example run
# Input:
-5
36241
# Output:
0
def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    min_count = float('inf')
    tot = 0
    if A[0] != 0:
        tot = A[0]
        count = 0
        for a in A[1:]:
            if tot > 0 and tot + a >= 0:
                count += tot+a+1
                tot = -1
            elif tot < 0 and tot + a <= 0:
                count += -(tot+a)+1
                tot = 1
            else:
                tot += a
        min_count = min(min_count, count)
    else:
        count = 1
        for i in [1, -1]:
            tot = i
            for a in A[1:]:
                if tot > 0 and tot + a >= 0:
                    count += tot+a+1
                    tot = -1
                elif tot < 0 and tot + a <= 0:
                    count += -(tot+a)+1
                    tot = 1
                else:
                    tot += a
            min_count = min(min_count, count)
    return min_count

if __name__ == '__main__':
    print(main())

# Example run
# Input:
-42600
2116
# Output:
0
import sys
N = int(input())
a = [int(_) for _ in input().split()]

#+,-,+,-
asum = [0]*(N)
ansp = 0
if(a[0] <= 0):
    ansp+=1-a[0]
    asum[0]=1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansp+=1+asum[i]
            asum[i]=-1
        else:
            ansp+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansp)
#-,+,-,+,,,
ansn = 0
if(a[0] >= 0 ):
    ansn+=1+a[0]
    asum[0]=-1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansn+=1+asum[i]
            asum[i]=-1
        else:
            ansn+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansn)
print(min(ansp,ansn))


# Example run
# Input:
1
2132653
# Output:
0