Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
A = [j for j in a]

cnt1 = 0
cnt2 = 0
S = 0

if a[0] > 0:
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            if S + a[i+1] >= 0:
                cnt1 += a[i+1] + S + 1 if a[i+1] + S + 1 > 0 else -(a[i+1] + S + 1)
                a[i+1] = -1-S
        elif a[i] < 0:
            if S + a[i+1] <= 0:
                cnt1 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                a[i+1] = 1-S
    A[0] = -1
    cnt2 = a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            if S + A[i+1] >= 0:
                cnt2 += A[i+1] + S + 1 if A[i+1] + S + 1 > 0 else -(A[i+1] + S + 1)
                A[i+1] = -1-S
        elif A[i] < 0:
            if S + A[i+1] <= 0:
                cnt2 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                A[i+1] = 1-S
elif a[0] < 0:
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            if S + a[i+1] >= 0:
                cnt1 += a[i+1] + S + 1 if a[i+1] + S + 1 > 0 else -(a[i+1] + S + 1)
                a[i+1] = -1-S
        elif a[i] < 0:
            if S + a[i+1] <= 0:
                cnt1 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                a[i+1] = 1-S
    A[0] = 1
    cnt2 = -a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            if S + A[i+1] >= 0:
                cnt2 += A[i+1] + S + 1 if A[i+1] + S + 1 > 0 else -(A[i+1] + S + 1)
                A[i+1] = -1-S
        elif A[i] < 0:
            if S + A[i+1] <= 0:
                cnt2 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                A[i+1] = 1-S
else:
    a[0] = 1
    cnt1 = 1
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            if S + a[i+1] >= 0:
                cnt1 += a[i+1] + S + 1 if a[i+1] + S + 1 > 0 else -(a[i+1] + S + 1)
                a[i+1] = -1-S
        elif a[i] < 0:
            if S + a[i+1] <= 0:
                cnt1 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                a[i+1] = 1-S
    A[0] = -1
    cnt2 = 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            if S + A[i+1] >= 0:
                cnt2 += A[i+1] + S + 1 if A[i+1] + S + 1 > 0 else -(A[i+1] + S + 1)
                A[i+1] = -1-S
        elif A[i] < 0:
            if S + A[i+1] <= 0:
                cnt2 += a[i+1] + S - 1 if a[i+1] + S - 1 > 0 else -(a[i+1] + S - 1)
                A[i+1] = 1-S
cnt = cnt2 if cnt1 >= cnt2 else cnt1

print(cnt)


# Example run
# Input:
-97071
36241
# Output:
0
def f(c, cost):
    for i in a[1:]:
        if c > 0:
            if c + i >= 0:
                cost += c + i + 1
                c = -1
            else:
                c += i
        else:
            if c + i <= 0:
                cost += 1 - c - i
                c = 1
            else:
                c += i
    return c, cost


n = int(input())
a = list(map(int, input().split()))
cost = (a[0] == 0)
c = a[0] + (a[0] == 0)
c, cost = f(c, cost)
tmp = cost
cost = 0
if a[0] >= 0:
    cost = a[0] + 1
    c = -1
else:
    cost = -a[0] + 1
    c = 1
c, cost = f(c, cost)
print(int(min(cost, tmp)))


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

acc = 0
cnt = 0
flag = 1 if a[0] > 0 else -1

for i in a:
    acc += i
    if (flag == 1 and flag > acc) or (flag == -1 and flag < acc) or i == 0:
        cnt += abs(flag - acc)
        acc = flag
    flag *= -1
print(cnt)


# Example run
# Input:
4
4
# Output:
0
from collections import defaultdict


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

    total = a_list[0]
    if total == 0:
        ans = solve(True, 1, 1, a_list[1:])
        ans = min(ans, solve(False, -1, 1, a_list[1:]))
    elif total > 0:
        ans = solve(True, total, 0, a_list[1:])
        ans = min(ans, solve(False, -1, abs(total) + 1, a_list[1:]))
    else:
        ans = solve(False, total, 0, a_list[1:])
        ans = min(ans, solve(True, 1, abs(total) + 1, a_list[1:]))
    print(ans)


if __name__ == '__main__':
    main()


