Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n = int(input())
a = [int(i) for i in input().split()]
cur = 0
ans1, ans2 = 0,0
for i, x in enumerate(a):
    cur += x
    if i%2 == 0:
        if cur >= 1:
            continue
        else:
            ans1 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans1 += abs(-1-cur)
            cur = -1
for i, x in enumerate(a):
    cur += x
    if i%2 != 0:
        if cur >= 1:
            continue
        else:
            ans2 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans2 += abs(-1-cur)
            cur = -1
print(min(ans1, ans2))

# Example run
# Input:
-99110661
2
# Output:
0
def c_sequence():
    N = int(input())
    A = [int(i) for i in input().split()]

    def solver(sign):
        ret, total = 0, 0
        for a in A:
            total += a
            if sign * total <= 0:
                ret += abs(sign - total)  # 総和がsignになるまでaを変化させる
                total = sign
            sign *= -1
        return ret
    # 1: 奇数番目を正、偶数番目を負にする場合。 -1: その逆
    return min(solver(1), solver(-1))

print(c_sequence())

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




# Example run
# Input:
-48
465
# Output:
0
def main():
    n = int(input())
    A = [int(a) for a in input().split()]
    min_count = float('inf')
    if A[0] != 0:
        tot = A[0]
        count = 0
        for a in A[1:]:
            if tot > 0 and tot + a >= 0:
                count += tot+a+1
                tot = -1
            elif tot < 0 and tot + a <= 0:
                count += -(tot+a)+1
                tot = 1
            else:
                tot += a
        min_count = min(min_count, count)
    for i in [1, -1]:
        count = abs(i - A[0])
        tot = i
        for a in A[1:]:
            if tot > 0 and tot + a >= 0:
                count += tot+a+1
                tot = -1
            elif tot < 0 and tot + a <= 0:
                count += -(tot+a)+1
                tot = 1
            else:
                tot += a
        min_count = min(min_count, count)
    return min_count

if __name__ == '__main__':
    print(main())

# Example run
# Input:
-3123902
-39597485
# Output:
0
n=int(input())
an=list(map(int, input().split()))

def check(sign):
    a_cnt=0
    a_sum=0
    for a in an:
        a_sum+=a
        if a_sum*sign<=0:
            a_cnt+=abs(a_sum-sign)
            a_sum=sign
        sign*=-1

        # print(a_sum, a_cnt)

    return a_cnt

print(min(check(1),check(-1)))


# Example run
# Input:
-87
141725276
# Output:
0
# 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 =before_sum
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:
-1
2657144
# Output:
0
n = int(input())
a_list = list(map(int, input().split()))

total = 0
count = 0
pos_or_neg = True  # True = +, False = -

if sum(a_list) >= 0:
    if n % 2 == 0:
        pos_or_neg = False
    else:
        pos_or_neg = True
else:
    if n % 2 == 0:
        pos_or_neg = True
    else:
        pos_or_neg = False

for a in a_list:
    total += a
    if pos_or_neg:
        while total <= 0:
            total += 1
            count += 1
        pos_or_neg = False

    else:
        while total >= 0:
            total -= 1
            count += 1
        pos_or_neg = True

print(count)

# Example run
# Input:
137752
-5930
# Output:
5931
def ops_needed(x, target):
    if abs(target - x) < abs(x):
        return 0
    else:
        return target - x

def count_ops(a, first_target):
    total_ops = 0
    accum = 0
    for i, ai in enumerate(a):
        new_accum = accum + a[i]
        if i % 2 == 1:
            ops = ops_needed(new_accum, first_target)
        else:
            ops = ops_needed(new_accum, -1 * first_target)
        total_ops += abs(ops)
        accum = new_accum + ops
    return total_ops
        

if __name__ == '__main__':
    _ = int(input())
    a = list(map(int, input().split()))
    print(min(count_ops(a, 1), count_ops(a, -1)))


# Example run
# Input:
0
8131
# Output:
0
N = int(input())
A = list(map(int, input().split()))
counter = 0            ####操作回数
A.reverse()
S = 0           
a = A.pop()
if a==0:
  counter += 1
  while A:
    b = A.pop()
    if b == 0:
      counter += 2
    elif b>0:
      A.append(b)
      S = -1
      break
    elif b<0:
      A.append(b)
      S = 1
      break
