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

count_list = []
previous = ''

flag_list = ['odd','even']

for f in flag_list:
    count = 0
    summary = 0
    for i,a in enumerate(a_list):
        if i == 0:
            if f == 'odd':
                previous = '+'
                if a <= 0:
                    a_result = 1
                    count += 1-a
                else:
                    a_result = a
            else:
                previous = '-'
                if a >= 0:
                    a_result = 1
                    count += 1-a
                else:
                    a_result = a
            summary += a_result
        else:
            if previous == '+':
                if summary + a < 0:
                    a_result = a
                else:
                    a_result = (-1)*abs(-1-summary)
                    count += abs(a-a_result)
                previous = '-'
            else:
                if summary + a > 0:
                    a_result = a
                else:
                    a_result = abs(1-summary)
                    count += abs(a-a_result)
                previous = '+'
            summary += a_result
    count_list.append(count)

print(min(count_list))

# Example run
# Input:
2147483647
165
# Output:
-164
n = int(input())

a = list(map(int,input().split()))
b = [i for i in a]


def solve(cnt,A,N):
    for i in range(1, N):
        if sum(A[0:i])>0:
            if sum(A[0:i+1])>=0:
                r = A[i]
                A[i]=-sum(A[0:i])-1
                cnt+=abs(r-A[i])
        else:
            if sum(A[0:i+1])<=0:
                r = A[i]
                A[i]=-sum(A[0:i])+1
                cnt+=abs(r-A[i])
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)
print(min(ans1,ans2))


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

totals = [0] * N
totals[0] = A[0]
con = 0

if totals[0] == 0:
  for i in range(1,N):
    if A[i] != 0:
      f = A[i]
      if f > 0:
        totals[0] = -1
      else:
        totals[0] = 1
      break
  else:
    totals[0] = 1
  con += 1

for i in range(1,N):
  totals[i] = totals[i - 1] + A[i]
  if totals[i - 1] * totals[i] >= 0:

    if totals[i - 1] < 0:
      con += abs(1 - totals[i])
      totals[i] += abs(1 - totals[i])
    elif totals[i - 1] > 0:
      con += abs(-1 - totals[i])
      totals[i] -= abs(-1 - totals[i])
  
print(con)


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

# 偶数番目が＋
A_even = A
S_even = 0
ans_even = 0
for i in range(n):
    if (S_even + A_even[i]) * ((-1) ** (i - 1)) > 0:
        S_even += A_even[i]
        continue
    ans_even += S_even + A_even[i] + 1
    A_even[i] = (-1) ** (i - 1) - S_even
    S_even = (-1) ** (i - 1)

# 奇数番目が＋
A_odd = A
S_odd = 0
ans_odd = 0
for i in range(n):
    if (S_odd + A_odd[i]) * ((-1) ** i) > 0:
        S_odd += A_odd[i]
        continue
    ans_odd += S_odd + A_odd[i] + 1
    A_odd[i] = (-1) ** i - S_odd
    S_odd = (-1) ** i

ans = min(ans_even, ans_odd)

print(ans)

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

# + - + - ...
cost1, sum1 = 0, 0
for i, a in enumerate(A):
	sum1 += a
	#print(sum1, cost1)
	if not i % 2:
		if sum1 <= 0:
			cost1 += (1 - sum1)
			sum1 = 1
	else:
		if 0 <= sum1:
			cost1 += (1 + sum1)
			sum1 = -1
#print(sum1, cost1)

# - + - + ...
cost2, sum2 = 0, 0
for i, a in enumerate(A):
	sum2 += a
	if i % 2:
		if sum2 <= 0:
			cost2 += (1 - sum2)
			sum2 = 1
	else:
		if 0 <= sum2:
			cost2 += (1 + sum2)
			sum2 = -1

print(min(cost1, cost2))


# Example run
# Input:
18
-15915
# Output:
0
n = int(input())

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

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

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

print(counter)


# Example run
# Input:
84816755
-1837384013
# 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**10
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:
-14993
-377
# Output:
0
n = int(input())
a = list(map(int, input().split()))
check = ''
if a[0] > 0:
    check = '+'
