Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
import copy
n = int(input())

numbers = list(map(int, input().split()))
numbers1 = copy.copy(numbers)
counter = 0
counter2 = 0
sum_in = 0
sum_in1 = 0

for i in range(len(numbers)):
    sum_in += numbers[i]
    if i % 2 == 0:
        if sum_in <= 0:
            sub = abs(sum_in) + 1
            sum_in += sub
            numbers[i] += sub
            counter += sub
    else:
        if sum_in >= 0:
            sub = abs(sum_in) + 1
            sum_in -= sub
            numbers[i] -= sub
            counter += sub

for i in range(len(numbers1)):
    sum_in1 += numbers1[i]

    if i % 2 != 0:
        if sum_in1 <= 0:
            sub = abs(sum_in1) + 1
            sum_in1 += sub
            numbers1[i] += sub
            counter2 += sub
    else:
        if sum_in1 >= 0:
            sub = abs(sum_in1) + 1
            sum_in1 -= sub
            numbers1[i] -= sub
            counter2 += sub

print(min([counter2, counter]))

# Example run
# Input:
124
-1967404
# Output:
0
n = int(input())
A = [int(a) for a in input().split()]

ans = 0
s = A[0]

if s <= 0:
    ans -= s-1
    s = 1
for i in range(1, n):
    if s > 0:
        s += A[i]
        if s >= 0:
            ans += s+1
            s = -1
    elif s < 0:
        s += A[i]
        if s <= 0:
            ans -= s-1
            s = 1

s = A[0]
c = 0
if s >= 0:
    c += s+1
    s = -1
for i in range(1, n):
    if s > 0:
        s += A[i]
        if s >= 0:
            c += s+1
            s = -1
    elif s < 0:
        s += A[i]
        if s <= 0:
            c -= s-1
            s = 1
ans = min(ans, c)
print(ans)

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

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

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

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

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
operate_num1 = 0
if a1[0]==0:
    a1[0] = 1
    operate_num1 += 1