# Example run
# Input:
-1135982
40998106
# Output:
0
N=int(input())
s=list(map(int,input().split()))
def f(N,s,t):    
    ss=s[0]   
    w=0
    for i in range(N-1):
        if t==1:
            if ss+s[i+1]>=t:
                ss=ss+s[i+1]
            else:
                w+=t-ss-s[i+1]
                ss=1
            t=-1
        elif t==-1:
            if ss+s[i+1]<=t:
                ss=ss+s[i+1]
            else:
                w+=ss+s[i+1]-t
                ss=-1
            t=1
    return w        
if s[0]<0:
    t=1
    print(f(N,s,t))
elif s[0]>0:
    t=-1  
    print(f(N,s,t))
else:
    t=1
    a=f(N,s,t)
    t=-1
    b=f(N,s,t)
    print(min(a,b)+1)
                
            
            
            
        
        

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

sum = a[0]
ans1 = 0
if sum <= 0:
	sum = 1
	ans1 += abs(a[0]-1)

for i in range(1, n):
	nextsum = sum + a[i]
	if (sum>0 and nextsum<0) or (sum<0 and nextsum>0):
		sum = nextsum
	elif sum>0:
		ans1 += abs(nextsum+1)
		sum = -1
	elif sum<0:
		ans1 += abs(nextsum-1)
		sum = 1


sum = a[0]
ans2 = 0
if sum >= 0:
	sum = -1
	ans2 += abs(a[0]+1)

for i in range(1, n):
	nextsum = sum + a[i]
	if (sum>0 and nextsum<0) or (sum<0 and nextsum>0):
		sum = nextsum
	elif sum>0:
		ans2 += abs(nextsum+1)
		sum = -1
	elif sum<0:
		ans2 += abs(nextsum-1)
		sum = 1

print(min(ans1, ans2))

# Example run
# Input:
-898293901
-696
# 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_
    
    print(mov, mov_)
    return min(mov, mov_)

_ = input()
inp = input()
inp = inp.split(' ')
inp = [int(i_) for i_ in inp]
print(c(inp))

# Example run
# Input:
dhf17s
107530361
# Output:
0 107530362
0
n = int(input())
a = list(map(int, input().split()))
count_1 = 0
count_2 = 0

for i in range(len(a)):
    if i == 0:
        count_1 += abs(1 - a[i])
    elif i % 2 == 1:
        count_1 += abs(-2 - a[i])
    elif i % 2 == 0:
        count_1 += abs(2 - a[i])

for i in range(len(a)):
    if i == 0:
        count_2 += abs(-1 - a[i])
    elif i % 2 == 1:
        count_2 += abs(2 - a[i])
    elif i % 2 == 0:
        count_2 += abs(-2 - a[i])

print(count_1 if count_1 < count_2 else count_2)

# Example run
# Input:
6462056
-97071
# Output:
97070
n = int(input())
a = [int(_) for _ in input().split()]
even_p = 0
even_n = 0
odd_p = 0
odd_n = 0

cnt = 0
# a[0] positive ver.
if a[0] > 0:
    sum_i = a[0]
else:
    cnt += abs(a[0]-1)
    sum_i = 1

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

cnt = 0
# a[0] negative ver.
if a[0] < 0:
    sum_i = a[0]
else:
    cnt += abs(a[0]+1)
    sum_i = -1

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

print(min(ans, cnt))

# Example run
# Input:
-31
-58867430
# Output:
0
n = int(input())
A = list(map(int, input().split()))
ans1 = 0
acc = 0
d = 1
for a in A:
    if (acc + a) * d > 0:
        acc += a
    else:
        ans1 += abs(1 - (acc + a) * d)
        acc = d
    d *= -1
ans2 = 0
acc = 0
d = -1
for a in A:
    if (acc + a) * d > 0:
        acc += a
    else:
        ans2 += abs(1 - (acc + a) * d)
        acc = d
    d *= -1
print(min(ans1, ans2))

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