else:
  S += a
    
    
while A:
  c = A.pop()
  if c>=0 and S>0:
    counter += abs(c+S)+1
    S = -1
  elif c<=0 and S<0:
    counter += abs(c+S)+1
    S = 1
  elif (c>0 and S<0) and S+c<=0:
    counter += abs(S+c)+1
    S = 1
  elif (c<0 and S>0) and S+c>=0:
    counter += abs(S+c)+1
    S = -1    
  else:
    S += c
    
print(counter)


# Example run
# Input:
386627675
19524
# Output:
0
def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist

def get_sign(x):
    if x > 0:
        return 1
    elif x < 0:
        return -1
    return 0

def submit():
    n, alist = read_input()

    # pattern 1
    s = 0
    sign = 1
    edit = 0

    for a in alist:
        temp = s + a
        temp_sign = get_sign(temp)

        if sign == temp_sign:
            edit += temp_sign * temp
            temp -= temp

        if temp == 0:
            edit += 1
            temp -= sign

        s = temp
        sign = get_sign(s)

    edit1 = edit

    # pattern 2
    s = 0
    sign = -1
    edit = 0

    for a in alist:
        temp = s + a
        temp_sign = get_sign(temp)

        if sign == temp_sign:
            edit += temp_sign * temp
            temp -= temp

        if temp == 0:
            edit += 1
            temp -= sign

        s = temp
        sign = get_sign(s)

    edit2 = edit

    print(min(edit1, edit2))


if __name__ == '__main__':
    submit()
    

# Example run
# Input:
-1
-3439167
# Output:
0
n = int(input())
A = [int(a) for a in input().split()]
ans1,ans2 = 0,0
total1,total2 = 0,0

for i in range(n):
    total1 += A[i]
    if i % 2== 0 and total1 <= 0:
        diff = abs(total1) + 1
        total1 += diff
        ans1 += diff
    elif i % 2 == 1 and total1 >= 0:
        diff = abs(total1) + 1
        total1 -= diff
        ans1 += diff
        
for i in range(n):
    total2 += A[i]
    if i % 2== 1 and total2 <= 0:
        diff = abs(total2) + 1
        total2 += diff
        ans2 += diff
    elif i % 2 == 0 and total2 >= 0:
        diff = abs(total2) + 1
        total2 -= diff
        ans2 += diff
        
print(min(ans1,ans2))

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

count = 0
sum_i = a[0]

