Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n=int(input())
aaa=tuple(map(int, input().split()))

ans_e=0
ans_o=0
even=0
odd=0
#even->+
for i, a in enumerate(aaa):
    even+=a
    if i%2==0:
        if even>0:
            continue
        else:
            tmp=1-even
            even=1
            ans_e+=tmp
    else:
        if even<0:
            continue
        else:
            tmp=even+1
            even=-1
            ans_e+=tmp

for i, a in enumerate(aaa):
    odd+=a
    if i%2==0:
        if odd<0:
            continue
        else:
            tmp=odd+1
            odd=-1
            ans_o+=tmp
    else:
        if odd>0:
            continue
        else:
            tmp=1-odd
            odd=1
            ans_o+=tmp
print(min(ans_e, ans_o))

# Example run
# Input:
3897539
-18099607
# Output:
0
def resolve(SL):
    # L[0]!=0を起点とする
    cnt = 0
    for i in range(len(SL)-1):
        s0 = SL[i]
        s1 = SL[i+1]
        if(s0>0 and s1>=0):
            SL[(i+1):] = [s-(s1+1) for s in SL[(i+1):]]
            cnt += (s1+1)
        elif(s0<0 and s1<=0):
            SL[(i+1):] = [s+(-s1+1) for s in SL[(i+1):]]
            cnt += (-s1+1)  
    return cnt
            
def ans(L):
#     SL = [sum(L[:(i+1)]) for i in range(len(L))]
    a = L[0]
    c0,c1=0,0
    SL = []
    s = 0
    for i,l in enumerate(L):
        s += L[i]
        SL.append(s)

    if (a>0):
        c0 = resolve(SL)
        c1 = (a+1) + resolve(list(map(lambda x:x-(a+1), SL)))
    elif (a<0):
        c0 = resolve(SL)
        c1 = (-a+1) + resolve(list(map(lambda x:x+(-a+1), SL)))
    else:
        c0 = 1 + resolve(list(map(lambda x:x+1, SL)))
        c1 = 1 + resolve(list(map(lambda x:x-1, SL)))
    
    return(min(c0,c1))
  
N = int(input())
L = [int(x) for x in input().split(' ')]

print(ans(L))


# Example run
# Input:
-126905272
28016
# 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:
0
-83
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]

seq_sum = a[0]
times_odd = 0

if a[0] == 0:
    times_odd += 1
    seq_sum = 1

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

seq_sum = -a[0]
times_even = 2 * a[0]

if a[0] == 0:
    times_even += 1
    seq_sum = -1

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

ans = min(times_odd, times_even)

print(ans)

# Example run
# Input:
-10
-967
# Output:
-1934
n=int(input())
arr=list(map(int,input().split()))
ans1=0
ans2=0
if arr[0]>0:
  lsum=arr[0]
else:
  lsum=1
  ans1+=1-arr[0]
for i in range(1,n):
  if i%2==1:
    if arr[i]<-lsum:
      lsum+=arr[i]
    else:
      ans1+=(abs(lsum)+1)+arr[i]
      lsum=-1
  else:
    if abs(lsum)<arr[i]:
      lsum+=arr[i]
    else:
      ans1+=(abs(lsum)+1)-arr[i]
      lsum=1
if arr[0]<0:
  lsum=arr[0]
else:
  ans2+=arr[0]+1
  lsum=-1
for i in range(1,n):
  if i%2==1:
    if arr[i]<-lsum:
      lsum+=arr[i]
    else:
      ans2+=(abs(lsum)+1)+arr[i]
      lsum=-1
  else:
    if abs(lsum)<arr[i]:
      lsum+=arr[i]
    else:
      ans2+=(abs(lsum)+1)-arr[i]
      lsum=1
ans=min(ans1,ans2)
print(ans)

# Example run
# Input:
-24
-1477
# Output:
0
n = int(input())
a = list(map(int, input().split()))
A = []
cnt = 0

for i in range(n-1):
    A.append(a[i])
    if sum(A) > 0 and sum(A) + a[i+1] > 0:
        cnt += abs(sum(A) + a[i+1])+1
        a[i+1] -= abs(sum(A) + a[i+1])+1

    elif sum(A) < 0 and sum(A) + a[i+1] < 0:
        cnt += abs(sum(A) - a[i+1])-1
        a[i+1] += abs(sum(A) - a[i+1])-1