tmp_sum = a1[0]
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num
        a1[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num
        a1[i] -= tmp_operate_num
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
operate_num2 = 0
if a2[0]<0:
    operate_num2 += 1 - a2[0]
    a2[0] += operate_num2
else:
    operate_num2 += a2[0] + 1
    a2[0] -= operate_num2

tmp_sum = a2[0]

for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num
        a2[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num
        a2[i] -= tmp_operate_num
    tmp_sum += a2[i]

print(min(operate_num1, operate_num2))        


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

plus_ans = 0
minus_ans = 0
sum = 0

for i in range(len(A)):
    sum += A[i]
    if i % 2 == 0:
        if sum <= 0:
            plus_ans += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            plus_ans += abs(sum) + 1
            sum = -1

sum = 0
for i in range(len(A)):
    sum += A[i]
    if i % 2 == 0:
        if sum >= 0:
            minus_ans += abs(sum) + 1
            sum = -1
    else:
        if sum <= 0:
            minus_ans += abs(sum) + 1
            sum = 1

print(min(plus_ans, minus_ans))


# Example run
# Input:
-597522
-2530418
# Output:
0
from itertools import accumulate

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


def func(a, judge):
    sum_list = list(accumulate(a))
    x = 0
    num = 0

    length = len(sum_list)

    for i in range(length):
        if judge and sum_list[i] + x <= 0:
            num += 1 - (sum_list[i] + x)
            x += 1 - (sum_list[i] + x)

        if (not judge) and sum_list[i] + x >= 0:
            num += 1 + (sum_list[i] + x)
            x -= 1 + (sum_list[i] + x)

        judge = not judge

    return num


ans = min([func(A, True), func(A, False)])

print(ans)


# Example run
# Input:
1
-10081
# Output:
0
n = int(input())

numbers = list(map(int, input().split()))
counter = 0
sum_in = 0
sum_in1 = numbers[0]

if numbers[0] >= 0:
    for i in range(len(numbers)):
        sum_in += numbers[i]
        if i % 2 == 0:
            if sum_in <= 0:
                sub = abs(sum_in) + 1
                sum_in += sub
                numbers[i] += sub
                counter += sub
        else:
            if sum_in >= 0:
                sub = abs(sum_in) + 1
                sum_in -= sub
                numbers[i] -= sub
                counter += sub

else:
    for i in range(len(numbers)):
        sum_in += numbers[i]

        if i % 2 != 0:
            if sum_in <= 0:
                sub = abs(sum_in) + 1
                sum_in += sub
                numbers[i] += sub
                counter += sub
        else:
            if sum_in >= 0:
                sub = abs(sum_in) + 1
                sum_in -= sub
                numbers[i] -= sub
                counter += sub

print(counter)

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

def f(A, op, acc = 0, cnt = 0):
    for i in range(n):
        acc += A[i]
        
        if i % 2 == 0 and acc * op > 0:
            cnt += op * acc + 1
            acc = - op
            
        if i % 2 == 1 and acc * op < 0:
            cnt += - op * acc + 1
            acc = op
            
    if acc == 0:
        cnt += 1
        
    return cnt
        
print(min(f(A, -1), f(A, 1)))

# Example run
# Input:
0
-14125092
# Output:
1
n=int(input())
arr=list(map(int,input().split()))
totalodd=0
totaleven=0
ansodd=0
anseven=0
for i in range(len(arr)):
    if i%2==0:      # 
        if totalodd+arr[i]>0:
            totalodd+=arr[i]
        else:
            ansodd+=1-(totalodd+arr[i])
            totalodd=1
        if totaleven+arr[i]<0:
            totaleven+=arr[i]
        else:
            anseven+=(totaleven+arr[i])+1
            totaleven=-1
    else:
        if totalodd+arr[i]<0:
            totalodd+=arr[i]
        else:
            ansodd+=(totalodd+arr[i])+1
            totalodd=-1
        if totaleven+arr[i]>0:
            totaleven+=arr[i]
        else:
            anseven+=1-(totaleven+arr[i])
            totaleven=1

print(min(ansodd,anseven))


# Example run
# Input:
5946
8
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]
cnt1 = 0
cnt2 = 0
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 == 0:
        if total >= 0:
            cnt1 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt1 += 1 - total
            total += 1 - total
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 != 0:
        if total >= 0:
            cnt2 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt2 += 1 - total
            total += 1 - total
print(min(cnt1, cnt2))


# Example run
# Input:
258529
69
# Output:
0
n=int(input())
A=list(map(int,input().split()))
ans=10**15
for i in[-1,1]:
    ansi,sum=0,0
    for a in A:
        sum+=a
        if sum*i<=0:ansi+=abs(sum-i);sum=i
        i*=-1
    ans=min(ans,ansi)
print(ans)

# Example run
# Input:
618445
-3249
# Output:
0
N = int(input())
A = list(map(int,input().split()))
S = A[0]
cnt = 0
if S!=0:
    for i in range(1,N):
        K = S+A[i]
        if S>0 and K>=0:
            cnt += 1+K
            S = -1
        elif S<0 and K<=0:
            cnt += 1-K
            S = 1
        else: S=K
else:
    S,cnt = 1,1
    for i in range(1,N):
        K = S+A[i]
        if S>0 and K>=0:
            cnt += 1+K
            S = -1
        elif S<0 and K<=0:
            cnt += 1-K
            S = 1
        else: S=K
    S,cnt1 = -1,1
    for i in range(1,N):
        K = S+A[i]
        if S>0 and K>=0:
            cnt1 += 1+K
            S = -1
        elif S<0 and K<=0:
            cnt1 += 1-K
            S = 1
        else: S=K
    cnt = min(cnt,cnt1)
print(cnt)

# Example run
# Input:
-28
187
# Output:
0
N = int(input())
b = list(map(int,input().split()))
for i in range(1,N):b[i] = b[i] + b[i-1]

cost = sub = 0
if b[0] > 0:pass
elif b[0] == 0:cost,sub = 1,1
else:cost,sub = 1 - b[0], 1-b[0]

for i in range(1,N):
    if i % 2 == 0:
        if b[i] + sub <= 0:
            newsub = -1 * (b[i] + sub) + 1
            cost += abs(newsub)
            sub += newsub
    else:
        if b[i] + sub >= 0:
            newsub = -1 * (b[i] + sub + 1)
            cost += abs(newsub)
            sub += newsub

cost2 = sub2 = 0
if b[0] < 0:pass
elif b[0] == 0:cost2,sub2 = 1,-1
else:cost2,sub2 = 1 + b[0], -1 *(1+b[0])

for i in range(1,N):
    if i % 2 == 1:
        if b[i] + sub2 <= 0:
            newsub2 = -1 * (b[i] + sub2) + 1
            cost2 += abs(newsub2)
            sub2 += newsub2
    else:
        if b[i] + sub2 >= 0:
            newsub2 = -1 * (b[i] + sub2 + 1)
            cost2 += abs(newsub2)
            sub2 += newsub2

print(min(cost,cost2))

# Example run
# Input:
-10318344
214
# Output:
0
def resolve(List):
    # L[0]!=0を起点とする
    L = 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 = 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))

