Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N = int(input())
a = [int(i) for i in input().split()]
 
def pura(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += 1 + abs(A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 + check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 + check))
                A[i] = 1 - check
        check += A[i]
    return ans
 
def mai(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] >= 0:
        ans +=1 + abs(A[0])
        A[0] = -1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 - check))
                A[i] = 1 - check
        else:
            if check + A[i] >= 0:
                ans += abs(A[i] +( 1 + check))
                A[i] = -1 - check
        check += A[i]
    return ans
print(min(pura(a), mai(a)))

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


def calc(val):
    # valには、１か−１を入れる。
    if (val * a[0] > 0):
        # 狙った符号のパターン
        temp = a[0]
        ans01 = 0

    else:
        # 違うパターン
        add = abs(a[0]) + 1
        ans01 = add
        temp = val

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

    return ans01


ans = min(calc(1), calc(-1))


print(ans)


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

count = 0
sum_i = a[0]

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

if neg_count < pos_count:
    count = neg_count
else:
    count = pos_count

print(count)


# Example run
# Input:
-10841372
-2552
# Output:
0
n=int(input())
a = list(map(int,input().split()))
sum_tmp = a[0]
ans = 0

if sum_tmp > 0:
    target = -1
elif sum_tmp < 0:
    target = 1
else:
    sum_tmp += 1
    ans += 1
    target = -1

for i in range(1,n):
    sum_tmp += a[i]
    if target == -1:
        if sum_tmp > -1:
            diff = sum_tmp + 1
            ans += diff
            sum_tmp -= diff
            target = 1
        else:
            target = 1
    else:
        if sum_tmp < 1:
            diff = 1 - sum_tmp
            ans += diff
            sum_tmp += diff
            target = -1
        else:
            target = -1

print(ans)

# Example run
# Input:
-4092419
-1
# Output:
0
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  Cost = 0
  # 符号 positive?
  #po_ = True 
  # 変わったか変わってないか
  ANS = [0] * (n)
  if A[0] > 0:
    pri_po = True
  elif A[0] == 0:
    pri_po = True
    A[0] += 1
    Cost += 1
  else:
    pri_po = False
  
  ANS[0] = A[0]
  
  for i in range(1,n):
    #print(ANS[i-1],pri_po,Cost)
    if ANS[i-1] + A[i] > 0 and pri_po == True:
      pri_po = False
      Cost += abs(-1 - (ANS[i-1] + A[i]))
      #print(abs(-1 - (ANS[i-1] + A[i])))
      A[i] -= abs(-1 - (ANS[i-1] + A[i]))
      #print('Hi^^',A[i])
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1] + A[i] == 0 and pri_po == False:
      pri_po = True
      Cost += 1
      A[i] += 1
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1] + A[i] == 0 and pri_po == True:
      pri_po = False
      Cost += 1
      A[i] -= 1
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1] + A[i] > 0 and pri_po == False:
      pri_po = True
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1] + A[i] < 0 and pri_po == True:
      pri_po = False
      ANS[i] = ANS[i-1] + A[i]
    elif ANS[i-1] + A[i] < 0 and pri_po == False:
      pri_po = True
      Cost += 1 - (ANS[i-1] + A[i])
      A[i] += 1 - (ANS[i-1] + A[i])
      ANS[i] = ANS[i-1] + A[i]
    else:
      pass
  print(Cost)
if __name__ == '__main__':
  main()

# Example run
# Input:
1
1
# Output:
0
import copy

n = int(input())
a = list(map(int, input().split()))
b = copy.copy(a)
c = copy.copy(a)
if a[0] == 0:
    b[0] = 1
    c[0] = -1
# print(a,b,c)
def sequence(x):
    if x[0] == 0:
        return(-1)
    else:
        cnt = 0
        sum = x[0]
        s = [x[0]]
        for i in range(1,n):
            sum = sum + x[i]
            if s[i-1]*sum < 0:
                s.append(sum)
                flag = 3
            else:
                if s[i-1] > 0:
                    cnt = cnt + (sum + 1)
                    sum = -1
                    s.append(sum)
                    flag = 4
                elif s[i-1] < 0:
                    cnt = cnt + (-1)*(sum - 1)
                    sum = 1
                    s.append(sum)
                    flag = 5
        return(cnt)
