Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
num_list = list(map(int, input().split()))
count = 0
sum_ = num_list[0]
if sum_ > 0:
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 0:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1 
                sum_ = -1
    print(count)                
elif sum_ < 0:
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 1:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1 
                sum_ = -1
    print(count)                
else:
    sum_ = 1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 0:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1 
                sum_ = -1
    count1 = count        
    sum_ = -1
    for i in range(1, n):
        sum_ += num_list[i]
        if i%2 == 1:
            if sum_ <= 0:
                count += abs(sum_) + 1
                sum_ = 1
        else:
            if sum_ >= 0:
                count += abs(sum_) + 1 
                sum_ = -1
    count2 = count           
    print(min(count1+1, count2+1))

# Example run
# Input:
-3281
1
# Output:
0
n = int(input())
array = list(map(int, input().split()))

total = 0
flag = -1
minus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        minus += abs(total*flag)+1
        total = flag
        flag *= -1

total = 0
flag = 1
plus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        plus += abs(total*flag)+1
        total = flag
        flag *= -1

print(min(minus, plus))


# Example run
# Input:
28952
-124042
# Output:
0
n = int(input())
a = list(map(int,input().split()))
s = []
for i in range(n):
    if i == 0:
        s.append(a[0])
    else:
        s.append(a[i]+s[-1])

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

# Example run
# Input:
-2147483648
-15824
# Output:
0
n = int(input())
*a, = map(int, input().split())

is_plus = False if a[0] > 0 else True

s = a[0]
ans = 0
for i in range(1, n):
    t = 0

    if is_plus and s+a[i] < 0:
        t = abs(s-a[i]) - 1
        a[i] += t
    elif not is_plus and s+a[i] > 0:
        t = abs(s+a[i]) + 1
        a[i] -= t

    s += a[i]
    ans += t
    is_plus = not is_plus

if s != 0:
    print(ans)
else:
    print(ans-1 if a[-1] < 0 else ans+1)


# Example run
# Input:
-109089799
-74270783
# Output:
0
N=int(input())
A=list(map(int,input().split()))

def dfs(sign):
    cnt=0
    tmp=0
    for a in A:
        tmp+=a
        if tmp*sign>=0:
            cnt+=abs(tmp)+1
            tmp=-sign
        sign*=-1
    return cnt

print(min(dfs(1),dfs(-1)))

# copy

# Example run
# Input:
-3650
-511342
# Output:
0
n = int(input())
A = list(map(int,input().split()))
def func(list1,op,acc = 0,count = 0):
    for i in range(n):
        acc += list1[i]
        if i % 2 == 1 and acc * op >= 0:
            count += op * acc + 1
            acc = -op
        elif i % 2 == 0 and acc * op <= 0:
            count += -op * acc + 1
            acc = op
    if acc == 0:
        count += 1
    return count
ans = min(func(A,1),func(A,-1))
print(ans)

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

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

answer = 1e15
for s in range(2): # start from + or -
  prev_cumsum=0
  num_man = 0
  for i, a in enumerate(A):
    if (prev_cumsum + a)*(-1)**(i+s) > 0:
      prev_cumsum += a
      #print(prev_cumsum)
    else:
      num_man += abs((-1)**(i+s) - prev_cumsum -a)
      prev_cumsum = (-1)**(i+s)
      #print(prev_cumsum)
  answer = min(answer, num_man)
  #print(num_man)
print(answer)
      
  

# Example run
# Input:
-1998
-147
# Output:
0
N = int(input())
A = tuple(map(int, input().split(' ')))

if A[0] == 0:
    cs = 1
    ans1 = 1
else:
    cs = A[0]
    ans1 = 0

for na in A[1:]:
    if cs >= 0:
        cs += na
        if cs < 0:
            continue

        ans1 += abs(cs) + 1
        cs = -1
    else:
        cs += na
        if cs > 0:
            continue

        ans1 += abs(cs) + 1
        cs = 1

if A[0] == 0:
    cs = -1
    ans2 = 1