else:
    check = '-'

ans = 0
for i in range(1, n):
    a[i] += a[i-1]
    if check == '+':
        if a[i] >= 0:
            ans += abs(a[i]) + 1
            a[i] -= abs(a[i]) + 1
        check = '-'
    else:
        if a[i] <= 0:
            ans += abs(a[i]) + 1
            a[i] += abs(a[i]) + 1
        check = '+'
print(a)
print(ans)

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

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            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
if h == 1:
    result = 1
if a[0] > 0:
    result += a[0] +1
    counter = -1
else:
    result += 1-a[0]
    counter = 1

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            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:
-32942311
298151
# Output:
0
N = int(input())
A = [int(x) for x in input().split()]
ans_plusstart = 0
sum_plusstart = 0
ans_minusstart = 0
sum_minusstart = 0
if A[0] < 0:
    ans_plusstart += 1 - A[0]
    sum_minusstart = A[0]
    sum_plusstart = 1
else:
    ans_minusstart += 1 + A[0]
    sum_minusstart = -1
    sum_plusstart = max(1, A[0])
    if A[0] == 0:
        ans_plusstart = 1
for i in range(1, N):
    #print(sum_plusstart, ans_plusstart, sum_minusstart, ans_minusstart)
    if i % 2 == 0:  # スタートと同じ記号にしたい
        if A[i] + sum_plusstart > 0:
            sum_plusstart = A[i] + sum_plusstart
        if A[i] + sum_plusstart <= 0:
            ans_plusstart += 1-(A[i] + sum_plusstart)
            sum_plusstart = 1

        if A[i] + sum_minusstart < 0:
            sum_minusstart = A[i] + sum_minusstart
        if A[i] + sum_minusstart >= 0:
            ans_minusstart += 1 + A[i] + sum_minusstart
            sum_minusstart = -1

    else:  # スタートと違う記号にしたい
        if A[i] + sum_plusstart < 0:
            sum_plusstart = A[i] + sum_plusstart
        if A[i] + sum_plusstart >= 0:
            ans_plusstart += 1+A[i] + sum_plusstart
            sum_plusstart = -1

        if A[i] + sum_minusstart > 0:
            sum_minusstart = A[i] + sum_minusstart
        if A[i] + sum_minusstart <= 0:
            ans_minusstart += 1 - (A[i] + sum_minusstart)
            sum_minusstart = 1
print(min(ans_minusstart, ans_plusstart))


# Example run
# Input:
-647437
346
# 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 solve(arr, positive):
    num_op = 0
    cumul = 0
    #  print('current cumul:', cumul)

    for a in arr:
        cumul += a

        if positive and cumul >= 0:
            num_op += 1 + cumul
            cumul = -1
        elif not positive and cumul <= 0:
            num_op += 1 - cumul
            cumul = 1

        positive = not positive

    return num_op


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

    op_plus = solve(arr, True)
    #  print('op plus:', op_plus)
    op_minus = solve(arr, False)
    #  print('op minus:', op_minus)

    print(min(op_plus, op_minus))


if __name__ == '__main__':
    main()


# Example run
# Input:
1363926
77305
# 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:
%Vfvs8
-241292
# Output:
0
def re(k1,l,s):
    r=0
    for i in range(0,n):
        if s==1:
            s=0
            k1+=l[i]
            if k1>=0:
                r+=k1+1
                k1=-1
            continue
        if s==0:
            s=1
            k1+=l[i]
            if k1<=0:
                r+=abs(k1)+1
                k1=1
    return r

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

k1=0

ans=min(re(k1,l,1),re(k1,l,0))



print(ans)

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

A = a[0]
asum = [A]
if A == 0:
    ansp,ansm,tempp,tempm = 1,1,1,-1
elif A < 0:
    ansp,ansm,tempp,tempm = -A + 1, 0, -A + 1, 0