if a[0] < 0:
    sum_i = 1
    pos_count = 1 - a[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 = 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
    if neg_count < pos_count:
        count = neg_count
    else:
        count = pos_count
elif a[0] > 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 = 1 + a[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
    if neg_count < pos_count:
        count = neg_count
    else:
        count = pos_count
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:
-37
1
# Output:
0
n=int(input())
a=list(map(lambda x: int(x), input().split()))
a.sort()
cnt=[]
val=[]
last=-1
for i in a:
    if i == last:
        cnt[-1]+=1
    else:
        cnt.append(1)
        val.append(i)
        last = i

low_val=-10
low_cnt=0
mid_val=0
mid_cnt=0
ans=0
for i, v in enumerate(val):
    if v>=low_val+3:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        low_val=v
        low_cnt=cnt[i]
        mid_val=0
        mid_cnt=0
    elif v==low_val+2:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        if mid_val>0:
            low_val=mid_val
            low_cnt=mid_cnt
            mid_val=v
            mid_cnt=cnt[i]
        else:
            low_val=v
            low_cnt=cnt[i]
            mid_val=0
            mid_cnt=0
    if v==low_val+1:
        mid_val=v
        mid_cnt=cnt[i]
ans=max(ans, low_cnt+mid_cnt)
print(ans)

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

ans=[0, 0]
if a[0]!=0:
    sm=a[0]
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[0]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1

    if a[0]>0:
        sm=-1
    else:
        sm=1
    ans[1]+=abs(a[0])+1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[1]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1
if a[0]==0:
    sm=1
    ans[0]+=1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[0]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1

    sm=-1
    ans[1]+=1
    for i in range(n-1):
        sm1=sm+a[i+1]
        if sm*sm1>=0:
            ans[1]+=abs(sm1)+1
            if sm>0:
                sm=-1
            else:
                sm=1
        else:
            sm=sm1
print(min(ans))

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

sum = A[0]
ans = 0

if sum == 0:
    ans += 1
    sum = 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]
    elif sum < 0:
        if sum + A[i] <= 0:
            ans += abs(sum + A[i]) + 1
            sum = 1
        else:
            sum += A[i]
print(ans)


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

cur = 1
ans1 = abs(A[0] - 1)
ans2 = abs(A[0] + 1)


for a in A[1:]:
    if cur > 0:
        if a + cur >= 0:
            ans1 += abs(-1 - (a + cur))
            cur  = -1
        else:
            cur = a + cur
    elif cur < 0:
        if a + cur <= 0:
            ans1 += abs(1 - (a + cur))
            cur = 1
        else:
            cur = a + cur

for a in A[1:]:
    if cur > 0:
        if a + cur >= 0:
            ans2 += abs(-1 - (a + cur))
            cur  = -1
        else:
            cur = a + cur
    elif cur < 0:
        if a + cur <= 0:
            ans2 += abs(1 - (a + cur))
            cur = 1
        else:
            cur = a + cur

print(min(ans1,ans2))

# Example run
# Input:
-209505
14111
# Output:
14110
n = int(input())
a = list(map(int,input().split()))
imos = 0
ruisekiwa = [0 for _ in range(n)]
ruisekiwa[0] = a[0]
for i in range(1, n):
	ruisekiwa[i] = ruisekiwa[i-1] + a[i]

# minus
imos = 0
minusans = 0
for i in range(n):
	targ = ruisekiwa[i] + imos
	if i % 2 == 0:
		if targ >= 0:
			imos -= targ+1
			minusans += targ+1
	else:
		if targ <= 0:
			imos += 1-targ
			minusans += 1-targ

# plus
imos = 0
plusans = 0
for i in range(n):
	targ = ruisekiwa[i] + imos
	if i % 2 == 1:
		if targ >= 0:
			imos -= targ+1
			plusans += targ+1
	else:
		if targ <= 0:
			imos += 1-targ
			plusans += 1-targ

print(min(minusans, plusans))

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

ans=10**10
s=0
cnt=0

for i in range(n):
    s+=a[i]
    if i%2==0:
        if s>=0:
            cnt += s + 1
            s = -1
    else:
        if s<=0:
            cnt += -s + 1
            s = 1
ans=min(ans,cnt)

s=0
cnt=0
for i in range(n):
    s+=a[i]
    if i%2==1:
        if s>=0:
            cnt += s + 1
            s = -1
    else:
        if s<=0:
            cnt += -s + 1
            s = 1
ans=min(ans,cnt)

print(ans)

# Example run
# Input:
-86
11
# Output:
0
n = int(input())
a = list(map(int, input().split()))
l = len(a)
cnt = 0
a_ = 0
x = -1
# -から
for i in range(l):
    a_ += a[i]
    if x == -1:
        if a_ > x:
            cnt += a_ -x
            a_ = -1
    else:
        if a_ < x:
            cnt += x-a_
            
            a_ = 1

    x *= -1

cnt1 = 0
a_ = 0
x1 = 1
# +から
for i in range(l):
    a_ += a[i]
    if x1 == -1:
        if a_ > x1:
            cnt1 += a_ -x1
            a_ = -1
    else:
        if a_ < x1:
            cnt1 += x1-a_
            
            a_ = 1

    x1 *= -1

if cnt >= 0 and cnt1 >=0:
    print(min(cnt, cnt1))
elif cnt < 0:
    print(cnt1)
else:
    print(cnt)

# Example run
# Input:
446
0
# Output:
1
N = int(input())
A = [int(x) for x in input().split()]


def solve(A, N):
    S = [0]*N
    answer = 0
    total = 0
    for i in range(N):
        total += A[i]
        S[i] = total
        if total == 0:
            d = 1 if S[i-1] < 0 else -1
            A[i] += d
            answer += 1
            total += d
        else:
            # S[i-1] < 0 and S[i] > 0
            # S[i-1] > 0 and S[i] < 0
            # S[i-1] > 0 and S[i] > 0
            if S[i-1] < 0 and S[i] < 0:
                answer += -S[i]+1
                total += -S[i]+1
            elif S[i-1] > 0 and S[i] > 0:
                answer += S[i]+1
                total += -(S[i]+1)
        S[i] = total
        #print(i, answer, "S[i-1]=%d"%S[i-1], "S[i]=%d"%S[i], sep="\t")
    return answer

if A[0] == 0:
    A[0] = -1
    m1 = solve(A, N) + 1
    A[0] = +1
    m2 = solve(A, N) + 1
    print(min(m1, m2))
else:
    m1 = solve(A, N)
    t = abs(A[0])
    A[0] = 1 if A[0] < 0 else -1
    m2 = solve(A, N) + t+1
    print(min(m1, m2))
    


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


# プラススタート ------------------
ans01 = 0
temp = a[0]
if (temp > 0):
    pass
else:
    add = abs(temp) + 1
    ans01 += add
    temp = 1

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
    #print(tar, ans)
# マイナススタート ------------------
ans02 = 0
temp = a[0]
if (temp < 0):
    pass
else:
    add = abs(temp) + 1
    ans02 += add
    temp = -1

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

ans = min(ans01, ans02)

print(ans)


# Example run
# Input:
0
-5095
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
tmp_a = a.copy()
Sum = [a[0]]
if a[0] > 0:
    flg = 1
    ans = 0
elif a[0] < 0:
    flg = 0
    ans = 0
elif a[0] == 0:
    Sum[0] = 1
    flg = 1
    ans = 1
idx = 0
for i in range(n-1):
    Sum.append(Sum[idx] + a[i+1])
    if flg  == 1:
        flg = 0
        if Sum[i+1] >= 0:
            tmp = Sum[i+1]
            Sum[i+1] = -1
            ans += tmp + 1
    else:
        flg = 1
        if Sum[i+1] <= 0:
            tmp = Sum[i+1]
            Sum[i+1] = 1
            ans += 1 - tmp
    idx += 1

tmp_ans = ans

a = tmp_a
Sum = [a[0]]
if a[0] > 0:
    Sum[0] = -1
    flg = 0
    ans = a[0] + 1
elif a[0] < 0:
    Sum[0] = 1
    flg = 1
    ans = 1 - a[0]
elif a[0] == 0:
    Sum[0] = -1
    flg = 0
    ans = 1
idx = 0
for i in range(n-1):
    Sum.append(Sum[idx] + a[i+1])
    if flg  == 1:
        flg = 0
        if Sum[i+1] >= 0:
            tmp = Sum[i+1]
            Sum[i+1] = -1
            ans += tmp + 1
    else:
        flg = 1
        if Sum[i+1] <= 0:
            tmp = Sum[i+1]
            Sum[i+1] = 1
            ans += 1 - tmp
    idx += 1

print(min(tmp_ans, ans))


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

#i%2==0 の時+
cnt=0
sums=0

for i in range(n):
    if i%2==0:
        if sums+a[i]<=0:
            tmp=abs(sums+a[i])+1
            sums=1
            cnt+=tmp
        else:
            sums+=a[i]
            tmp=a[i]
    else:
        #マイナスになってほしい
        if sums+a[i]>=0:
            tmp=abs(sums+a[i])+1
            sums=-1
            cnt+=tmp
        else:
            sums+=a[i]
            tmp=a[i]
    #print(a[i],tmp)

ans=cnt
#print("##############")
#i%2==0 の時+
cnt=0
sums=0

for i in range(n):
    if i%2==1:
        if sums+a[i]<=0:
            tmp=abs(sums+a[i])+1
            sums=1
            cnt+=tmp
        else:
            tmp=a[i]
            sums+=a[i]
    else:
        #マイナスになってほしい
        if sums+a[i]>=0:
            tmp=abs(sums+a[i])+1
            sums=-1
            cnt+=tmp
        else:
            tmp=a[i]
            sums+=a[i]
    #print(a[i],tmp)

print(min(cnt,ans))







# Example run
# Input:
0
-54266464
# Output:
0
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def calc_num_op(cumul, a):
    tmp_cumul = cumul + a
    #  print('current cumul:', cumul)
    #  print('current a:', a)
    #  print('bare cumul:', tmp_cumul)
    #  print('goodiness:', tmp_cumul != 0 and cumul // abs(cumul) != tmp_cumul // abs(tmp_cumul))
    if (cumul <= 0 and tmp_cumul <= 0):
        return abs(-cumul - a + 1), 1
    if (cumul >= 0 and tmp_cumul >= 0):
        return abs(-cumul - a - 1), -1
    return 0, tmp_cumul


def solve(arr, sign):
    num_op = 0
    cumul = arr[0]
    print('current cumul:', cumul)
    if cumul == 0:
        num_op += 1
        cumul += 1 if sign == '+' else -1
        #  print('modified cumul:', cumul)
    for a in arr[1:]:
        delta, cumul = calc_num_op(cumul, a)
        #  print('delta:', delta)
        #  print('modified cumul:', cumul)
        num_op += delta
    return num_op


def main():
    _ = read_h()
    arr = read_h()

    op_plus = solve(arr, '+')
    #  print('op plus:', op_plus)
    op_minus = solve(arr, '-')
    #  print('op minus:', op_minus)

    print(min(op_plus, op_minus))


if __name__ == '__main__':
    main()


# Example run
# Input:
1008752943
-37
# Output:
current cumul: -37
current cumul: -37
0
def culc(a, plus, ans):
    sum = a[0]
    for i in range(1, len(a)):
        plus = not(plus)
        sum += a[i]
        if plus:
            if sum <= 0:
                ans += abs(sum) + 1
                sum = 1
        else:
            if sum >= 0:
                ans += abs(sum) + 1
                sum = -1
    return ans

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

plus = None
ans = 0
if a[0] == 0:
    ans += 1
    a[0] = 1
    plus = True
elif a[0] > 0:
    plus = True
else:
    plus = False

ans1 = culc(a, plus, ans)

a[0] = a[0] // abs(a[0]) * -1

ans2 = abs(a[0]) + 1
ans2 = culc(a, not(plus), abs(a[0]) + 1 - ans)

print(min(ans1, ans2))

# Example run
# Input:
-16
-224231
# Output:
0
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()
# +からのstart
S = [0]*N
tmp = max(0, 1 - A[0])
S[0] = max(1, A[0])
for i in range(1, N):
    if i%2:
        x = 1 + S[i-1] + A[i]
        if x > 0:
            tmp += x
            S[i] = -1
        else:
            S[i] = S[i-1] + A[i]
    else:
        x = 1 - S[i-1] - A[i]
        if x > 0:
            tmp += x
            S[i] = 1
        else:
            S[i] = S[i-1] + A[i]
ans = tmp*1

# -スタート
S = [0]*N
tmp = max(0, 1 + A[0])
S[0] = min(-1, A[0])
for i in range(1, N):
    if i%2 == 0:
        x = 1 + S[i-1] + A[i]
        if x > 0:
            tmp += x
            S[i] = -1
        else:
            S[i] = S[i-1] + A[i]
    else:
        x = 1 - S[i-1] - A[i]
        if x > 0:
            tmp += x
            S[i] = 1
        else:
            S[i] = S[i-1] + A[i]
ans = min(tmp, ans)
print(ans)

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

import itertools
al_ac = list(itertools.accumulate(al))

ans = 0
init = 1

fix = 0
for a in al_ac:
    a += fix
    if init == 1:
        if a >= 1:
            init *= -1
            continue
        else:
            ans += abs(init - a)
            fix += init - a
            init *= -1
    else:
        if a <= -1:
            init *= -1
            continue
        else:
            ans += abs(init - a)
            fix += init - a
            init *= -1
ans2 = 0
init = -1

fix = 0
for a in al_ac:
    a += fix
    if init == 1:
        if a >= 1:
            init *= -1
            continue
        else:
            ans2 += abs(init - a)
            fix += init - a
            init *= -1
    else:
        if a <= -1:
            init *= -1
            continue
        else:
            ans2 += abs(init - a)
            fix += init - a
            init *= -1

print(min(ans, ans2))

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