def main():
    N = int(input())
    L = [int(x) for x in input().split(' ')]
    print(ans(L))

main()


# Example run
# Input:
-131587518
-3766
# Output:
0
# ABC059 C - Sequence
n=int(input())
a=list(map(int,input().split()))

total=a[0]
ans=0
if total<=0:
    ans=1-total
    total=1

for aa in a[1:]:
    if total>0:
        y=total+aa
        if y<0:
            total=y
        else:
            ans+=y+1
            total=-1
    else:
        y=total+aa
        if y>0:
            total=y
        else:
            ans+=1-y
            total=1


total=a[0]
ans2=0
if total>=0:
    ans2+=total+1
    total=-1

for aa in a[1:]:
    if total>0:
        y=total+aa
        if y<0:
            total=y
        else:
            ans2+=y+1
            total=-1
    else:
        y=total+aa
        if y>0:
            total=y
        else:
            ans2+=1-y
            total=1

print(min(ans,ans2))
        


# Example run
# Input:
-15860207
-54634663
# Output:
0
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

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

def solve(a):
    if a[0] > 0:
        status_pos = True
    elif a[0] < 0:
        status_pos = False

    tmp = 0
    ans = 0
    for i in range(n):
        tmp += a[i]
        if tmp == 0:
            ans += 1
            if status_pos:
                tmp = -1
            else:
                tmp = 1

        elif status_pos and tmp < 0:
            ans += 1+abs(tmp)
            tmp = 1
        elif status_pos == False and tmp > 0:
            ans += 1+abs(tmp)
            tmp = -1
        status_pos = not(status_pos)
    return ans

if a[0] == 0:
    a[0] = 1
    ans = 1
    ans += solve(a)

    a[0] = -1
    ans2 = 1
    ans2 += solve(a)
    ans = min(ans,ans2)
else:
    ans = solve(a)
    #値反転
    ans3 = abs(a[0])+1
    if a[0] > 0:
        a[0] = -1
    else:
        a[0] = 1
    ans3 += solve(a)
    ans = min(ans,ans3)

print(ans)


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

even_is_negative = 0
odd_is_nagative = 0

for i in range(n):
    if i % 2 == 0 and a[i] < 0:
        even_is_negative += 1
    elif i % 2 == 1 and a[i] < 0:
        odd_is_nagative += 1

# print(even_is_negative)
# print(odd_is_nagative)

sum = a[0]
change = 0

if even_is_negative >= odd_is_nagative:
    for i in range(1, n):
        if i % 2 == 1 and sum + a[i] <= 0:
            change += abs(sum + a[i]) + 1
            sum = 1
            # print("a " + str(sum))
        elif i % 2 == 0 and sum + a[i] >= 0:
            change += sum + a[i] + 1
            sum = -1
            # print("b " + str(sum))
        else:
            sum += a[i]
            # print("c " + str(sum))

if even_is_negative < odd_is_nagative:
    for i in range(1, n):
        if i % 2 == 1 and sum + a[i] >= 0:
            change += sum + a[i] + 1
            sum = -1
            # print("a " + str(sum) + str(change))
        elif i % 2 == 0 and sum + a[i] <= 0:
            change += abs(sum + a[i]) + 1
            sum = 1
            # print("b " + str(sum)+ str(change))
        else:
            sum += a[i]
            # print("c " + str(sum)+ str(change))

if sum == 0:
    print(change + 1)
else:
    print(change)

# Example run
# Input:
-18579092
21643
# Output:
0
def solve(x):
    if x == 0:
        return INF

    sgn = (-1) ** (x < 0)
    ret = abs(a[0] - x)
    sm = x
    for e in a[1:]:
        sgn *= -1

        if sgn < 0:
            if sm + e < 0:
                sm += e
            else:
                ret += e + 1 + sm
                sm = -1

        else:
            if sm + e > 0:
                sm += e
            else:
                ret -= e - 1 + sm
                sm = 1

    return ret


n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18

ans = min(solve(1), solve(-1), solve(a[0]))
print(ans)


# Example run
# Input:
3
3
# Output:
0
n=int(input())
a=list(map(int,input().split()))
mulsum=[0]*n
cnt=0
cnt2=0
buf=0
cur=0
mulsum[0]=a[0]
for i in range(n-1):
    mulsum[i+1]=mulsum[i]+a[i+1]
