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

s = 0
num = 0
for i, x in enumerate(a):
    if i == 0:
        if x == 0:
            num += 1
            for j, y in enumerate(a):
                if j == n - 1:
                    s = 1
                    break
                elif y > 0:
                    s = -1
                    break
                elif y < 0:
                    s = 1
                    break
        else:
            s = x
    else:
        if s > 0:
            if s + x < 0:
                s += x
            else:
                num += abs(-s-x-1)
                s = -1
        else:
            if s + x > 0:
                s += x
            else:
                num += abs(-s-x+1)
                s = 1
print(num)

# Example run
# Input:
1049999
4
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
ls1 = [1] + [-2 if i%2 == 0 else 2 for i in range(n-1)]
ls2 = [-1] + [2 if i%2 == 0 else -2 for i in range(n-1)]
ans1, ans2 = 0,0
for x, y in zip(a, ls1):
    ans1 += abs(x-y)
for x, y in zip(a, ls2):
    ans2 += abs(x-y)
print(min(ans1, ans2))

# Example run
# Input:
-3463607
18
# Output:
17
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    
    suma = [0] * n
    minop = 1e9

    for greater0 in [True, False]:
        oper = 0
        for i in range(n):
            if i == 0:
                suma[i] = a[i]
                if suma[i]<0:
                    greater0 = False
            else:
                suma[i] = a[i] + suma[i-1]
            
            greater0 = not greater0
            
            if greater0 and suma[i]<=0:
                oper +=  1 - suma[i]
                suma[i] = 1
                continue
            
            if (not greater0) and suma[i]>=0:
                oper += 1 + suma[i]
                suma[i] = -1
                continue

        minop = min(minop, oper)
    
    print(oper)
            

        

solve()


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

s = [0]*(n+1)
for i in range(len(a)):
    s[i+1]=s[i]+a[i]

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

    else:
        if now > 0:
            continue
        else:
            case1 += abs(now)+1
            now = 1

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

    else:
        if now > 0:
            continue
        else:
            case2 += abs(now) + 1
            now = 1

print(min(case1,case2))

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

# Example run
# Input:
B[=
-24
# 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:
1792657
-728818981
# Output:
0
n = int(input())
A = map(int, input().split())
sum_b = 0
cnt_b = 0
sum_c = 0
cnt_c = 0
for i,a in enumerate(A):
  sum_b += a
  if not sum_b or ((sum_b > 0) != ((i % 2) > 0)):
    cnt_b += abs(sum_b) + 1
    sum_b = 1 if ((i % 2) > 0) else -1
  sum_c += a
  if not sum_c or ((sum_c > 0) == ((i % 2) > 0)):
    cnt_c += abs(sum_c) + 1
    sum_c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))


# Example run
# Input:
1
-1
# Output:
0
n = int(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)


# Example run
# Input:
-436344399
-83
# Output:
0
n = int(input())
_arr = list(map(int, input().split()))

ans = []
for first in (_arr[0], 1, -1):
    arr = _arr[:]
    c = 0
    prev = 0
    for i in range(n):
        t = prev + arr[i]
        if i == 0:
            arr[i] = first
        elif prev > 0 and t >= 0:
            diff = t + 1
            c += diff
            arr[i] -= diff 
        elif prev < 0 and t <= 0:
            diff = -1 * t + 1
            c += diff
            arr[i] += diff
        prev += arr[i]
    ans.append(c)
    print(arr)
print(min(ans))

# Example run
# Input:
0
90
# Output:
[90]
[90]
[90]
0
N = int(input())
A = list(map(int,input().split()))

totals = [0] * N
totals[0] = A[0]
con = 0

if totals[0] == 0:
  for i in range(1,N):
    if A[i] != 0:
      f = A[i]
      if f > 0:
        totals[0] = -1
      else:
        totals[0] = 1
    break
  else:
    totals[0] = 1
  con += 1

for i in range(1,N):
  totals[i] = totals[i - 1] + A[i]
  if totals[i - 1] * totals[i] >= 0:
    if totals[i - 1] < 0:
      con += abs(1 - totals[i])
      totals[i] += abs(1 - totals[i])
    elif totals[i - 1] > 0:
      con += abs(-1 - totals[i])
      totals[i] -= abs(-1 - totals[i])
  print(totals[:i + 1])
  
print(con)


# Example run
# Input:
1
-131968027
# 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:
		count1 += abs(temp - a[i])
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		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(temp - a[i])
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