elif A[0] > 0:
    cs = -1
    ans2 = abs(A[0]) + 1
else:
    cs = 1
    ans2 = abs(A[0]) + 1

for na in A[1:]:
    if cs >= 0:
        cs += na
        if cs < 0:
            continue

        ans2 += abs(cs) + 1
        cs = -1
    else:
        cs += na
        if cs > 0:
            continue

        ans2 += abs(cs) + 1
        cs = 1

print(min(ans1, ans2))


# Example run
# Input:
0
-15
# Output:
0
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
def solve(cnt,current_sum):
    for i in range(n-1):
        if current_sum * (current_sum + a[i+1]) < 0:#符号が違う
            current_sum += a[i+1]
            cnt += 0#そのまま
        elif current_sum < 0:
            cnt += 1 - (current_sum + a[i+1])
            current_sum = 1 
        else:
            cnt += (current_sum + a[i+1]) +1 
            current_sum = -1
    return cnt
if a[0] > 0:
    print(min(solve(0,a[0]),solve(1+abs(a[0]),-1)))
elif a[0] < 0:
    print(min(solve(0,a[0]),solve(1+abs(a[0]),1)))
else:
    print(min(solve(1,1),solve(1,-1)))


# Example run
# Input:
0
35
# Output:
0
n=int(input())
a=list(map(int,input().split()))
import sys
sum=a[0]
cnt=0
if a[0]==0:
    sum+=1
    cnt+=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<=0:
                cnt+=(1-z)
                sum=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
    cnt_plus=cnt
    sum=-1
    cnt=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<=0:
                cnt+=(1-z)
                sum=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
    cnt_sbst=cnt
    print(cnt_sbst)
    print(cnt_plus)
    print(min(cnt_plus,cnt_sbst))
    sys.exit()
for i in range(1,n):
    if sum<0:
        z=sum+a[i]
        if z>0:
            sum=z
        elif z<=0:
            cnt+=(1-z)
            sum=1
    elif sum>0:
        z=sum+a[i]
        if z>=0:
            cnt+=(z+1)
            sum=-1
        elif z<0:
            sum=z            
print(cnt)

# 6
# 0 0 -1 3 5 0





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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

# Example run
# Input:
u"-itX>w
78831
# Output:
0
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0

for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count1 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count1 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count1 += 1
        currentSum = -1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count2 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count2 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count2 += 1
        currentSum = 1

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count3 += abs(currentSum) + 1
        currentSum = -1
    elif A[0] <= 0 and restSum == 0:
        count3 += 1
        currentSum = 1
        
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[0] >= 0 and restSum == 0:
        count4 += 1
        currentSum = -1
        
print(count1, count2, count3, count4)


# Example run
# Input:
-3
24
# Output:
0 0 0 0
from itertools import accumulate
n = int(input())
a = [int(item) for item in input().split()]

ans = []
asum = list(accumulate(a))
for key in range(2):
    count = 0
    cum_diff = 0
    for i, item in enumerate(asum):
        if i%2 == key:
            if item + cum_diff <= 0:
                diff = 1 - item - cum_diff
                count += abs(diff)
                cum_diff += diff
        else:
            if item + cum_diff >= 0:
                diff = -1 - item - cum_diff
                count += abs(diff)
                cum_diff += diff
    ans.append(count)

print(min(ans))

# Example run
# Input:
-2243514
5183902
# Output:
0
def calc(sign, A):
    cumsum_A = [0 for _ in range(len(A))]
    cumsum_A[0] = A[0]
    for i in range(len(cumsum_A) - 1):
        cumsum_A[i + 1] = cumsum_A[i] + A[i + 1]
    ret, offset = 0, 0
    for a in cumsum_A:
        b = a + offset
        if sign * b <= 0:
            diff = sign - b
            offset += diff
            ret += abs(diff)
        sign *= (-1)
    return ret


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    print(min([calc(1, A), calc(-1, A)]))


if __name__ == '__main__':
    main()