A = sequence(a)
B = sequence(b)+1
C = sequence(c)+1
# print(A,B,C)
D = min([i for i in (A,B,C) if i >= 0])
print(D)

# Example run
# Input:
1
-124978655
# Output:
0
n = int(input())
a = list(map(int,input().split()))
A = [n for n 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:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = -1
    cnt2 = a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
elif a[0] < 0:
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = 1
    cnt2 = -a[0] + 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
else:
    a[0] = 1
    cnt1 = 1
    for i in range(n-1):
        S += a[i]
        if a[i] > 0:
            while S + a[i+1] >= 0:
                a[i+1] -= 1
                cnt1 += 1
        elif a[i] < 0:
            while S + a[i+1] <= 0:
                a[i+1] += 1
                cnt1 += 1
    A[0] = -1
    cnt2 = 1
    for i in range(n-1):
        S += A[i]
        if A[i] > 0:
            while S + A[i+1] >= 0:
                A[i+1] -= 1
                cnt2 += 1
        elif A[i] < 0:
            while S + A[i+1] <= 0:
                A[i+1] += 1
                cnt2 += 1
cnt = cnt2 if cnt1 >= cnt2 else cnt1

print(cnt)


# Example run
# Input:
-1921542
0
# Output:
1
N = int(input())
a = [int(i) for i in input().split()]

def pura(A):
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += abs(1-A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 + check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 + check))
                A[i] = 1 - check
        check += A[i]
    return ans

def mai(A):
    ans = 0
    check = 0
    if A[0] >= 1:
        ans +=1+abs(A[0])
        A[0] = -1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 + check))
                A[i] = 1 - check
        else:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 + check
        check += A[i]
    return ans
print(min(pura(a), mai(a)))

# Example run
# Input:
-9
-13574883
# Output:
2
n=input()
a=[int(i) for i in 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
        elif 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:
)FAM
1506843
# Output:
0
N = int(input())
A = list(map(int, input().split()))

cntA, sumA = 0, 0
for i in range(N):
    sumA += A[i]
    if i % 2 == 0:
        if sumA <= 0:
            cntA += abs(sumA) + 1
            sumA += abs(sumA) + 1
    else:
        if sumA >= 0:
            cntA += abs(sumA) + 1
            sumA -= abs(sumA) + 1
            
cntB, sumB = 0, 0
for i in range(N):
    sumB += A[i]
    if i % 2 != 0:
        if sumB >= 0:
            cntB += abs(sumB) + 1
            sumB += abs(sumB) + 1
    else:
        if sumB >= 0:
            cntB += abs(sumB) + 1
            sumB -= abs(sumB) + 1

print(min(cntA, cntB))

# Example run
# Input:
0
227
# Output:
0
n = int(input())
a = list(map(int, input().split()))
 
lis=[]
now=0
for num in a:
    now+=num
    lis.append(now)
 
ans=10**20
cnt=0
sm=0
for i in range(len(lis)):
    if i%2==0:
        if lis[i]+sm >= 0:
            add = lis[i]+sm+1
            cnt+= add
            sm=-add
    else:
        if lis[i]+sm <= 0:
            add = abs(1-lis[i]-sm)
            cnt+= add
            sm=add
ans=min(ans,cnt)
 
cnt=0
sm=0
for i in range(len(lis)):
    if i%2==1:
        if lis[i]+sm >= 0:
            add = lis[i]+sm+1
            cnt+= add
            sm=-add
    else:
        if lis[i]+sm <= 0:
            add = abs(1-lis[i]-sm)
            cnt+= add
            sm=add
ans=min(ans,cnt)
print(ans)

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