else:
    ansp,ansm,tempp,tempm = 0, A2 + 1, 0, -A2 - 1

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

    A1 = A + tempp
    if A1 == 0:
        ansp += 1
        tempp += ((i%2)*2-1)
    elif i%2==0 and A1 < 0:
        ansp += -A1 + 1
        tempp += -A1 + 1
    elif i%2!=0 and A1 > 0:
        ansp += A1 + 1
        tempp += -A1 - 1

    A2 = A + tempm
    if A2 == 0:
        ansm += 1
        tempm += -((i%2)*2-1)
    elif i%2!=0 and A2 < 0:
        ansm += -A2 + 1
        tempm += -A2 + 1
    elif i%2==0 and A2 > 0:
        ansm += A2 + 1
        tempm += -A2 - 1

print(min(ansp,ansm))

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

sums = 0
count = 0
count2 = 0
for i in range(len(a)):
    if i % 2 == 0:
        pp = a[i]
        if sums + pp > 0:
            None
        else:
            sums = 1
            count =  count + 1 - pp - sums
    else:
        pp = a[i]
        if sums + pp < 0:
            None
        else:
            sums = -1
            count = count -1 -pp - sums
            
for i in range(len(a)):
    if i % 2 == 1:
        pp = a[i]
        if sums + pp > 0:
            None
        else:
            sums = 1
            count2 =  count2 + 1 - pp - sums
    else:
        pp = a[i]
        if sums + pp < 0:
            None
        else:
            sums = -1
            count2 = count2 -1 -pp - sums
            
print(min(count,count2))


# Example run
# Input:
47
-5701370
# Output:
0
N = int(input())
nums = list(map(int, input().split()))
sum_n = 0
ans = 10**5+1
for start in [-1, 1]:
  before = start
  cnt = 0
  for num in nums:
    sum_n += num
    if before*sum_n >= 0:
      if before < 0:
        cnt += abs(1-sum_n)
        before = 1
      else:
        cnt += abs(-1-sum_n)
        before = -1
    else:
      before = sum_n
    print(cnt)
  ans = min(ans, cnt)
print(ans)

# Example run
# Input:
29
996
# Output:
0
1993
0
def F(list_A, sign):
  total = 0
  cnt = 0
  for a in list_A:
    total += a
    if sign==True and total < 1:
      cnt += 1- total
      total = 1
    elif sign==False and total > -1:
      cnt += total + 1
      total = -1
    
    sign = not sign
  return cnt

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

ans = min(F(A, True), F(A, False))
print(ans)

# Example run
# Input:
21643
-887384
# Output:
0
import unittest


def solve(n, a):
    # 貪欲
    cnt = 0
    total = a[0]
    if a[0] < 1:
        cnt = abs(a[0]) + 1
        total = 1
    for i in range(1, n):
        if i % 2 == 0:  # +
            if total + a[i] > 0:
                total += a[i]
            else:
                diff = abs(total + a[i]) + 1
                cnt += abs(diff)
                total = 1
        else:  # -
            if total + a[i] < 0:
                total += a[i]
            else:
                diff = abs(total + a[i]) + 1
                cnt += abs(diff)
                total = -1
    t = cnt
    cnt = 0
    total = a[0]
    if a[0] > -1:
        cnt = abs(a[0]) + 1
        total = -1
    for i in range(1, n):
        if i % 2 == 0:  # -
            if total + a[i] < 0:
                total += a[i]
            else:
                diff = abs(total + a[i]) + 1
                cnt += abs(diff)
                total = -1
        else:  # +
            if total + a[i] > 0:
                total += a[i]
            else:
                diff = abs(total + a[i]) + 1
                cnt += abs(diff)
                total = 1

    return min(t, cnt)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    result = solve(n, a)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 4
        a = [1, -3, 1, 0]
        actual = solve(n, a)
        expected = 4
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 5
        a = [3, -6, 4, -5, 7]
        actual = solve(n, a)
        expected = 0
        self.assertEqual(actual, expected)

    def test_solve_3(self):
        n = 6
        a = [-1, 4, 3, 2, - 5, 4]
        actual = solve(n, a)
        expected = 8
        self.assertEqual(actual, expected)

    def test_solve_4(self):
        n = 6
        a = [-1, 2, -2, 2, -2, 1000]
        actual = solve(n, a)
        expected = 0
        self.assertEqual(actual, expected)