# Example run
# Input:
675805
1792657
# Output:
0
n = int(input())
ls = list(map(int, input().split()))


def calc(ls, sign):
    count = 0
    acc = 0
    for x in ls:
        y = acc + x
        if y == 0 or y // abs(y) != sign:
            z = sign - y
            count += abs(z)
            acc = sign
        else:
            acc = y
        sign *= -1
    return count


count = min(calc(ls, 1), calc(ls, -1))
print(count)

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

ans1 = 0
s = 0
flg = 1
for ai in a:
    s += ai
    if s * flg <= 0:
        ans1 += abs(s) + 1
        s = flg
    flg *= -1

ans2 = 0
s = 0
flg = -1
for ai in a:
    s += ai
    if s * flg <= 0:
        ans2 += abs(s) + 1
        s = flg
    flg *= -1

print(min(ans1, ans2))


# Example run
# Input:
6534
2147483647
# Output:
0
n = int(input())
A = list(map(int, input().split()))
A2 = A[:]
RAW = A[:]

# +-にするとき
su = 0
for i, a in enumerate(A):
    su += a
    if i % 2 == 0:
        if su <= 0:
            # a[i] を増やす
            t = (-su + 1)
            A[i] += t
            su += t
    else:
        if su >= 0:
            # a[i] をへらす
            t = (su + 1)
            A[i] -= t
            su -= t

# -+にするとき
su = 0
for i, a in enumerate(A2):
    su += a
    t = 0
    if i % 2 ==0:
        if su >= 0:
            # a[i]をへらす
            t = (su + 1)
            A2[i] -= t
            su -= t
    else:
        if su <= 0:
            # a[i]をふやす
            t = (-su + 1)
            A2[i] += t
            su += t
# print(A)
# print(A2)

ans1 = sum([abs(a-b) for a,b in zip(A, RAW)])
ans2 = sum([abs(a-b) for a,b in zip(A2, RAW)])
print(min(ans1, ans2))

# Example run
# Input:
-5
-14993
# Output:
0
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()

cum = 0
ope = 0
# first plus case
for i,item in enumerate(A):
    cum += item
    if i%2 == 0 and cum <= 0:
        ope += abs(cum)+1
        cum = 1
    elif i%2 == 1 and cum >= 0:
        ope += cum+1
        cum = -1
#    print(cum)
tmp = ope

cum = 0
ope = 0
# first minus case
for i,item in enumerate(A):
    cum += item
    if i%2 == 1 and cum <= 0:
        ope += abs(cum)+1
        cum = 1
    elif i%2 == 0 and cum >= 0:
        ope += cum+1
        cum = -1
print(tmp,ope)
print(min(tmp,ope))

# Example run
# Input:
9209671
0
# Output:
1 1
1
n = int(input())
a = list(map(int, input().split()))
ans = 0
key = a[0]
if key == 0:
    flag = 1
    a[0] = 1
    ans += 1
elif a[0] > 0:
    flag = 1
else:
    flag = -1
dp = [0 for i in range(n)]
dp[0] = a[0]
for i in range(1, n):
    dp[i] = dp[i - 1] + a[i]
    if dp[i] == 0:
        dp[i] = flag * -1
        ans += 1
    elif flag == 1 and dp[i] > 0:
        ans += abs(-1 - dp[i])
        dp[i] = -1
    elif flag == -1 and dp[i] < 0:
        ans += abs(1 - dp[i])
        dp[i] = 1
    flag *= -1

    
ans1 = ans
ans = 0
if key == 0:
    flag = -1
    a[0] = -1
    ans += 1
elif a[0] > 0:
    flag = 1
else:
    flag = -1
dp = [0 for i in range(n)]
dp[0] = a[0]
for i in range(1, n):
    dp[i] = dp[i - 1] + a[i]
    if dp[i] == 0:
        dp[i] = flag * -1
        ans += 1
    elif flag == 1 and dp[i] > 0:
        ans += abs(-1 - dp[i])
        dp[i] = -1
    elif flag == -1 and dp[i] < 0:
        ans += abs(1 - dp[i])
        dp[i] = 1
    flag *= -1
