Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
# coding: utf-8
# Here your code



N = int(input())
a = [int(i) for i in input().split()] 

result_1 = 0
before_sum =a[0]
if a[0] == 0:
    before_sum = 1
    result_1 += 1
after_sum =a[0]

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if before_sum * after_sum > 0:
        if after_sum < 0:
            result_1 += 1 - after_sum
            after_sum = 1
        elif after_sum > 0:
            result_1 += 1 + after_sum
            after_sum = -1
    elif before_sum * after_sum == 0:
        result_1 += 1
        if before_sum < 0:
            after_sum = 1
        else:
            after_sum = -1

if a[0] < 0:
    before_sum = 1
elif a[0] >= 0:
    before_sum = -1
after_sum =a[0]
result_2 = 1 + abs(before_sum)


for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if before_sum * after_sum > 0:
        if after_sum < 0:
            result_2 += 1 - after_sum
            after_sum = 1
        elif after_sum > 0:
            result_2 += 1 + after_sum
            after_sum = -1
    elif before_sum * after_sum == 0:
        result_2 += 1
        if before_sum < 0:
            after_sum = 1
        else:
            after_sum = -1

print(min(result_1,result_2))


# Example run
# Input:
-4852
-348121
# Output:
0
n = int(input())
a_list = list(map(int, input().split(' ')))

def count_manipulation(a_list, start):
    assert start in (0, 1)
    sum = 0
    count = 0
    for i, a in enumerate(a_list):
        sum += a
        if i % 2 == start:
            if sum > 0:
                continue
            else:
                diff = 1 - sum
                count += diff
                sum += diff
        else:
            if sum < 0:
                continue
            else:
                diff = sum - (-1)
                count += diff
                sum -= diff
    return count

count_plus = count_manipulation(a_list, 0)
count_minus = count_manipulation(a_list, 1)
print(min(count_plus, count_minus))


# Example run
# Input:
-12
242208
# Output:
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
anti_delay = 0
anti_all_over = 0
if a[0] != 0:
  antiL = L[:]
  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
  if antiL[0] < 0:
    sign = 1
    anti_delay = 1 - antiL[0]
    anti_all_over = 1 - antiL[0]
  else:
    sign = 1
    anti_delay = antiL[0] - 1
    anti_all_over = antiL[0] - 1
  for i in range(1, n):
    antiL[i] += anti_delay
    if antiL[i] <= 0 and sign == -1:
      anti_delay += 1 - antiL[i]
      anti_all_over += 1 - antiL[i]
      antiL[i] = 1
    elif antiL[i] >= 0 and sign == 1:
      anti_delay -= antiL[i] + 1
      anti_all_over += antiL[i] + 1
      antiL[i] = -1
    sign *= -1
  print(min(anti_all_over, 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
4887419
# Output:
0
n = int(input())
a = list(map(int, input().split()))

def chk(a,first):
    count = 0
    x = 0 # sum
    t = first # True : plus, False : minus
    for item in a:
        x += item
        if t == True and x<1:
            count += 1-x
            x = 1
        elif t == False and x>-1:
            count += x+1
            x = -1
        t = not t
    return count

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

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

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

# A[0] の初期符号が正しいと仮定してしまっているが、そうとは限らない。
a = A[0]
q = 10**15
if a > 0:
    q = min(f(a,0), f(-1,a+1))
elif a < 0:
    q = min(f(a,0),f(1,-a+1))
else:
    q = min(f(1,1),f(-1,1))

print(q)

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

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S < 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-1 if A[0] > 0 else 1) + abs(A[0]) + 1)
print(ans)


# Example run
# Input:
-227170451
13499019
# Output:
0
N = int(input())
src = list(map(int,input().split()))

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

# Example run
# Input:
337
11991
# Output:
0
n=int(input())
A=list(map(int, input().split()))
#値のコピーを作るときはスライスする
B=A[:]

#a1の符号を正にする場合
count_1=0
sum_1=0
if A[0]==0:
    A[0]+=1
    count_1+=1
    sum_1+=A[0]
elif A[0]>0:
    sum_1+=A[0]
elif A[0]<0:
    A[0]=1
    count_1+=(abs(A[0])+1)
    sum_1+=A[0]