# Example run
# Input:
-1168909
0
# Output:
1
n = int(input())
a_list = list(map(int,input().split()))
ans = float('inf')

for i in [1,-1]:
    ans_i = 0
    sums  = 0
    for a in a_list:
        sums += a
        if sums*i <= 0:
            ans_i += abs(sums-i)
            sums = i
        i *= -1
    ans = min(ans,ans_i)

print(ans)

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

check=a[0]
ans=0
if check<=0:
    ans=abs(check)+1
    check=1

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

            
check=a[0]
ans2=0
if check>=0:
    ans2=abs(check)+1
    check=-1

for i in range(1,n):
    check2=check+a[i]
    if i%2!=0:
        if check2<=0:
            ans2+=(abs(check2)+1)
            check=1
        else:
            check=check2
            
    else:
        if check2>=0:
            ans2+=(abs(check2)+1)
            check=-1
        else:
            check=check2
print(min(ans,ans2))
    

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

check=a[0]
ans=0
if check==0:
    for i in range(1,n):
        if check+a[i]==0:
            continue
            
        elif check+a[i]>0:
            if i%2==0:
                check=1
                ans=1
                break
            else:
                check=-1
                ans=1
                break
        else:
            if i%2==0:
                check=-1
                ans=1
                break
            else:
                check=1
                ans=1
                break
    else:
        check=1
        ans=1
                

for i in range(1,n):
    check2=check+a[i]

    if check<0:
        if check2>0:
            check=check2
        else:
            ans+=(abs(check2)+1)
            check=1
    else:
        if check2<0:
            check=check2
        else:
            ans+=(abs(check2)+1)
            check=-1

print(ans)
    
    

# Example run
# Input:
-728818981
-2811762
# Output:
0
N = int(input())
nums = list(map(int, input().split()))
ans = 10**10+1
for start in [-1, 1]:
  before = start
  cnt = 0
  sum_n = 0
  for num in nums:
    sum_n += num
    if before*sum_n >= 0:
      if before < 0:
        cnt += abs(1-sum_n)
        sum_n = 1
      else:
        cnt += abs(-1-sum_n)
        sum_n = -1
    before = sum_n
  ans = min(ans, cnt)
print(ans)


# Example run
# Input:
58432185
-88
# Output:
0
import copy
n = int(input())
a = [int(i) for i in input().split()]
b=a.copy()
s0p = a[0]
s0n = b[0]
countp = 0
countn = 0

if a.count(0)==n:
  print(2*n-1)
  exit()

if s0p<=0:
  s0p+=(abs(s0p)+1)
  countp+=abs(s0p)

if s0n>=0:
  s0n-=(abs(s0n)+1)
  countn+=abs(s0n)

for i in range(1,n):
  s1 = s0p+a[i]
  if s0p*s1>=0:
    if s1>0:
      a[i]-=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1<0:
      a[i]+=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1==0:
      if s0p>0:
        a[i]-=1
        countp+=1
      elif s0p<0:
        a[i]+=1
        countp+=1
  s0p += a[i]

for i in range(1,n):
  s1 = s0n+b[i]
  if s0n*s1>=0:
    if s1>0:
      b[i]-=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1<0:
      b[i]+=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1==0:
      if s0n>0:
        b[i]-=1
        countn+=1
      elif s0n<0:
        b[i]+=1
        countn+=1
  s0n += b[i]

print(countp if countp<=countn else(countn))







# Example run
# Input:
-2540
-1836
# Output:
0
n=int(input())
a=list(map(int,input().split()))
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
print(cnt)





# Example run
# Input:
-2090237817
-14
# Output:
0
def solve(N, As):
    i = As[0]
    positive = True if As[0] < 0 else False
    ans = 0
    if i == 0:
        ans = 1
        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:
139893
5182
# Output:
0
n = int(input())
A = [item for item in list(map(int, input().split()))]
S = [A[0]]
for i in range(1, n):
    S.append(A[i]+S[i-1])
count = 0
if S[0] == 0:
    A[0] += 1
    for item in S:
        item += 1 
    count += 1