s = [sum(a[0:i+1]) for i in range(n)]
count = 0
total_delta = 0
if s[0] == 0:
    delta = -1 * (s[1] // abs(s[1]))
    total_delta += delta
    count += 1
for i in range(1, n):
    sign = (s[i-1] + total_delta) // abs(s[i-1] + total_delta)
    if (s[i] + total_delta) * sign > 0 :
        delta  = (sign * -1) - (s[i] + total_delta)
        total_delta += delta
        count += abs(delta)
    elif (s[i] + total_delta) == 0:
        total_delta += sign * -1
        count += 1
print(count)


# Example run
# Input:
1288
-11392175
# Output:
11394748
n = int(input())
A = list(map(int, input().split()))

sum = A[0]
ans = 0
if sum == 0:
    sum += 1
    ans += 1
for i in range(1, len(A)):
    if sum > 0:
        if sum + A[i] >= 0:
            ans += abs(sum + A[i]) + 1
            sum = -1
        else:
            sum += A[i]
            continue
    elif sum < 0:
        if sum + A[i] <= 0:
            ans += abs(sum + A[i]) + 1
            sum = 1
        else:
            sum += A[i]
            continue
print(ans)


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

if a[0]>0:
    P=0
    SUMP=a[0]
else:
    P=1-a[0]
    SUMP=1
for i in range(1,n):
    if i%2==0:
        if SUMP+a[i]>=1:
            P+=0
            SUMP=SUMP+a[i]
        else:
            P+=1-(SUMP+a[i])
            SUMP=1
    elif i%2==1:
        if SUMP+a[i]<=(-1):
            P+=0
            SUMP=SUMP+a[i]
        else:
            P+=SUMP+a[i]+1
            SUMP=(-1)
if a[0]<0:
    N=0
    SUMN=a[0]
else:
    N=1-a[0]
    SUMN=(-1)
for i in range(1,n):
    if i%2==1:
        if SUMN+a[i]>=1:
            N+=0
            SUMN=SUMN+a[i]
        else:
            N+=1-(SUMN+a[i])
            SUMN=1
    elif i%2==0:
        if SUMN+a[i]<=(-1):
            N+=0
            SUMN=SUMN+a[i]
        else:
            N+=SUMN+a[i]+1
            SUMN=(-1)
print(min(P,N))

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

def solve(isPositive):
    sum_a = 0
    ans = 0
    for a in A:
        sum_a += a
        
        # 一回前が正か？
        if isPositive:
            # 一回前が正の場合、今回は負にならないといけない
            # そのため、0以上ならば負になるように調整
            if sum_a>=0:
                ans += 1 + sum_a
                # 最小回数の操作なので、sum_aはマイナス1になる
                sum_a = -1
            isPositive = False
        else:
            if sum_a<=0:
                ans += 1 - sum_a
                sum_a = 1
            isPositive = True
            
    return ans

print(min(solve(False), solve(True)))

# Example run
# Input:
1813543
-252699780
# 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:
  opp=0
  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
  sum=a[0]
  opm=abs(sum)+1
  if(sum>0):sum=-1
  else: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(opp,opm)
    
print(op)

# Example run
# Input:
-8135
-671550176
# Output:
0
n = int(input())

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

sum = 0
count = 0

for i in range(0,n - 1):
    sum += As[i]
    if sum > 0:
        if sum + As[i + 1] > 0:
            count += max(sum + As[i + 1] + 1,0)
            As[i + 1] -= sum +  As[i + 1] + 1
    elif sum == 0:
        count += 1
        if As[i + 1] >=0:
            sum -= 1
        else:
            sum += 1
    else:
        if sum + As[i + 1] < 0:
            count += max(abs(sum + As[i + 1] - 1),0)
            As[i + 1] += abs(sum + As[i + 1] - 1)

sum += As[-1]
if sum == 0:
    count += 1

print(count)


# Example run
# Input:
-10
453
# Output:
0
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count3 = 0
count4 = 0

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[i] <= 0 and restSum == 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
        
        
print(count3)


# Example run
# Input:
1
17917685
# Output:
0
n  = int(input())
A = list(map(int,input().split()))
pal = [-1,1]
cnt = 10**18
for p in pal:
    s = 0
    tmp = 0
    prev = p
    for a in A:
        s+=a
        if s==0:
            tmp+=1
            s = prev
            prev*=-1
            continue
        if a==0:
            tmp +=abs(s)+1
            s = prev
            prev*=-1
            continue
        if s//abs(s) != prev:
            tmp+=abs(s)+1
            s = prev
        else:
            pass
        prev*=-1
    cnt = min(cnt,tmp)
print(cnt)


# Example run
# Input:
-28
187
# Output:
0
n = int(input())
A = list(map(int, input().split()))
def solve(A, p):
  act = 0
  total = 0
  for a in A:
    total += a
    if total * p < 1:
      act += abs(p - total)
      total = p
    p *= -1
  return act
ans = min(solve(A, 1), solve(A, -1))
print(ans)

# Example run
# Input:
5460
2
# Output:
0
def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = [[0] * (N+1) for _ in range(2)]
    ans = [0] * 2
    for i in range(N):
        for n in range(2):
            total[n][i+1] = total[n][i] + A[i]
            if (i+n) % 2 == 0:
                if total[n][i+1] <= 0:
                    ans[n] += 1 - total[n][i+1]
                    total[n][i+1] = 1
            else:
                if total[n][i+1] >= 0:
                    ans[n] += total[n][i+1] + 1
                    total[n][i+1] = -1
    print(min(ans))


if __name__ == "__main__":
    main()


# Example run
# Input:
-7737
-126905272
# Output:
0
def main():
    from itertools import accumulate

    N = int(input())
    *A, = map(int, input().split())
    *acc, = accumulate(A)

    def count(w: int = 1) -> int:
        # m: -+-+-
        # w: +-+-+
        ret = 0
        add_val = 0
        for i, x in enumerate(acc):
            if (i & 1) ^ w:
                b = max(0, 1 - (x + add_val))
                ret += b
                add_val += b

            else:
                b = max(0, (x + add_val) - (-1))
                ret += b
                add_val -= b
        return ret

    ans = min(
        count(w=0),
        count(w=1)
    )

    print(ans)


if __name__ == '__main__':
    main()


# Example run
# Input:
-3228579
-28608
# Output:
0
n = int(input())
a = list(map(int, input().split()))
i = 0
sum_before = 0
sum_after = 0
count = 0
if a[0] == 0:
    if sum(a) > 0:
        a[0] = 1
    else:
        a[0] = -1
    count += 1

while i < n:
    sum_after = sum_before + a[i]
    if sum_after * sum_before > 0 or sum_after == 0:
        if sum_after < 0:
            a[i] = a[i] - sum_after + 1
        elif sum_after > 0:
            a[i] = a[i] - sum_after - 1
        elif sum_before < 0:
            a[i] += 1
        else:
            a[i] -= 1
        count += abs(sum_after) + 1
        sum_after = sum_before + a[i]
    i += 1
    sum_before = sum_after

print(count)
 




# Example run
# Input:
-3122
424
# Output:
0
import sys
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
a = list(map(int, input().split()))
b = a[:]
# 無変更チェック
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    break
  elif S>0 and S+int(a[i])>=0:
    break
  S+=int(a[i])
  if i==n-1:
    print(counter_1)
    sys.exit()
# a[0]を1に変えた場合の計算
counter_1=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_1+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_1+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_2=abs(int(a[0])+1)
a[0]=-1
S=a[0]
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_2+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_2+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
print(min(counter_1,counter_2))

# Example run
# Input:
-31
-58867430
# Output:
58867429
N = int(input())
A = list(map(int,input().split()))
ret = 0
def count(nega):
  ret = 0
  s = 0
  for e in A:
    nega = not nega
    #print(e,ret,s,s+e)
    if nega and 0 <= s + e:
      ret += abs(s + e) + 1
      s = -1
    elif not nega and s + e <= 0:
      ret += abs(s + e) + 1
      s = 1
    else:
      s += e
  return ret
print(min(count(True),count(False)))


# Example run
# Input:
-635811
-47579
# Output:
0
n = int(input())
i = input()

i = i.split()
for item in range(len(i)):
    i[item] = int(i[item])

totn = 0
totp = 0

countp = 0
countn = 0

for x in range(len(i)):
    totp += i[x]
    totn += i[x]
    
    if x == 0:
        if totp == 0:   
            totn = -1
            countn = 1

            totp = 1
            countp = 1
            
        elif totp < 0:
            countp = abs(totp) + 1
            totp = 1

        elif totp > 0:
            countn = abs(totn) + 1
            totn = -1

    elif x %2 == 1:
        if totn == 0:
            countn += 1
            totn = 1
        elif totn < 0:
            countn += abs(totn) + 1
            totn = 1

        if totp == 0:
            countp += 1
            totp = -1
        elif totp > 0:
            countp += abs(totp) + 1
            totp = -1

    elif x %2 == 0:
        if totn == 0:
            countn += 1
            totn = -1
        elif totn > 0:
            countn += abs(totn) + 1
            totn = -1

        if totp == 0:
            countp += 1
            totp = 1
        elif totp < 0:
            countp += abs(totp) + 1
            totp = 1
    '''print('totn', totn)
    print('countn', countn)
    print('totp', totp)
    print('countp', countp) '''   
count = min(countn, countp)
print(count)


# Example run
# Input:
31499
-58743
# 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()

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

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

count2 = abs(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:
-39
2569
# Output:
0
# -*- coding: utf-8 -*-
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
aa = list(accumulate(a))
cnt1 = 0
cnt2 = 0
#+はじまり
modify_sum1 = 0
start1 = 1
for ai in aa:
    cur_val1 = (ai + modify_sum1)*start1
    if cur_val1 <= 0:
        cnt1+=1 - cur_val1
        modify_sum1+=(1 - cur_val1)*start1
    start1 *= (-1)
#-はじまり
modify_sum2 = 0
start2 = -1
for ai in aa:
    cur_val2 = (ai + modify_sum2)*start2
    if cur_val2 <= 0:
        cnt2+=1 - cur_val2
        modify_sum2+=(1 - cur_val2)*start2
    start2 *= (-1)
print(min([cnt1,cnt2]))


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

# Example run
# Input:
23
-3964499
# Output:
0
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

acc = [0] * n
acc[0] = A[0]
for i in range(1, n):
    acc[i] = acc[i - 1] + A[i]

ans = 0
if acc[0] == 0:
    acc[0] += 1
    ans += 1
cur = acc[0]
x = 0
for i in range(1, n):
    acc[i] += x
    if cur > 0:
        if acc[i] >= 0:
            ans += acc[i] + 1
            x -= acc[i] + 1
            acc[i] = -1
    else:
        if acc[i] <= 0:
            ans += abs(acc[i]) + 1
            x += abs(acc[i]) + 1
            acc[i] = 1
    cur = acc[i]
print(ans)


# Example run
# Input:
1
30
# Output:
0
N = int(input())
a =list(map(int,input().split()))
a1=[0]*N
a2=[0]*N

s1 =a[0]
s2 =a[0]
#正の数から始まるパターン
c1 = 0
if s1 ==0:
    s1 = 1
    c1 = 1
elif s1 <0:
    a1[0]=1
    c1 = -s1+1

for i in range(1,N):
    if s1*(s1+a[i])>=0 and s1>0:
        a1[i] = -s1-1
        c1 += abs(a[i]-a1[i])
    elif s1*(s1+a[i])>=0 and s1<0:
        a1[i] = -s1+1
        c1 += abs(a1[i]-a[i])
    else:
        a1[i]=a[i]
    s1 = s1+a1[i]
#負の数から始まるパターン

c2=0
if s2 ==0:
    s2 = 1
    c2 =1
elif s2 >0:
    a2[0]=-1
    c2 = s2+1
    
for i in range(1,N):
    if s2*(s2+a[i])>=0 and s2>0:
        a2[i] = -(s2+1)
        c2 +=abs(a[i]-a2[i])
    elif s2*(s2+a[i])>=0 and s2<0:
        a2[i] = -s2+1
        c2 +=abs(a2[i]-a[i])
    else:
        a2[i]=a[i]
    s2 = s2+a2[i]    
    


print(min(c1,c2))

# Example run
# Input:
-407
0
# Output:
1
n=int(input())
a=list(map(int,input().split()))
ans_o=0
cnt_o=0
ans_e=0
cnt_e=0
for i in range(n):
  cnt_o+=a[i]
  if i%2==0:
    if cnt_o>0:
      continue
    else:
      ans_o+=abs(cnt_o)+1
      cnt_o=1
  else:
    if cnt_o<0:
      continue
    else:
      ans_o+=cnt_o+1
      cnt_o=-1
for i in range(n):
  cnt_e+=a[i]
  if i%2==0:
    if cnt_e<0:
      continue
    else:
      ans_e+=cnt_e+1
      cnt_e=-1
  else:
    if cnt_e>0:
      continue
    else:
      ans_e+=abs(cnt_e)+1
      cnt_e=1
print(min(ans_o,ans_e))

# Example run
# Input:
-3753932
42339391
# Output:
0