#print(mulsum)
i=0
pm=[]
mp=[]
while i<n:#+-+-+-...の列を目指す
    if (mulsum[i]+buf)<=0:#a[i]+buf>0になるようbufを調整
        cur=mulsum[i]+buf
        buf=1-mulsum[i]
        cnt=cnt+(1-cur)
        #pm.append(1)
    else:
        i=i
        #pm.append(mulsum[i])
    if i==n-1:
        break
    if (mulsum[i+1]+buf)>=0:#a[i+1]+buf<0になるよう調整
        cur=mulsum[i+1]+buf
        buf=-1-mulsum[i+1]
        cnt=cnt+(1+cur)
        #pm.append(-1)
    else:
        i=i
        #pm.append(mulsum[i+1])
    i=i+2
#print(pm,cnt)
buf=0
i=0
while i<n:#-+-+-+...の列を目指す
    if (mulsum[i]+buf)>=0:#a[i]+buf<0になるようbufを調整
        cur=mulsum[i]+buf
        buf=-1-mulsum[i]
        cnt2=cnt2+(1+cur)
        #mp.append(-1)
    else:
        i=i
        #mp.append(mulsum[i])
    #print(buf,cnt2)
    if i==n-1:
        break
    if (mulsum[i+1]+buf)<=0:#a[i+1]+buf>0になるよう調整
        cur=mulsum[i+1]+buf
        buf=1-mulsum[i+1]
        cnt2=cnt2+(1-cur)
        #mp.append(1)
    else:
        i=i
        #mp.append(mulsum[i+1])
    i=i+2
    #print(buf,cnt2)
#print(mp,cnt2)
print(min(cnt,cnt2))


# Example run
# Input:
1
-11314940
# Output:
0
N = int(input())
A = list(map(int,input().split()))
ans = 10**15

for s in [1,-1]:
  cos = 0
  tot = 0
  
  for a in A:
    tot+=a
    if s*tot<=0:
      cos+=abs(tot-s)
      tot=s
    s*=-1
  
  ans=min(ans,cos)

print(ans)

# Example run
# Input:
-83
0
# Output:
1
import copy
import sys
write = sys.stdout.write

n = int(input())
A = list(map(int,input().split())) # +, -, +, ...
B = copy.deepcopy(A) #-, +, -, ...
sumA = []
sumB = []
cntA = 0
cntB = 0
if A[0] == 0:
    A[0] += 1
    cntA += 1
    B[0] -= 1
    cntB += 1
elif A[0] > 0:
    cntB += (B[0]+1)
    B[0] = -1
else:
    cntA += abs(A[0])+1
    A[0] = 1
sumA.append(A[0])
sumB.append(B[0])
#write("cntA : " + str(cntA) + " cntB : " + str(cntB) + "\n") 
for i in range(1, n):
    tempA = sumA[i-1] + A[i]
    tempB = sumB[i-1] + B[i]
    if i%2 == 1: #Aは-, Bは+
        if tempA == 0:
            #A[i] -= 1
            cntA += 1
            sumA.append(-1)
        elif tempA > 0:
            #A[i] -= abs(tempA) + 1
            cntA += (abs(tempA) + 1)
            sumA.append(-1)
        else:
            sumA.append(tempA)

        if tempB == 0:
            #B[i] += 1
            cntB += 1
            sumB.append(1)
        elif tempB < 0:
            #B[i] += abs(tempB) + 1
            cntB += (abs(tempB) + 1)
            sumB.append(1)
        else:
            sumB.append(tempB)
    else: #Aは+, Bは-
        if tempA == 0:
            cntA += 1
            sumA.append(1)
        elif tempA < 0:
            cntA += (abs(tempA) + 1)
            sumA.append(1)
        else:
            sumA.append(tempA)
        
        if tempB == 0:
            #B[i] -= 1
            cntB += 1
            sumB.append(-1)
        elif tempB > 0:
            #B[i] -= abs(tempB) + 1
            cntB += (abs(tempB) + 1)
            sumB.append(-1)
        else:
            sumB.append(tempB)
    #write("cntA : " + str(cntA) + " cntB : " + str(cntB) + "\n")

print(str(min(cntA, cntB)))

# Example run
# Input:
1
-755
# Output:
0
N = int(input())
A = list(map(int,input().split()))
cnt1,cnt2 = 0,0
S1,S2 = A[0],A[0]
#
if A[0]==0:
    cnt1,cnt2 = 1,1
    S1,S2 = 1,-1
elif A[0]>0:
    cnt2 += 1+A[0]
    S2 = -1
else:
    cnt1 += 1-A[0]
    S1 = 1