#print(S)
for i in range(1, n):
    #print(S[i-1], S[i])
    if S[i] * S[i-1] >= 0:
        dif = -1 * (S[i-1]//abs(S[i-1])) - S[i] 
        A[i] += dif
        for j in range(i,n):
            S[j] += dif
        count += abs(dif)
        #print(S)


print(count)

# Example run
# Input:
-1
2199169
# Output:
0
n = int(input())
A = [int(x) for x in input().split()]
sum_start_plus = 0
sum_start_minus = 0
ans_start_plus = 0
ans_start_minus = 0
flag_start_plus = True
flag_start_minus = True

# プラス始まりの場合を計算する
for a in A:
    sum_start_plus += a
    if flag_start_plus:
        flag_start_plus = False
        if sum_start_plus > 0:
            continue
        else:
            ans_start_plus += abs(1 - sum_start_plus)
            sum_start_plus = 1
    else:
        flag_start_plus = True
        if sum_start_plus < 0:
            continue
        else:
            ans_start_plus += abs(-1 - sum_start_plus)
            sum_start_plus = -1

# マイナス始まりの場合を計算する
for a in A:
    sum_start_minus += a
    if flag_start_minus:
        flag_start_minus = False
        if sum_start_minus < 0:
            continue
        else:
            ans_start_minus += abs(-1 - sum_start_minus)
            sum_start_minus = -1
    else:
        flag_start_minus = True
        if sum_start_minus > 0:
            continue
        else:
            ans_start_minus += abs(1 - sum_start_minus)
            sum_start_minus = 1

print(min(ans_start_plus, ans_start_minus))

# Example run
# Input:
21643
-887384
# 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**10
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 = 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 = 1-lis[i]-sm
            cnt+= add
            sm+=add
ans=min(ans,cnt)
print(ans)

# Example run
# Input:
28016
-48
# Output:
0
import itertools

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(itertools.accumulate(A))
    func1 = (plus, minus)
    func2 = (minus, plus)

    cnt1, cnt2 = 0, 0
    offset1, offset2 = 0, 0
    for i, v in enumerate(a):
        ret = func1[i%2](v + offset1)
        offset1 += ret
        cnt1 += abs(ret)
        ret = func2[i%2](v + offset2)
        offset2 += ret
        cnt2 += abs(ret)
    print(min(cnt1, cnt2))

def plus(n):
    if n <= 0:
        x = 1 - n
        return x
    else:
        return 0

def minus(n):
    if n >= 0:
        x = -1 - n
        return x
    else:
        return 0

main()


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

def check(flag):
    acc = 0
    cnt = 0

    flag = flag
    for i in a:
        acc += i
        if (flag == 1 and flag > acc) or (flag == -1 and flag < acc) or i == 0:
            cnt += abs(flag - acc)
            acc = flag
        flag *= -1
    return cnt

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



# Example run
# Input:
-1351531223
-7517
# Output:
0
# 必要になったら結果が1か-1になるまで加えたり引いたりする方針
# 実装がちょっと考える 符号変わったりするとか先頭が0の場合とか

n = int(input())
arr = list(map(int, input().split()))
tmp = arr[0]


def f(arr, tmp):
    count = 0
    for i in range(1, n):
        if tmp + arr[i] < 0 < tmp:
            # 加えたら符号が+から-になる場合
            tmp += arr[i]
        elif tmp < 0 < tmp + arr[i]:
            # 加えたら符号が-から+になる場合
            tmp += arr[i]
        elif 0 <= tmp + arr[i] <= tmp or 0 <= tmp <= tmp + arr[i]:
            # 加えても+から-にはならず+のまま
            count += abs(-1 - tmp - arr[i])
            tmp = -1
        elif tmp + arr[i] <= tmp <= 0 or tmp <= tmp + arr[i] <= 0:
            # 加えても-から+にはならず-のまま
            count += abs(1 - tmp - arr[i])
            tmp = 1
        else:
            # runtime errorの出し方がわからんのでTLEを狙う（おい
            while True:
                if 1 == 0:
                    break

    return count


if tmp == 0:
    print(min(f(arr, 1), f(arr, -1)) + 1)
else:
    print(f(arr, tmp))



# Example run
# Input:
-15015728
42339391
# Output:
0