# Example run
# Input:
-83
-39355
# Output:
0
n = int(input())
a = list(map(int, 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
        if t == False and x > -1:
            ans += x + 1
            x = -1
        t = not t
    return ans


print(min(chk(a, True), chk(a, False)))


# Example run
# Input:
134
-5930
# Output:
0
import itertools

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(itertools.accumulate(A))
    even, odd = 0, 0
    for i, v in enumerate(a):
        if i % 2:
            odd += v
        else:
            even += v

    if even > odd:
        func = (plus, minus)
    else:
        func = (minus, plus)

    cnt = 0
    add_ = 0
    for i, v in enumerate(a):
        ret = func[i%2](v + add_)
        add_ += ret
        cnt += abs(ret)
    print(cnt)

def plus(n):
    if n <= 0:
        x = 1 - n
        return x
    else:
        return 0

def minus(n):
    if n >= 0:
        x = -1 - n
        return x
    else:
        return 0


main()


# Example run
# Input:
-1406309
-967
# Output:
0
if __name__ == '__main__':
# C
    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
        else:
            o *= -1

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

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

def solve(A):
  res = 0
  pre_a = A[0]
  for a in A[1:]:
    a += pre_a
    if a * pre_a < 0:
      pre_a = a
      continue
    diff = - a + (-1)**(pre_a > 0)
    res += abs(diff)
    pre_a = a + diff
  return res
  
if A[0] != 0:
  ans = solve(A)
else:
  A[0] = 1
  ans = solve(A) + 1
  A[0] = -1
  ans = min(ans, solve(A) + 1)

print(ans)

# Example run
# Input:
150088694
665
# Output:
0
n=input()
a=list(map(int,input().split()))
ans=10**18
for s in -1,1:
  c=0
  if a[0]*s<0:c=abs(s-a[0])
  elif a[0]*s>0:s=a[0]
  else:c=1
  for i in a[1:]:
    if s<0:
      b=-s+1
      c+=max(0,b-i)
      s+=max(i,b)
    else:
      b=-s-1
      c+=max(0,i-b)
      s+=min(i,b)
  ans=min(ans,c)
print(ans)

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

sum = a[0]
count = 0

for i in range(1, n) :

    if sum == 0 :
        count += 1
        if a[i] > 0 :
            sum = -1
        elif a[i] < 0 :
            sum = 1

    temp = sum
    sum += a[i]
    if temp > 0 and sum > 0 :
        count += sum + 1
        sum = -1
    elif temp < 0 and sum < 0 :
        count += -sum + 1
        sum = 1

if sum == 0 :
    count += 1

print(count)


# Example run
# Input:
-331748
14563732
# Output:
0
def solve():
  ans = float('inf')
  N = int(input())
  A = list(map(int, input().split()))
  if A[0]==0:
    lis = [1,-1]
  else:
    lis = [A[0],-A[0]//abs(A[0])]
  for l in lis:
    cnt = abs(A[0]-l)
    total = l
    for i in range(1,N):
      new_total = total+A[i]
      if total*(new_total)>=0:
        new_total = (-1)*total//abs(total)
        cnt += abs(new_total-(total+A[i]))
      total = new_total
    ans = min(ans,cnt)
  return ans
print(solve())

# Example run
# Input:
-8056
-449705
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

# a_1 > 0 の場合を試す
res, sum = 0, 0
if 0 < A[0]: sum = A[0]
else: res, sum = -A[0] + 1, 1

for i in range(1, N):
    if 0 < sum:
        if -1 < sum + A[i]: # a_i を足して、符号が変わらない
            res += abs(A[i] + sum + 1)
            sum = -1
        else: # a_i を足して符号が変わる
            sum += A[i]
    else:
        if sum + A[i] < 1:
            res += abs(A[i] - (-sum + 1))
            sum = 1
        else:
            sum += A[i]

ans = res

# a_1 < 0 の場合を試す
res, sum = 0, 0
if A[0] < 0: sum = A[0]
else: res, sum = A[0] + 1, -1

for i in range(1, N):
    if 0 < sum:
        if -1 < sum + A[i]: # a_i を足して、符号が変わらない
            res += abs(A[i] + sum + 1)
            sum = -1
        else: # a_i を足して符号が変わる
            sum += A[i]
    else:
        if sum + A[i] < 1:
            res += abs(A[i] - (-sum + 1))
            sum = 1
        else:
            sum += A[i]

ans = min(ans, res)
print(ans)

# Example run
# Input:
-154
1
# Output:
0
def z(s,l):
	for i in range(n-1):
		r=l+a[i+1]
		if r*l>=0:
			if l<=0:
				s+=1-r
				r=1
			else:
				s+=1+r
				r=-1
		l=r
	return s
n=int(input())
a=list(map(int,input().split()))
s1=0
l1=a[0]
if a[0]<=0:
	s1=1-a[0]
	l1=1
s2=0
l2=a[0]
if a[0]>=0:
	s2=a[0]+1
	l2=-1
print(min(z(s1,l1),z(s2,l2)))

# Example run
# Input:
-245642563
2806913
# Output:
0
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
# a[0] == 0 のケース、要検証

n = int(input())
a = list(map(int, input().split()))
count_p = 0  # 操作回数(正)
count_m = 0  # 操作回数(負)
s = 0  # 現時点の和


def counter(a, s):
    if s * (s + a) < 0:
        return 0
    else:
        if s < 0:
            return 1 - (s + a)
        else:
            return -1 - (s + a)


# a[0]を+にする場合
if a[0] <= 0:
    count_p = 1 - a[0]
    s = 1
else:
    s = a[0]

for i in range(n-1):
    tmp = counter(a[i + 1], s)
    s = s + a[i+1]+tmp
    count_p = count_p + abs(tmp)

# a[0]を-にする場合
if a[0] >= 0:
    count_m = 1 + a[0]
    s = -1
else:
    s = a[0]


for i in range(n-1):
    tmp = counter(a[i + 1], s)
    s = s + a[i+1]+tmp
    count_m = count_m + abs(tmp)

print(str(min(count_p, count_m)))


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


a1 = a.copy()
cnt1 = 0
sum1 = 0
if a1[0] == 0:
    a1[0] = 1
    cnt1 +=1

a2 = a.copy()
cnt2 = 0
sum2 = 0
if a2[0] == 0:
    a2[0] = -1
    cnt2 +=1
    
    
for i in range(n-1):
    sum1 = sum(a1[:i+1])
    if sum1 > 0 and (sum1+a1[i+1]) >= 0:
        cnt1 += abs(((sum1 * -1)-1) - a1[i+1])
        a1[i+1] = ((sum1 * -1)-1)
    
    elif sum1 < 0 and (sum1 + a1[i+1]) <= 0:
        cnt1 += abs(abs(sum1)+1 - a1[i+1])
        a1[i+1] = abs(sum1)+1

for i in range(n-1):
    sum2 = sum(a2[:i+1])
    if sum2 > 0 and (sum2+a2[i+1]) >= 0:
        cnt2 += abs(((sum2 * -1)-1) - a2[i+1])
        a2[i+1] = ((sum2 * -1)-1)
        
    elif sum2 < 0 and (sum2+a2[i+1]) <= 0:
        cnt2 += abs(abs(sum2)+1 - a2[i+1])
        a2[i+1] = abs(sum2)+1
        
print(min(cnt1,cnt2))
        

# Example run
# Input:
-3528
-5900
# Output:
0
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0 and sum(A) + a[i+1] > 0:
        cnt += abs(sum(A) + a[i+1])+1
        a[i+1] -= abs(sum(A) + a[i+1])+1


    elif sum(A) < 0 and sum(A) + a[i+1] < 0:
        cnt += abs(sum(A) - a[i+1])-1
        a[i+1] += abs(sum(A) - a[i+1])-1


if sum(a) == 0:
    cnt += 1

print(cnt)

# Example run
# Input:
-86
0
# Output:
1
n=int(input())
l=[int(i) for i in input().split()]
sm=l[0]
req=0 
if sm==0:
    sm+=1 
    req+=1 
    pr=1 
elif sm<0:
    pr=0 
else:
    pr=1 
for i in range(1,n):
    if pr==1:
        n1=sm+l[i]
        if n1<0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=sm+1 
            sm=-1 
    else: 
        n1=sm+l[i]
        if n1>0:
            sm+=l[i]
            pass 
        else: 
            sm+=l[i]
            req+=(-sm+1) 
            sm=1 
    pr=1-pr  
print(req)

            

# Example run
# Input:
-23909
-68
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

#奇数項を正にする
oddS = (A[0] if A[0] > 0 else 1)
oddtotal = (0 if A[0] > 0 else 1 - A[0])
for i in range(1, N):
    if oddS > 0:
        if oddS + A[i] < 0: oddS += A[i]
        else:
            oddtotal += abs(-1 - (oddS + A[i]))
            oddS = -1
    elif oddS < 0:
        if oddS + A[i] > 0: oddS += A[i]
        else: 
            oddtotal += 1 - (oddS + A[i])
            oddS = 1

#偶数項を正にする
eS = (A[0] if A[0] < 0 else -1)
etotal = (0 if A[0] < 0 else A[0] + 1)
for i in range(1, N):
    if eS > 0:
        if eS + A[i] < 0: eS += A[i]
        else:
            etotal += abs(-1 - (eS + A[i]))
            eS = -1
    elif eS < 0:
        if eS + A[i] > 0: eS += A[i]
        else: 
            etotal += 1 - (eS + A[i])
            eS = 1

print(min(oddtotal, etotal))

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

ans = 1e9
for sign in (1, -1):
    s = sign
    res, acc = 0, 0
    for a in A:
        acc += a
        if acc * s <= 0:
            res += abs(acc-s)
            acc = s
        s *= -1
        print(acc, a, res)
    ans = min(ans, res)
    print()

print(ans)


# Example run
# Input:
-87
141725276
# Output:
141725276 141725276 0

-1 141725276 141725277

0
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    
    suma = [0] * n
    minop = 1e9

    for greater0 in [True, False]:
        oper = 0
        for i in range(n):
            if i == 0:
                suma[i] = a[i]
            else:
                suma[i] = a[i] + suma[i-1]
            
            greater0 = not greater0
            
            if greater0 and suma[i]<=0:
                oper +=  1 - suma[i]
                suma[i] = 1
                continue
            
            if (not greater0) and suma[i]>=0:
                oper += 1 + suma[i]
                suma[i] = -1
                continue

        minop = min(minop, oper)
    
    print(minop)
            

        

solve()


# Example run
# Input:
-3249
901872
# Output:
0
n = int(input())
A = [int(x) for x in input().split()]
sum_start_plus = 0
sum_start_minus = 0
ans_start_plus = 0
ans_start_minus = 0
flag_start_plus = True
flag_start_minus = True

# プラス始まりの場合を計算する
for a in A:
    sum_start_plus += a
    if flag_start_plus:
        flag_start_plus = False
        if sum_start_plus > 0:
            continue
        else:
            ans_start_plus += abs(1 - sum_start_plus)
            sum_start_plus = 1
    else:
        flag_start_plus = True
        if sum_start_plus < 0:
            continue
        else:
            ans_start_plus += abs(-1 - sum_start_plus)
            sum_start_plus = -1

# マイナス始まりの場合を計算する
for a in A:
    sum_start_minus += a
    if flag_start_minus:
        flag_start_minus = False
        if sum_start_minus < 0:
            continue
        else:
            ans_start_minus += abs(-1 - sum_start_minus)
            sum_start_minus = -1
    else:
        flag_start_minus = True
        if sum_start_minus > 0:
            continue
        else:
            ans_start_minus += abs(1 - sum_start_minus)
            sum_start_minus = 1

print(min(ans_start_plus, ans_start_minus))

# Example run
# Input:
18
92
# Output:
0
import math

n = int(input())
ai = tuple(map(int, input().split()))

kisuu = 0.0
guusuu = 0.0
for i, a in enumerate(ai):
    if i % 2:
        kisuu += a
    else:
        guusuu += a
kisuu /= math.floor(n / 2)
guusuu /= n - math.floor(n / 2)

if kisuu > guusuu:
    kisuu = True
    guusuu = False
else:
    kisuu = False
    guusuu = True

sum = 0
ans = 0
for i, a in enumerate(ai):
    sum += a
    if i % 2:
        if kisuu:
            if sum <= 0:
                ans += 1 - sum
                sum = 1
        else:
            if sum >= 0:
                ans += 1 + sum
                sum = -1
    else:
        if guusuu:
            if sum <= 0:
                ans += 1 - sum
                sum = 1
        else:
            if sum >= 0:
                ans += 1 + sum
                sum = -1
print (ans)

# Example run
# Input:
107
186860433
# Output:
0
n=int(input())
a=list(map(lambda x: int(x), input().split()))

ans_plus=0
tmp=0
if a[0]<=0:
    ans_plus=1-a[0]
    tmp=1
else:
    tmp=a[0]
plus_flag=False
for i in a[1:]:
    tmp+=i
    if plus_flag==True and tmp>0:
        pass
    elif plus_flag==True and tmp<=0:
        ans_plus+=1-tmp
        tmp=1
    elif plus_flag==False and tmp<0:
        pass
    elif plus_flag==False and tmp>=0:
        ans_plus+=1+tmp
        tmp=-1
    plus_flag=not plus_flag
#print(ans_plus)

ans_minus=0
tmp=0
if a[0]>=0:
    ans_minus=1+a[0]
    tmp=-1
else:
    tmp=a[0]
plus_flag=True
for i in a[1:]:
    tmp+=i
    if plus_flag==True and tmp>0:
        pass
    elif plus_flag==True and tmp<=0:
        ans_minus+=1-tmp
        tmp=1
    elif plus_flag==False and tmp<0:
        pass
    elif plus_flag==False and tmp>=0:
        ans_minus+=1+tmp
        tmp=-1
    plus_flag=not plus_flag
#print(ans_minus)
print(min(ans_plus, ans_minus))

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

a = b

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]

count2 = abs(a[0]) + 1

a = b

if a[0] == 0:
	a[0] = 1
	count1 = 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:
-224484380
171476207
# Output:
0
N = int(input())
A = list(map(int,input().split()))

#初期化
dp = [[0,0]]*N
if A[0] == 0:
  for i in range(1,N):
    if A[i] > 0:
      dp[i-1][0] = 2*i-1
      dp[i-1][1] = -1
      break
    elif A[i] < 0:
      dp[i-1][0] = 2*i-1
      dp[i-1][1] = 1
      break
    else:
      pass
  else:
    dp[N-1][0] = 2*N-1
else:
  dp[0][1] = A[0]

#dp    
for j in range(N-1):
  S_j = dp[j][1]
  if (S_j > 0 and A[j+1] < -S_j) or (S_j < 0 and A[j+1] > -S_j):
    dp[j+1][0] = dp[j][0]
    dp[j+1][1] = dp[j][1]+A[j+1]
  elif S_j > 0:
    dp[j+1][0] = dp[j][0]+S_j+A[j+1]+1
    dp[j+1][1] = -1
  elif S_j < 0:
    dp[j+1][0] = dp[j][0]-S_j-A[j+1]+1
    dp[j+1][1] = -1

print(dp[N-1][0])

# Example run
# Input:
1
4887419
# Output:
0
N=int(input())
A=list(map(int, input().split()))
#和の符号が異なる


ans1=0
ans2=0

if A[0]==0:
    a0_1=1
    a0_2=-1
    ans1+=1
    ans2+=1
elif A[0]>1:
    a0_1=A[0]
    a0_2=-1
    ans2+=A[0]+1
else:
    a0_1=1
    a0_2=A[0]
    ans1+=1-A[0]


now1=a0_1
for i in range(1,N):
    if now1*(now1+A[i])<0:
        now1+=A[i]
    else:
        if now1>0:
            add=(-1)*(now1+1)
        else:
            add=(-1)*(now1-1)
        now1+=add
        ans1+=abs(add-A[i])
    #print(now1)

now2=a0_2
for i in range(1,N):
    if now2*(now2+A[i])<0:
        now2+=A[i]
    else:
        if now2>0:
            add=(-1)*(now2+1)
        else:
            add=(-1)*(now2-1)
        now2+=add
        ans2+=abs(add-A[i])
ans=min(ans1, ans2)
print(ans)
#print(ans1, ans2)

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

sa = 0
count = [0, 0]

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

sa = 0

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

print(count)

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

def seq(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(seq(A,True),seq(A,False)))

# Example run
# Input:
0
13
# Output:
0
#ABC059C
N=int(input())
A=list(map(int,input().split()))
ans=[0,0]
i=[1,0]
for c in range(2):
	summ=0
	for a in A:
		summ+=a
		if summ==0:
			ans[c]+=abs(summ-(-1)**i[c])
			summ=(-1)**i[c]
		elif (summ>0)==i[c]:
			ans[c]+=abs(summ-(-1)**i[c])
			summ=(-1)**i[c]
		i[c]=(i[c]+1)%2
print(min(ans))

# Example run
# Input:
-131787924
-1
# Output:
0