#
for i in range(1,N):
    K = S1+A[i]
    if S1>0 and K>=0:
        cnt1 += 1+K
        S1 = -1
    elif S1<0 and K<=0:
        cnt1 += 1-K
        S1 = 1
    else:
        S1 = K
#
for i in range(1,N):
    K = S2+A[i]
    if S2>0 and K>=0:
        cnt2 += 1+K
        S2 = -1
    elif S2<0 and K<=0:
        cnt2 += 1-K
        S2 = 1
    else:
        S2 = K
print(min(cnt1,cnt2))

# Example run
# Input:
-10318344
214
# Output:
0
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    i = 0
    # 偶数番目が正のとき
    s = 0
    tmp1 = 0
    if a[i] > 0:
        s = a[i]
    else:
        tmp1 = abs(a[i])+1
        s = 1
    i = 1
    while i < n:
        if not s * (s+a[i]) < 0:
            tmp1 += abs(s+a[i])+1
            if i % 2 == 0:
                s = 1
            else:
                s = -1
        else:
            s += a[i]
        i += 1
    # 奇数番目が正のとき
    s = 0
    tmp2 = 0
    i = 0
    if a[i] < 0:
        s = a[i]
    else:
        tmp2 = abs(a[i])+1
        s = -1
    i = 1
    while i < n:
        if not s * (s+a[i]) < 0:
            tmp2 += abs(s+a[i])+1
            if i % 2 == 1:
                s = 1
            else:
                s = -1
        else:
            s += a[i]
        i += 1
    print(min(tmp1, tmp2))

if __name__ == '__main__':
    main()

# Example run
# Input:
-80
-7517
# Output:
0
def resolve(L):
    # L[0]!=0を起点とする
    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(L):
    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())
L = [int(x) for x in input().split(' ')]

print(ans(L))

# Example run
# Input:
142
-30
# Output:
0
N = int(input())
a =list(map(int,input().split()))

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

print(c)

# Example run
# Input:
-16
5215966
# Output:
0
def solve(N, As):
    positive = True if As[0] < 0 else False
    for i, a in enumerate(As):
        if a != 0:
            if i % 2 == 0:
                positive = True if a < 0 else False
            else:
                positive = False if a < 0 else True
            break

    ans = 0
    i = As[0]
    if i == 0:
        ans = 1
        if positive:
            i = -1
        else:
            i = 1

    for a in As[1:]:
        if positive:
            if i + a <= 0:
                ans += abs(1 - (i + a))
                a += 1 - (i + a)
        else:
            if i + a >= 0:
                ans += abs(-1 - (i + a))
                a += -1 - (i + a)
        i += a
        positive = not positive

    return ans

if __name__ == "__main__":
    n = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(n, As))


# Example run
# Input:
4
24837
# Output:
0
import sys

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

if all((x == 0 for x in l)):
    print(n * 2 - 1)
    sys.exit()

ans = 0
last_sum = l[0]
if last_sum == 0:
    for i in range(n - 1):
        if l[i + 1] != 0:
            if i + 1 % 2 == 1:
                ans = + 1
                last_sum = -1
            else:
                ans = + 1
                last_sum = 1
for i in range(n - 1):
    # print(last_sum)
    if last_sum > 0:
        if last_sum + l[i + 1] < 0:
            last_sum += l[i + 1]
        else:
            a = -1 - last_sum - l[i + 1]
            ans += abs(a)
            last_sum += a + l[i + 1]
    else:
        if last_sum + l[i + 1] > 0:
            last_sum += l[i + 1]
        else:
            a = 1 - last_sum - l[i + 1]
            ans += abs(a)
            last_sum += a + l[i + 1]
print(ans)


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

ans = 10**10

# 1 -1 1 -1...
cost1 = 0
s = 0
for i in range(n):
    t = 1 if i % 2 == 0 else -1
    c = 0
    if i % 2 == 0:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost1 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost1 += abs(c - a[i])

cost2 = 0
s = 0
for i in range(n):
    t = -1 if i % 2 == 0 else 1
    c = 0
    if i % 2 == 1:
        if s + a[i] > 0:
            s += a[i]
        else:
            c = abs(s - t)
            s += c
            cost2 += abs(c - a[i])
    else:
        if s + a[i] < 0:
            s += a[i]
        else:
            c = abs(s - t)
            s -= c
            cost2 += abs(- c - a[i])

print(cost1, cost2)
print(min(cost1, cost2))
# -1 1 -1 1..


# Example run
# Input:
-18758
470
# Output:
0 0
0