print(min(ans1, ans))


# Example run
# Input:
1
274829
# Output:
0
def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    min_count = float('inf')
    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:
        for i in [1, -1]:
            count = 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:
718181
5330
# Output:
0
n = int(input())
a_list = list(map(int,input().split()))

count = 0
summary = 0
previous = ''

for i,a in enumerate(a_list):
    if i == 0:
        if a > 0:
            previous = '+'
        elif a < 0:
            previous = '-'
        else:
            flag = False
            for idx,num in enumerate(a_list):
                if num != 0:
                    flag = True
                    if num > 0:
                        if i % 2 == 1:
                            previous = '-'
                            a = -1
                        else:
                            previous = '+'
                            a = 1
                    else:
                        if i % 2 == 0:
                            previous = '-'
                            a = -1
                        else:
                            previous = '+'
                            a = 1
            if flag == False:
                previous = '+'
                a = 1
            count += 1
        summary += a
    else:
        if previous == '+':
            if summary + a < 0:
                a_result = a
            else:
                a_result = (-1)*abs(-1-summary)
                count += abs(a-a_result)
            previous = '-'
        else:
            if summary + a > 0:
                a_result = a
            else:
                a_result = abs(1-summary)
                count += abs(a-a_result)
            previous = '+'
        summary += a_result

print(count)

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

c1 = 0
s = 0

# 累積和の奇数番目を正とするパターン
for i in range(n):
    s += a[i]
    if i % 2 == 1:
        if s <= 0:
            c1 += 1 - s
            s = 1

    else:  # iが偶数
        if s >= 0:
            c1 += 1 + s
            s = -1

c2 = 0
s = 0

# 累積和の偶数番目を正とするパターン
for i in range(n):
    s += a[i]
    if i % 2 == 1:
        if s >= 0:
            c2 += 1 + s
            s = -1
    else:
        if s <= 0:
            c2 += 1 - s
            s = 1

print(min(c1, c2))


# Example run
# Input:
-114
-473
# Output:
0
from itertools import accumulate
n = int(input())
a = list(accumulate([int(i) for i in input().split()]))
d = 0
ans = 0
for i, n in enumerate(a):
    n += d
    if i & 1:
        if n >= 0:
            ans += n + 1
            d -= n + 1
    # 奇数回目でマイナスのとき
    elif n <= 0:
        ans += - n + 1
        d += - n + 1
c = ans
ans = 0
d = 0
for i, n in enumerate(a):
    n += d
    if i & 1 == 0:
        if n >= 0:
            ans += n + 1
            d -= n + 1
    elif n <= 0:
        ans += - n + 1
        d += - n + 1
print(min(ans, c))

# Example run
# Input:
-19
-20238871
# Output:
0
n = int(input())
b = [int(x) for x in input().split()]
a = list()
temp = 0
count1 = 0
count2 = 0

a = b.copy()

if a[0] == 0:
	a[0] = 1
	count1 = 1

sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
			count1 += abs(temp - a[i])
		else:
			temp = abs(sum) + 1
			count1 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

a = b.copy()

count2 = abs(a[0]) + 1
if a[0] >= 0:
	a[0] = -1
else:
	a[0] = 1
	
sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		count2 += abs(sum - a[i]) + 1
		if sum > 0:
			temp = -1 * abs(sum) - 1
			count2 += abs(temp - a[i])
		else:
			temp = abs(sum) + 1
			count2 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


# Example run
# Input:
-1028681
96
# Output:
0
n = int(input())
a = list(map(int, input().split()))
prv_total =0
cnt = 0
for i in range(n-1):
  total = prv_total + a[i]
  nxt_total = total+a[i+1]
  while total*nxt_total >= 0:
    if total == nxt_total:
      if total > 0:
        a[i+1] -= 1
        nxt_total -=1
      else:
        a[i+1] += 1
        nxt_total +=1        
    elif total-nxt_total == 1:
      a[i+1] -= 1
      nxt_total -=1
    elif nxt_total-total == 1:
      a[i+1] += 1
      nxt_total += 1
    elif (total<nxt_total and total >= 0) or (nxt_total<total and nxt_total >= 0):
      total -= 1
      nxt_total -= 1
    elif (total<nxt_total and nxt_total <= 0) or (nxt_total<total and total <= 0):
      total += 1
      nxt_total += 1
    cnt += 1
  prv_total = total