for i in range(1,n):
    #奇数番目の項までの和は正に
    if i%2==0:#奇数番目の項
        if sum_1+A[i]>0:
            sum_1+=A[i]
        elif sum_1+A[i]<0:
            count_1 += (abs(sum_1+A[i])+1)
            sum_1=1
        elif sum_1+A[0]==0:
            count_1+=1
            sum_1=1
        else:
            pass
    #偶数番目の項までの和は負に
    elif i%2==1:#偶数番目の項
        if sum_1+A[i]>0:
            count_1 += (abs(sum_1+A[i])+1)
            sum_1=-1
        elif sum_1+A[i]<0:
            sum_1+=A[i]
        elif sum_1+A[i]==0:
            sum_1 = -1
            count_1+=1
        else:
            pass


#a1の符号を負にする場合
count_2=0
sum_2=0
if B[0]==0:
    B[0]-=1
    count_2+=1
    sum_2+=B[0]
elif B[0]>0:
    B[0]= -1
    count_2+=(abs(B[0])+1)
    sum_2+=B[0]
elif B[0]<0:
    sum_2+=B[0]

for i in range(1,n):
    if i%2==0:#奇数番目の項
    #奇数番目の項までの和は負に
        if sum_2+B[i]>0:
            count_2 += (abs(sum_2+B[i])+1)
            sum_2= -1
        elif sum_2+B[i]<0:
            sum_2+=B[i]
        elif sum_2+B[i]==0:
            sum_2 = -1
            count_2+=1
        else:
            pass
    #偶数番目の項までの和は負に
    elif i%2==1:#偶数番目の項
        if sum_2+B[i]>0:
            sum_2+=B[i]
        elif sum_2+B[i]<0:
            count_2 += (abs(sum_2+B[i])+1)
            sum_2=1
        elif sum_2+B[i]==0:
            count_2+=1
            sum_2=1
        else:
            pass

print(min(count_1,count_2))


# Example run
# Input:
0
232953470
# Output:
0
n = int(input())

numbers = list(map(int, input().split()))
counter = 0
sum_i_n = 0
sum_i_n_1 = numbers[0]

for i in range(len(numbers) - 1):
    sum_i_n += numbers[i]
    sum_i_n_1 += numbers[i + 1]

    if sum_i_n == 0:
        numbers[i] += 1
        sum_i_n += 1
        sum_i_n_1 += 1
        counter += 1
    if sum_i_n * sum_i_n_1 > 0:
        sub_n = abs(sum_i_n)
        sub_n1 = abs(sum_i_n_1)
        if abs(sum_i_n) - abs(sum_i_n_1) > 0:
            if sum_i_n_1 > 0:
                numbers[i + 1] -= (sub_n1 + 1)
                sum_i_n_1 -= (sub_n1 + 1)
                counter += (sub_n1 + 1)
            else:
                numbers[i + 1] += (sub_n1 + 1)
                sum_i_n_1 += (sub_n1 + 1)
                counter += (sub_n1 + 1)
        else:
            if sum_i_n > 0:
                numbers[i] -= (sub_n + 1)
                sum_i_n -= (sub_n + 1)
                sum_i_n_1 -= (sub_n + 1)
                counter += (sub_n + 1)
            else:
                numbers[i] += (sub_n + 1)
                sum_i_n += (sub_n + 1)
                sum_i_n_1 += (sub_n + 1)
                counter += (sub_n + 1)
#        sub = abs(sum_i_n_1) + 1
#        counter += sub
#        if sum_i_n_1 > 0:
#            numbers[i + 1] -= sub
#            sum_i_n_1 -= sub
#        else:
#            numbers[i + 1] += sub
#            sum_i_n_1 += sub

if sum_i_n_1 == 0:
    counter += 1

print(counter)

# Example run
# Input:
-160045822
155287
# Output:
0
N = int(input())
src = list(map(int,input().split()))

cum1 = cum2 = 0
ans1 = ans2 = 0
for i,a in enumerate(src):
    cum1 += a
    cum2 += a
    if i%2:
        if cum1 >= 0:
            ans1 += cum1+1
            cum1 = -1
        if cum2 <= 0:
            ans2 += 1-cum2
            cum2 = 1
    else:
        if cum1 <= 0:
            ans1 += 1-cum1
            cum1 = 1
        if cum2 >= 0:
            ans2 += cum2+1
            cum2 = -1

print(min(ans1,ans2))


# Example run
# Input:
7
310244
# 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

print(min(cnt1,cnt2))
        