CumSum = [0] * n
c = 0
for i,a in enumerate(A):
    c += a
    CumSum[i] = c
# 最初が正の場合
total_cost = 0
c_sum = 0
for i,a in enumerate(A):
    c_sum += a
    if i % 2 ==0:
        if c_sum > 0:
            continue
        total_cost += abs(c_sum)+ 1
        c_sum = 1
        continue

    if c_sum < 0:
        continue
    total_cost += abs(c_sum)+ 1
    c_sum = -1
# 最初が負の場合
total_cost2 = 0
c_sum = 0
for i,a in enumerate(A):
    c_sum += a
    if i % 2 ==0:
        if c_sum < 0:
            continue
        total_cost2 += abs(c_sum)+ 1
        c_sum = -1
        continue

    if c_sum > 0:
        continue
    total_cost2 += abs(c_sum)+ 1
    c_sum = 1
print(min(total_cost,total_cost2))



# Example run
# Input:
11099514
313
# Output:
0
n = int(input())
a = list(map(int, input().split()))
minnum = float('inf')
for m in range(2):
    ans = 0
    s = [0]*(n+1)
    tmp = a[0] 
    if m == 0:
        if a[0] >= 0:
            ans += a[0]+1
            a[0] = -1 
    else:
        if a[0] <= 0:
            ans += abs(a[0])+1
            a[0] = 1

    for i in range(n):
        s[i+1] = s[i] + a[i]
        if s[i] < 0:
            if s[i+1] != 0 and s[i+1] > 0:
                continue
            else:
                ans += abs(s[i+1])+1
                s[i+1] = 1
        elif s[i] > 0:
            if s[i+1] != 0 and s[i+1] < 0:
                continue
            else:
                ans += abs(s[i+1])+1   
                s[i+1] = -1

    minnum = min(minnum,ans)
    a[0] = tmp

print(minnum) 

# Example run
# Input:
-126905272
28016
# 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
        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:
1
-4
# Output:
0
def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