total = prv_total + a[-1]
if total == 0:
  cnt += 1
  
print(cnt)

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

pa=0
s=A[0]
if A[0]<=0:
    pa=1-A[0]
    s=1

for i in range(1,n):
    if i%2==1:
        if s+A[i]>=0:
            pa+=s+A[i]-(-1)
            s=-1
        else:
            s+=A[i]
    else:
        if s+A[i]<=0:
            pa+=1-(s+A[i])
            s=1
        else:
            s+=A[i]
ma=0
s=A[0]
if A[0]>=0:
    ma=A[0]-(-1)
    s=-1

for i in range(1,n):
    if i%2==1:
        if s+A[i]<=0:
            ma+=1-(s+A[i])
            s=1
        else:
            s+=A[i]
    else:
        if s+A[i]>=0:
            ma+=s+A[i]-(-1)
            s=-1
        else:
            s+=A[i]
       
print(min(pa,ma))

# Example run
# Input:
-28608
60
# Output:
0
N = int(input())
nums = list(map(int, input().split()))
ans = 10**10+1
for start in [-1, 1]:
  before = start
  cnt = 0
  sum_n = 0
  for num in nums:
    sum_n += num
    if before*sum_n >= 0:
      if before < 0:
        cnt += 1-sum_n
        sum_n = 1
      else:
        cnt += 1+sum_n
        sum_n = -1
    before = sum_n
  ans = min(ans, cnt)
print(ans)

# Example run
# Input:
-1423
-614
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]

sum_a = 0
ans = 0 
zero = 0 #数列aの先頭に並ぶ0の個数
for x in a:
    if sum_a > 0 and sum_a + x >= 0:
        ans += sum_a + x + 1 #sum_aを-1にするのにかかるコスト
        sum_a = -1
    elif sum_a < 0 and sum_a + x <= 0:
        ans += -(sum_a + x) + 1 #sum_aを+1にするのにかかるコスト
        sum_a = 1
    else:
        sum_a += x
    if sum_a == 0:
        zero += 1
if zero != 0:
    ans += 2*zero - 1 
print(ans)


# Example run
# Input:
10559
1792657
# Output:
0
n = int(input())
a = input().split()
a = [int(m) for m in a]
q = []
k = 0
kco = 0
#+-
for i in range(n):
    if i == 0:
        if a[i] > 0:
            q.append(a[i])
        else:
            q.append(1)
            kco += 1 - a[i]
        k += q[i]
    else:
        k += a[i]
        if i % 2 != 0:
            if k < 0:
                q.append(a[i])
            else:
                q.append(a[i]-k-1)
                kco += k + 1
            k += q[i] - a[i]
        if i % 2 == 0:
            if k > 0:
                q.append(a[i])
            else:
                q.append(a[i]-k+1)
                kco += -k + 1
            k += q[i] - a[i]
xco = kco
q = []
k = 0
kco = 0
#-+
for i in range(n):
    if i == 0:
        if a[i] < 0:
            q.append(a[i])
        else:
            q.append(-1)
            kco += a[i] + 1
        k += q[i]
    else:
        k += a[i]
        if i % 2 == 0:
            if k < 0:
                q.append(a[i])
            else:
                q.append(a[i]-k-1)
                kco += k + 1
            k += q[i] - a[i]
        if i % 2 != 0:
            if k > 0:
                q.append(a[i])
            else:
                q.append(a[i]-k+1)
                kco += -k + 1
            k += q[i] - a[i]
yco = kco
print(min(xco, yco))

# Example run
# Input:
-4
0
# Output:
0