# Example run
# Input:
-7038374
-6
# Output:
0
n = int(input())
arr = [int(x) for x in input().split()]

def exec(sign):
    a = [x for x in arr]
    res = 0

    if a[0] == 0:
        a[0] = sign * (-1)
        res += 1

    x = 0
    for i in range(n-1):
        x += a[i]
        tmp = sign - (x + a[i+1])
        if sign < 0:
            tmp = min(tmp, 0)
        else:
            tmp = max(tmp, 0)
        res += abs(tmp)
        a[i+1] += tmp
        sign *= (-1)
    return res

print(min(exec(1), exec(-1)))


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

#値を修正する場合、1か−1にすればよい
##そのためには、値の絶対値に1を足した数を加えればよい

#正、負のパターンと負、正のパターンの両方について算出し、小さい方を出力する
##没解だと、所与のA[0]の符号を基準としたまま、答えを提出していたが、
##当然、それが最適値であるとは限らない！！！

total = 0
ans = 0
total2 = 0
ans2 = 0

for i in range(N):
    total += A[i]
    #奇数番目を正にする
    if i % 2 == 0:
        #1より小さい == 0以下
        if total < 1:
            ans += 1 - total
            total = 1
    else:
        #0以上
        if total > -1:
            ans += (1 + total)
            total = -1

for i in range(N):
    total2 += A[i]
    #偶数番目を正にする
    if i % 2 == 1:
        if total2 < 1:
            ans2 += 1 - total2
            total2 = 1
    else:
        if total2 > -1:
            ans2 += 1 + total2
            total2 = -1

print(min(ans,ans2))

# Example run
# Input:
-38181262
41286958
# Output:
0
n=int(input())
l=list(map(int,input().split()))

s=0
c=0
for (i,j) in enumerate(l):
  if i%2: #plus
    if s+j<=0:
      c+=(abs(s+j)+1)
      s=1
    else:
      s+=j
  else: #minus
    if s+j>=0:
      c+=(abs(s+j)+1)
      s=-1
    else:
      s+=j
a=c

s=0
c=0
for (i,j) in enumerate(l):
  if i%2==0: #plus
    if s+j<=0:
      c+=(abs(s+j)+1)
      s=1
    else:
      s+=j
  else: #minus
    if s+j>=0:
      c+=(abs(s+j)+1)
      s=-1
    else:
      s+=j
b=c
print(min(a,b))

# Example run
# Input:
-591
41555
# Output:
0
N = int(input())

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

cum_A = [0] * N

ans = 0
if A[0] == 0:
    ans += 1
    cum_A[0] = 1
else:
    cum_A[0] = A[0]


for i in range(1,N):
    if cum_A[i-1] < 0:
        if cum_A[i-1] + A[i] >= 1:
            cum_A[i] = cum_A[i-1] + A[i]
        else:
            ans += 1 - (cum_A[i-1] + A[i])
            cum_A[i] = 1
    else:
        if cum_A[i-1] + A[i] <= -1:
            cum_A[i] = cum_A[i-1] + A[i]
        else:
            ans += 1 + (cum_A[i-1] + A[i])
            cum_A[i] = -1

print(ans)

# Example run
# Input:
1
-514355545
# Output:
0
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans1 = 0
    S1 = [0] * N
    S1[0] = A[0]
    if A[0] == 0:
        S1[0] = -1
        ans1 += 1
    for i in range(1, N):
        S1[i] = S1[i-1] + A[i]
        if S1[i]*S1[i-1] < 0:
            continue
        if S1[i-1] > 0:
            S1[i] = -1
            ans1 += abs((-1) - (S1[i-1]+A[i]))
        else:
            S1[i] = 1
            ans1 += abs(1 - (S1[i-1]+A[i]))
    S2 = [0] * N
    ans2 = 0
    if A[0] > 0:
        S2[0] = -1
        ans2 += abs((-1) - A[0])
    else:
        S2[0] = 1
        ans2 += abs(1 - A[0])
    for i in range(1, N):
        S2[i] = S2[i-1] + A[i]
        if S2[i]*S2[i-1] < 0:
            continue
        if S2[i-1] > 0:
            S2[i] = -1
            ans2 += abs((-1) - (S2[i-1]+A[i]))
        else:
            S2[i] = 1
            ans2 += abs(1 - (S2[i-1]+A[i]))

    print(min(ans1, ans2))