# Example run
# Input:
s]`tEQJ%'
0
# Output:
1
N = int(input())
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]

for i in range(1,N):
    S[i] = S[i-1] + a[i]

count = [0]*N
num = [0]*2
for i in range(2):
    value = 0
    for j in range(N):
        if (S[j]+value)*((-1)**(i+j)) <= 0:
            num[i] += abs(S[j] + value - (-1)**(i+j))
            value += (-1)**(i+j) - S[j]
        #print(i,num,value)

#print(S)
print(min(num))

# Example run
# Input:
1
0
# Output:
1
import itertools
N = input()
l = list(map(int,input().split(" ")))
ruiseki = 0
ans = [0,0]
for pattern in [0,1]: #奇偶による+-を制御
    ruiseki = 0
    for i,num in enumerate(l):
        ruiseki += num
        if (i+pattern) %2 == 0:
            if ruiseki >= 0:
                ans[pattern] += ruiseki + 1
                ruiseki = -1
        else:
            if ruiseki <= 0:
                ans[pattern] +=1-ruiseki
                ruiseki = 1
print(min(ans))


# Example run
# Input:
v>z%!
-450
# Output:
0
n = int(input())
a = list(map(int, input().split()))

result = []

for i in range(2):
    num = 0
    r = 0
    for j in range(len(a)):
        num += a[j]
        if (j + i) % 2 == 0:
            if num <= 0:
                r -= num - 1
                num = 1

        else:
            if num >= 0:
                r += num + 1
                num = -1

    result.append(r)

print(min(result))


# Example run
# Input:
-8
-39
# Output:
0
n=int(input())
a=list(map(int,input().split()))
u=0
s=1
x=0
y=0
for i in a:
    u+=i
    if s*u<=0:
      x+=1-s*u
      u=s
    s=s*(-1)
s=-1
u=0
for i in a:
    u+=i
    if s*u<=0:
      y+=1-s*u
      u=s
    s=-1*s
print(min(x,y))

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

#マイナススタート
now = 0
count = 0
for i,j in enumerate(a):
    now += j
    if i%2 == 0:
        if now >= 0:
            count += abs(now)+1
            now = -1
    else:
        if now <= 0:
            count += abs(now)+1
            now = 1

#プラススタート
now = 0
count2 = 0
for i,j in enumerate(a):
    now += j
    if i%2 == 0:
        if now <= 0:
            count2 += abs(now)+1
            now = 1
    else:
        if now >= 0:
            count2 += abs(now)+1
            now = -1

print(min(count,count2))

# Example run
# Input:
-83
0
# Output:
1
N = int(input())
a = [int(i) for i in input().split()]
 
def pura(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += 1 + abs(A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 - check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 - check))
                A[i] = 1 - check
        check += A[i]
    return ans
 
def mai(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] >= 0:
        ans +=1 + abs(A[0])
        A[0] = -1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 - check))
                A[i] = 1 - check
        else:
            if check + A[i] >= 0:
                ans += abs(A[i] +( 1 + check))
                A[i] = -1 - check
        check += A[i]
    return ans
print(min(pura(a), mai(a)))

# Example run
# Input:
-38606206
6825
# Output:
0
import copy


def resolve(L_input):
    L = copy.deepcopy(L_input)
    cnt = 0
    s = L[0]
    for i in range(1, len(L)):
        a = L[i]
        if s > 0 and s+a >= 0:
            L[i] = -s-1
            cnt += (s+a+1)
            s = -1
        elif s < 0 and s+a <= 0:
            L[i] = -s+1
            cnt += (-s-a+1)
            s = 1
        else:
            s += a

    return cnt


def solution(L):
    first_term = L[0]
    if first_term > 0:
        L_positive = L
        first_positibe_cnt = resolve(L_positive)
        # extract first_term+1 to first_term to be -1
        L_negative = [-1]+L[1:]
        first_negative_cnt = (first_term+1) + resolve(L_negative)
    elif first_term < 0:
        # add -first_term+1 to first_term to be 1
        L_positive = [1]+L[1:]
        first_positibe_cnt = (-first_term+1) + resolve(L_positive)
        L_negative = L
        first_negative_cnt = resolve(L_negative)
    else:
        # add 1 to first_term to be 1
        L_positive = [1]+L[1:]
        first_positibe_cnt = 1 + resolve(L_positive)
        # extract 1 to first_term to be -1
        L_negative = [-1]+L[1:]
        first_negative_cnt = 1 + resolve(L_negative)

    # print("first_positive, cnt: {}".format(first_positibe_cnt))
    # print(L_positive)
    # print("first_negative_cnt, cnt: {}".format(first_negative_cnt))
    # print(L_negative)

    return min(first_positibe_cnt, first_negative_cnt)


if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split(' ')))
    print(solution(L))


# Example run
# Input:
1792657
-728818981
# Output:
0
n=input()
a=[int(i) for i in 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
        elif 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:
.s09
-1
# Output:
0
import copy 

def resolve(List):
    # L[0]!=0を起点とする
    L = copy.deepcopy(List)
    cnt = 0
    s = L[0]
    for i in range(1,len(L)):
        a = L[i]
        if(s>0 and s+a>=0):
            L[i] = -s-1
            cnt += (s+a+1)
            s = -1
        elif(s<0 and s+a<=0):
            L[i] = -s+1
            cnt += (-s-a+1)
            s = 1
        else:
            s += a
    return cnt      

def ans(List):
    L = copy.deepcopy(List)
    a = L[0]
    c0,c1=0,0

    if (a>0):
        c0 = resolve(L)
        c1 = (a+1) + resolve([-1]+L[1:])
    elif (a<0):
        c0 = resolve(L)
        c1 = (-a+1) + resolve([1]+L[1:])
    else:
        c0 = 1 + resolve([1]+L[1:])
        c1 = 1 + resolve([-1]+L[1:])
    
    return(min(c0,c1))

N = int(input())
List = [int(x) for x in input().split(' ')]
print(ans(List))


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