if sum(a) == 0:
    cnt += 1

print(cnt)

# Example run
# Input:
-274078593
-28418
# 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:
-836
159824875
# Output:
0
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

#プラス始まり
if an[0] > 0:
    sum = an[0]
    ans = 0
else:
    sum = 1
    ans = abs(an[0])+1

for i in range(1,n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1
ans1 = ans

#-始まり
if an[0] < 0:
    sum = an[0]
    ans = 0
else:
    sum = -1
    ans = abs(an[0])+1

for i in range(1, n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1

# print(ans1, ans)
print(min([ans1, ans]))


# Example run
# Input:
-8951
11
# Output:
0
n = int(input())
a = list(map(int, input().split()))
count_1 = 0
count_2 = 0
sum_1 = 0
sum_2 = 0

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

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

print(count_1 if count_1 < count_2 else count_2)

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

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

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


if a[0] < 0:
    t2 = 0
    p2 = a[0]
else:
    t2 = abs(-1 - a[0])
    p2 = -1
    

print(min(f(t1, p1), f(t2, p2)))

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

numbers = list(map(int, input().split()))
counter = 0

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

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

print(counter)

# Example run
# Input:
-37
1
# Output:
0
N = int(input())
A = list(map(int, input().split()))
cs = [A[0]] + [0] * (N - 1)
a = 0
b = 0
for i in range(N - 1):
  cs[i + 1] = cs[i] + A[i + 1]
temp = 0
for i in range(N):
  if i % 2:
    if cs[i] + temp >= 0:
      a += abs(cs[i] + temp) + 1
      temp -= abs(cs[i] + temp) + 1
  else:
    if cs[i] + temp <= 0:
      a += abs(cs[i] + temp) + 1
      temp += abs(cs[i] + temp) + 1
temp = 0
for i in range(N):
  if i % 2:
    if cs[i] + temp <= 0:
      b += abs(cs[i] + temp) + 1
      temp += abs(cs[i] + temp) + 1
  else:
    if cs[i] + temp >= 0:
      b += abs(cs[i] + temp) + 1
      temp -= abs(cs[i] + temp) + 1
print(min(a, b))

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

def test(total, res):
    for i in a[1:]:
        hugou = total > 0
        total += i
        if hugou:
            if total>=0:
                res += abs(total)+1
                total = -1
        else:
            if total<=0:
                res += abs(total)+1
                total = 1
    return res

    
res = 0
total = a[0]
if a[0]<=0:
    total = 1
    res += abs(a[0])+1
res1 = test(total, res)

res = 0
total = a[0]
if a[0]>=0:
    total = -1
    res += abs(a[0])+1
res2 = test(total, res)

print(min(res1, res2))

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

def solver(_sign):
    s = A[0]
    count = 0

    if s == 0:
        count += 1
        if n == 1:
            return count
        else:
            if _sign: # 先頭が正
                s = 1
            else:
                s = -1

    for a in A[1:]:
        prev = s
        sign = prev > 0
        s += a
        if s == 0:
            count += 1
            if sign: # previous is positive
                s = -1
            else: # prev is negative
                s = 1
        elif sign == (s > 0): # previous and current have the same sign
            count += abs(s)+1
            if s > 0:
                s = -1
            else:
                s = 1
        else:
            pass

    return count

print(min(solver(True), solver(False)))

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

ans = [0,0]
cum = [0,0]
sn = [1,-1]

for i, aa in enumerate(a):
    for j in range(2):
        if (-1)**i * sn[j] * aa > 0 and abs(aa) > abs(cum[j]):
            cum[j] += aa
            continue
        if cum[j]*aa < 0:
            ans[j] += abs(cum[j]) - abs(aa) + 1
        else:
            ans[j] += abs(cum[j]) + abs(aa) + 1
        cum[j] = (-1)**i * sn[j]
    
print(min(ans))

# Example run
# Input:
-1
-3439167
# Output:
0
n=int(input())
a=list(map(int, input().split()))
c1, c2 = 0, 0
s = 0
for i in range(len(a)):
    S = s+a[i]
    if i%2 == 0:
        if S > 0:
            s = S
        else:
            c1 += abs(S)+1
            s = 1
    else:
        if S < 0:
            s = S
        else:
            c1 += abs(S)+1
            s = -1
s=0
for i in range(len(a)):
    S = s+a[i]
    if i%2 != 0:
        if S > 0:
            s = S
        else:
            c2 += abs(S)+1
            s = 1
    else:
        if S < 0:
            s = S
        else:
            c2 += abs(S)+1
            s = -1
print(min(c1, c2))


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

def func(x):
	global a

	s = 0
	k = 0

	for i in a:
		s += i
		if s*x <= 0:
			k += abs(x-s)
			s = x
		x *= -1

	return k


print(min(func(1), func(-1)))

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

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

# Example run
# Input:
\@LU%V
32
# Output:
0
n=int(input())
a=list(map(int,input().split()))
import sys
sum=a[0]
cnt=0
if a[0]==0:
    sum+=1
    cnt+=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<=0:
                cnt+=(1-z)
                sum=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
    cnt_plus=cnt
    sum=-1
    cnt=1
    for i in range(1,n):
        if sum<0:
            z=sum+a[i]
            if z>0:
                sum=z
            elif z<=0:
                cnt+=(1-z)
                sum=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
    cnt_sbst=cnt
    print(min(cnt_plus,cnt_sbst))
    sys.exit()
for i in range(1,n):
    if sum<0:
        z=sum+a[i]
        if z>0:
            sum=z
        elif z<=0:
            cnt+=(1-z)
            sum=1
    elif sum>0:
        z=sum+a[i]
        if z>=0:
            cnt+=(z+1)
            sum=-1
        elif z<0:
            sum=z            
print(cnt)

# 6
# 0 0 -1 3 5 0





# Example run
# Input:
-33958
1593280440
# Output:
0
N=int(input())
A=list(map(int,input().split()))
cur=A[0]
ans=0
isplus=True
ind=1
if cur<0:
  isplus=False
if cur==0:
  # すべて0の場合
  allzero=True
  firstNotZero=0
  firstNotZeroInd=0
  for i in range(N):
    if A[i]!=0:
      firstNotZero=A[i]
      firstNotZeroInd=i
      allzero=False
      break
  if allzero:
    print(N)
    exit(0)
  # 0以外が出てくる場合
  if firstNotZero>0:
    cur=-1
    ind=firstNotZeroInd
    isplus=False
    print("ind",ind,"isplus",isplus)
  else:
    cur=1
    ind=firstNotZeroInd
    isplus=True
    print("ind",ind,"isplus",isplus)

for i in range(ind,N):
  print("i",i,"cur",cur,"A[i]",A[i])
  if isplus:
    if cur+A[i]>=0:
      diff=abs((cur+A[i])-(-1))
      print("cur",cur,"cur+A[i]",cur+A[i]," -> -1 diff",diff)
      ans+=diff
      print("ans",ans)
      cur=-1
    else:
      print("no problem")
      cur+=A[i]
    isplus=False
  else:
    if cur+A[i]<=0:
      diff=abs((cur+A[i])-1)
      print("cur",cur,"cur+A[i]",cur+A[i]," -> 1 diff",diff)
      ans+=diff
      print("ans",ans)
      cur=1
    else:
      print("no problem")
      cur+=A[i]
    isplus=True
  
print(ans)

# Example run
# Input:
-499948
-21000
# Output:
0
n = input()
a = [int(i) for i in input().split()]
cou = len(a)
counter = 0
X = a[0]
ans = 0
for i in a:
    if X > 0:
        b = -1 - X
        ans += abs(b - a[i])
        X = -1
        counter += 1
        if counter == cou - 1:
            break
    else:
        b = 1 - X
        ans += abs(b - a[i])
        X = 1
        counter += 1
        if counter == cou - 1:
            break
print (ans)

# Example run
# Input:
oBtKmC1{'
0
# Output:
1
# def sign(x):
#     return (x > 0) - (x < 0)


def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    target = {1, -1}
    results = set()
    for sign in target:
        total = 0
        ans = 0
        for an in a:
            total += an
            if sign != ((total > 0) - (total < 0)):
                ans -= (total - sign) * sign
                total = sign
            sign *= -1
        results.add(ans)

    print(min(results))


if __name__ == "__main__":
    main()


# Example run
# Input:
-56661351
981571
# Output:
0
n = int(input())
a = list(map(int,input().split()))
ans1 = 0
num = 0
f1 = 1
for i in range(n):
    num += a[i]
    if f1:
        if num <=0:
            ans1 += 1-num
            num = 1
        f1 = 0
    else:
        if num >= 0:
            ans1 += num+1
            num = -1
        f1 = 1
ans2 = 0
num = 0
f1 = 0
for i in range(n):
    num += a[i]
    if f1:
        if num <=0:
            ans2 += 1-num
            num = 1
        f1 = 0
    else:
        if num >= 0:
            ans2 += num+1
            num = -1
        f1 = 1
print(min(ans1,ans2))

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

cnt = 0
sgn = 1
s = 0
for _a in a:
    if (s + _a) * sgn <= 0:
        cnt += abs(_a + s - sgn)
        s = sgn
    else:
        s += _a
    sgn = -sgn

ans = cnt

cnt = 0
sgn = -1
s = 0
for _a in a:
    if (s + _a) * sgn <= 0:
        cnt += abs(_a + s - sgn)
        s = sgn
    else:
        s += _a
    sgn = -sgn

ans = min(ans, cnt)

print(ans)

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

ans = 1e9
for sign in (1, -1):
    s = sign
    res, acc = 0, 0
    for a in A:
        acc += a
        if acc * s <= 0:
            res += abs(acc-s)
            acc = s
        s *= -1
    ans = min(ans, res)

print(ans)


# Example run
# Input:
393537
-19
# Output:
0
n = int(input())
a = list(map(int, input().split()))
def f(a, b):
    # b == 0: １番めが正

    sum_a = 0
    cost = 0
    for i, ai in enumerate(a):
        if i % 2 == b:
            sum_a += ai
            if sum_a <= 0:
                x = 1 - sum_a
                sum_a += x
                cost += abs(x)
        else:
            sum_a += ai
            if sum_a >= 0:
                x = -1 - sum_a
                sum_a += x
                cost += abs(x)
    return cost
print(min(f(a, 0), f(a, 1)))

# Example run
# Input:
-7038374
-6
# 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 =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_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 += abs(before_sum) + 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 += abs(before_sum) + 1
        if before_sum < 0:
            after_sum = 1
        else:
            after_sum = -1
    
print(min(result_1,result_2))


# Example run
# Input:
-101281970
-210
# Output:
0
n=int(input())
a=list(map(int,input().split()))
tmp=0
csum_a=[]
for ai in a:
  tmp+=ai
  csum_a.append(tmp)
ans=0
tmp=0
plus=True
for si in csum_a:
  if plus and si+tmp>0:
    pass
  elif plus and si+tmp<=0:
    ans+=1-(si+tmp)
    tmp+=1-(si+tmp)
  elif not plus and si+tmp<0:
    pass
  elif not plus and si+tmp>=0:
    ans+=1+(si+tmp)
    tmp-=1+si+tmp
  plus=not plus

ans0=ans
ans=0
tmp=0
plus=False
for si in csum_a:
  if plus and si+tmp>0:
    pass
  elif plus and si+tmp<=0:
    ans+=1-(si+tmp)
    tmp+=1-(si+tmp)
  elif not plus and si+tmp<0:
    pass
  elif not plus and si+tmp>=0:
    ans+=1+(si+tmp)
    tmp-=1+si+tmp
  plus=not plus

print(min(ans0,ans))

# Example run
# Input:
715035410
0
# Output:
1
n = int(input())
a = list(map(int, input().split()))
cost = (a[0] == 0)
c = a[0] + (a[0] == 0)
for i in a[1:]:
  if c > 0:
    if c + i >= 0:
      cost += c + i + 1
      c = -1
    else:
      c += i
  else:
    if c + i <= 0:
      cost += 1 - c - i
      c = 1
    else:
      c += i
tmp = cost
cost = 0
if a[0] >= 0:
  cost = a[0] + 1
  c = -1
else:
  cost = -a[0] + 1
  c = 1
for i in a[1:]:
  if c > 0:
    if c + i >= 0:
      cost += c + i + 1
      c = -1
    else:
      c += i
  else:
    if c + i <= 0:
      cost += 1 - c - i
      c = 1
    else:
      c += i
print(int(min(tmp, cost)))


# Example run
# Input:
42
2147483647
# Output:
0
n=int(input())
l=list(map(int,input().split()))
if l[0]>0:
	ans=0
	now=l[0]
else:
	ans=1-l[0]
	now=1
for i in range(1,n):
	if i%2==0:
		if now + l[i]>0:
			now+=l[i]
		else:
			ans+=(1-now)-l[i]
			now=1
	else:
		if now + l[i]<0:
			now+=l[i]
		else:
			ans+=(1+now)+l[i]
			now=-1
if l[0]<0:
	tmp=0
	now=l[0]
else:
	tmp=1+l[0]
	now=-1
for i in range(1,n):
	if i%2==1:
		if now + l[i]>0:
			now+=l[i]
		else:
			tmp+=(1-now)-l[i]
			now=1
	else:
		if now + l[i]<0:
			now+=l[i]
		else:
			tmp+=(1+now)+l[i]
			now=-1
print(min(tmp,ans))



# Example run
# Input:
-90312
-12211339
# Output:
0
N = int(input())
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0

for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count1 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count1 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count1 += 1
        currentSum = -1
        
currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count2 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count2 += abs(currentSum) + 1
        currentSum = -1
    elif currentSum == 0 and restSum == 0:
        count2 += 1
        currentSum = 1
        
print(min(count1, count2))





# Example run
# Input:
-877447
8312590
# Output:
0
from itertools import accumulate

N = int(input())
As = list(map(int, input().split()))
acc = list(accumulate(As))

# 偶数が正
ans = 0
cnt = 0 #累積カウント
parity = [1,-1]
for i,a in enumerate(acc):
    a += cnt
    p = parity[i%2]
    if p * a > 0:
        continue
    else:
        ans += abs(a)+1
        cnt += p*(abs(a)+1)

# 偶数が負
ans2 = 0
cnt = 0 #累積カウント
parity = [-1,1]
for i,a in enumerate(acc):
    a += cnt
    p = parity[i%2]
    if p * a > 0:
        continue
    else:
        ans2 += abs(a)+1
        cnt += p*(abs(a)+1)

print(min(ans,ans2))


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


def calc(ls):
    count = 0
    acc = ls[0]
    sign = acc // abs(acc)
    for x in ls[1:]:
        y = acc + x
        if y == 0 or y // abs(y) == sign:
            z = -sign - y
            count += abs(z)
            acc = -sign
        else:
            acc = y
        sign *= -1
    return count


if ls[0] != 0:
    count = calc(ls)
else:
    ls0 = ls.copy()
    ls0[0] = 1
    ls1 = ls.copy()
    ls1[0] = -1
    count = min(calc(ls0), calc(ls1)) + 1
print(count)

# Example run
# Input:
441722
1107228
# Output:
0
from itertools import accumulate
import copy

def sol(acmA, sign=1):    
  add = 0
  ans = 0
  if sign==1:
    if acmA[0] <= 0:
      add = -acmA[0]+1
      ans = abs(-acmA[0]+1)
      acmA[0] = 1
  else:  
    if acmA[0] >= 0:
      add = -acmA[0]-1
      ans = abs(-acmA[0]-1)
      acmA[0] = -1      
      
  for i in range(1,N):
    acmA[i] += add
    tmp_add = 0
    if sign == 1:
      if i%2==0:
        if acmA[i] <=0:
          tmp_add = -acmA[i]+1
      else:
        if acmA[i] >=0:
          tmp_add = -acmA[i]-1
    else:
      if i%2==1:
        if acmA[i] <=0:
          tmp_add = -acmA[i]+1
      else:
        if acmA[i] >=0:
          tmp_add = -acmA[i]-1     
   
    #print(i, tmp_add, acmA[i])
    acmA[i] += tmp_add
    add +=  tmp_add
    ans +=abs(tmp_add)
  if acmA[-1] == 0: return ans +1
  else: return ans

N = int(input())
A = list(map(int,input().split()))
acmA = list(accumulate(A))
acmA2 = copy.deepcopy(acmA)
print(min(sol(acmA, 1), sol(acmA2, -1)))

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