if __name__ == '__main__':
    main()


# Example run
# Input:
1
-38175
# 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
            if i > 0:
                mov += 1
                mov_ += 1
            j = i
            break
        if i == len(ints) - 1:
            return i + 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:
T~.yFv
4
# Output:
0 5
0
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 15:51:53 2018

@author: maezawa
"""

def sign(x):
    return x//abs(x)

def f(n, a0, s):
    cnt = 0
    cum = 0
    for i, ai in enumerate(a):
        cum += ai
        if cum == 0:
            cnt += 1
            cum = (-1)**i*s
        elif sign(cum) == (-1)**i*s:
            continue
        else:
            cnt += abs(cum)+1
            cum = (-1)**i*s
    return cnt

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

cnt = 0
cnt0 = f(n, a, -1)
cnt1 = f(n, a, 1)
cnt = min([cnt0,cnt1])
print(cnt)
    

# Example run
# Input:
176191212
197383
# Output:
0
n=int(input())
a=list(map(int,input().split()))
dp=[0]*n
dp[0]=a[0]
for i in range(1,n):
  dp[i]=dp[i-1]+a[i]
ans1,ans2,cnt1,cnt2,flag=0,0,0,0,True
for i in range(n):
  if flag==True:
    if dp[i]+cnt1<=0:
      ans1+=abs(1-(dp[i]+cnt1))
      cnt1+=1-(dp[i]+cnt1)
    flag=False
  else:
    if dp[i]+cnt1>=0:
      ans1+=abs(-1-(dp[i]+cnt1))
      cnt1+=-1-(dp[i]+cnt1)
    flag=True

flag=False
for i in range(n):
  if flag==True:
    if dp[i]+cnt2<=0:
      ans2+=abs(1-(dp[i]+cnt2))
      cnt2+=1-(dp[i]+cnt2)
    flag=False
  else:
    if dp[i]+cnt2>=0:
      ans2+=abs(-1-(dp[i]+cnt2))
      cnt2+=-1-(dp[i]+cnt2)
    flag=True
print(min(ans1,ans2))

# Example run
# Input:
1
4887419
# Output:
0
n = int(input())
a = list(map(int,input().split()))
A = a[:]
count_plus=0
count_minus=0
x = 0
y = 0
for i in range(n):
  if i%2==0:
    x+=a[i]
    if x<=0:
      count_plus+=-1*x+1
      a[i]+=-1*x+1
      x=1
  else:
    x+=a[i]
    if x>0:
      count_plus+=x+1
      a[i]+=-1*x-1
      x=-1
for i in range(n):
  if i%2==0:
    y+=A[i]
    if y>=0:
      count_minus+=y+1
      A[i]+=-1*y-1
      y=-1
  else:
    y+=A[i]
    if y<0:
      count_minus+=-1*y+1
      A[i]+=-1*y+1
      y=1
if x==0:
  count_plus+=1
if y==0:
  count_minus+=1
print(min(count_plus,count_minus))

# Example run
# Input:
-15915
-501843
# Output:
1
# coding: utf-8
# Here your code

N = int(input())
a = [int(i) for i in input().split()] 

result_1 = 0
before_sum = a[0]

if a[0] <= 0:
    before_sum = 1
    result_1 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 0:
        if after_sum <= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = 1
    else:
        if after_sum >= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = -1

result_2 = 0
before_sum = a[0]

if a[0] >= 0:
    before_sum = -1
    result_2 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 1:
        if after_sum <= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = 1
    else:
        if after_sum >= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = -1

print(min(result_1,result_2))


# Example run
# Input:
-19799
-259420352
# Output:
0
n = int( input())
A = list( map( int, input().split()))
ansp = 0
sums = A[0]
if sums == 0:
    ansp += 1
    sums += 1
for i in range(1,n):
    sums += A[i]
    if i%2 == 1:
        if sums < 0:
            pass
        else:
            ansp += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansp += 1 - sums
            sums = 1
sums = A[0]
ansm = 0
if sums == 0:
    ansm += 1
    sums -= 1
for i in range(1,n):
    sums += A[i]
    if i%2 == 0:
        if sums < 0:
            pass
        else:
            ansm += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansm += 1 - sums
            sums = 1
print( min(ansp, ansm))

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

@functools.lru_cache()
def memo(n):
    ans1 = 0
    ans2 = 0
    now = 0

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

    now = 0

    for i in range(n):
        now += a[i]
        if i % 2 == 1:
            if now <= 0:
                ans2 += 1 - now
                now = 1
        else:
            if now >= 0:
                ans2 += now + 1
                now = -1
    
    return min([ans1,ans2])

print(memo(n))

# Example run
# Input:
1
0
# Output:
1
# coding: utf-8
# Here your code

N = int(input())
a = [int(i) for i in input().split()] 

result_1 = 0
before_sum = a[0]

if a[0] <= 0:
    before_sum = 1
    result_1 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 0:
        if after_sum <= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = 1
    else:
        if after_sum >= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = -1

result_2 = 0
before_sum = a[0]

if a[0] >= 0:
    before_sum = -1
    result_2 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 1:
        if after_sum >= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = -1
    else:
        if after_sum <= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = 1

print(min(result_1,result_2))


# Example run
# Input:
-15915
-501843
# Output:
0
n=int(input())
a=list(map(int,input().split()))
ans=10**19

for i in [-1,1]:
    b=0
    c=0
    for j in a:
        b+=j
        if b*i<=0:
            c+=abs(b-i)
            b=i
        i*=-1
    ans=min(ans,c)

print(ans)    

# Example run
# Input:
431
5
# Output:
0
def c(ints):
    
    for i in range(len(ints)):
        if ints[i] != 0:
            sig = 1 if ints[i] > 0 else -1
            total = ints[i]
            mov = i
            if i > 0:
                mov += 1
            j = i
            break
        if i == len(ints) - 1:
            return i + 1
    
    for i_ in ints[j+1:]:
        tmp = total + i_
        if tmp == 0:
            mov +=1
            tmp = -sig
            
        elif sig * tmp > 0:
            mov += abs(tmp) + 1
            tmp = -sig
            
        sig *= -1
        total = tmp
        
    return mov

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

# Example run
# Input:
X\&*
1900838388
# Output:
0
n = int(input())
a = list(map(int,input().split()))

ans1 = 0
ans2 = 0
tmp = 0

for i,e in enumerate(a):
    tmp += e
    if i % 2 == 0:
        if tmp > 0:
            pass
        else:
            ans1 += 1 - tmp
            tmp = 1
    else:
        if tmp < 0:
            pass
        else:
            ans1 += tmp + 1
            tmp = -1

tmp = 0

for i,e in enumerate(a):
    tmp += e
    if i % 2 == 1:
        if tmp > 0:
            pass
        else:
            ans2 += 1 - tmp
            tmp = 1
    else:
        if tmp < 0:
            pass
        else:
            ans2 += tmp + 1
            tmp = -1

print(min(ans1, ans2))


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

def ssa(n):
    arr = A
    memo =['inf'] * (n + 1)
    def _ssa(n):
        if n == 0:
            return arr[0]
        if memo[n] != 'inf':
            return memo[n]
        memo[n] = _ssa(n -1) + arr[n]
        return memo[n]
    return _ssa(n)

cnt = 0
chg = 0
for i in range(n - 1):
    if ssa(i) + chg > 0:
        if ssa(i + 1) + chg >= 0:
            cnt += ssa(i + 1) + chg + 1
            chg += -(ssa(i + 1)+ chg  + 1)
    elif ssa(i) + chg < 0:
        if ssa(i + 1) + chg <= 0:
            cnt += 1 - ssa(i + 1) - chg
            chg += 1 - ssa(i + 1) - chg

if ssa(n - 1) + chg == 0:
    cnt +=1

print(cnt)


# Example run
# Input:
1
2273269
# Output:
0
n = int(input())
A = list(map(int, input().split()))
ans = {True:0, False:0}
for s in [True, False]:
    sign = s
    total = 0
    for i in range(len(A)):
        if total + A[i] == 0 or sign == (total + A[i] > 0):
            ans[s] += abs(total + A[i]) + 1
            total = -1 if sign else 1
        else:
            total += A[i]
        sign = total > 0
print(min(ans.values()))


# Example run
# Input:
224
-3753932
# Output:
0
n = int(input())
a = list(map(int, input().split(' ')))
result = 0
h = 0
if a[0] == 0:
    a[0] += 1
    result += 1
    h = 1
counter = a[0]

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

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

# Example run
# Input:
-58743
-207
# Output:
0