Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
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

t1 = 0
p1 = a[0]

t2 = 0
if a[0] > 0:
    t2 += abs(-1 - a[0])
    p2 = -1
elif a[0] < 0:
    t2 += 1 - a[0]
    p2 = 1
else:  # a[0] == 0
    t1 = 1
    p1 = -1
    t2 = 1
    p2 = 1

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

# Example run
# Input:
-21000
3
# 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 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:
-61894
-24
# Output:
0
n=int(input())
a=list(map(int,input().split()))


now=a[0]
if now==0:
    c=1
    flag=1
    for i in range(1,n):
        if not a[i]==0:
            flag=abs(a[i])//a[i]
            #print(flag)
            if i%2==1:
                flag*=-1
    now=flag
else:
    flag=abs(a[0])//a[0]
    c=0
#print(c,now,flag)

for i in range(1,n):
    tmp=now+a[i]
    if not tmp*flag<0:
        c+=abs(flag*-1-tmp)
        now=flag*-1
    else:
        now=tmp
    flag*=-1
    #print(c,now,flag)

print(c)

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

def cnt(p):
  s=d=0
  for i in range(n):
    c=(s+a[i])*p
    if c<=0:
      d+=(1-c)
      s=p
    else:
      s+=a[i]
    p*=(-1)
  return d

da=cnt(1)
db=cnt(-1)
print(min(da,db))

# Example run
# Input:
-5701370
-3339504
# Output:
0
n = int(input())
A = list(map(int,input().split()))
a = [A,A]
res = [0,0]
sum = 0
for check in range(2):
  sum = 0
  if check:
    if a[check][0] > 0:
      temp = -1 - a[check][0]
      a[check][0] += temp
      res[check] += temp * -1
    elif a[check][0] < 0:
      temp = 1 - a[check][0]
      a[check][0] += temp
      res[check] += temp
  if a[check][0] == 0:
    if check == 0:
      a[check][0] += 1
    else:
      a[check][0] -= 1
    res[check] += 1
  for i in range(n-1):
    sum += a[check][i]
    if sum * (sum + a[check][i+1]) >= 0:
      if sum > 0:
        temp = -1 - sum - a[check][i+1]
        a[check][i+1] += temp
        res[check] += temp * -1
      else:
        temp = 1 - sum - a[check][i+1]
        a[check][i+1] += temp
        res[check] += temp
print(min(res[0],res[1]))

# Example run
# Input:
-28608
60
# 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:
0
-6956
# Output:
0
N = int(input())
A = list(map(int, input().split()))

def sol(S):
    ret = 0
    for a in A[1:]:
        b = a
        if S * (S + b) > 0:
            b = (abs(S) + 1) * (1 if S < 0 else -1)
        if S + b == 0:
            b = b - 1 if S > 0 else b + 1
        ret += abs(b - a)
        S += b
    return ret

if A[0] == 0:
    ans = min(sol(1), sol(-1)) + 1
else:
    ans = min(sol(A[0]), sol(-1 if A[0] > 0 else 1) + abs(A[0]) + 1)
print(ans)


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

ans = 10 ** 18
for z in range(2):
    if z == 0:
        sign = 1
    else:
        sign = -1
    c = 0
    cost = 0
    for x in a:
        c += x
        if c * sign <= 0:
            cost += 1 - c * sign
            c = sign
        sign *= -1
    ans = min(ans, cost)
print(ans)

# Example run
# Input:
-46896159
2561
# Output:
0
import time
ts=time.time()
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
from itertools import permutations,groupby
import sys
import bisect
import string
import random
alp=string.ascii_lowercase
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

n=I()
a=LI()
def solve(a,x):
    if a[0]*x>0:
        p=a[0]
        m=0
    else:
        p=x
        m=abs(a[0]-x)
    for i in range(1,n):
        t=-1 if p>0 else 1
        if (a[i]+p)*t>0:
            p+=a[i]
        else:
            m+=abs(a[i]+p-t)
            p+=a[i]+t*abs(a[i]+p-t)
    return m

print(min(solve(a,1),solve(a,-1)))

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

s1 = 0
SUM = 0
for i in range(len(a)):
    nxt = SUM + a[i]

    # plus
    if i % 2 == 0:
        if nxt > 0:
            SUM = nxt
            ops = 0
        else:
            SUM = 1
            ops = (1 - nxt)
    # minus
    else:
        if nxt < 0:
            SUM = nxt
            ops = 0
        else:
            SUM = -1
            ops = abs(-1 - nxt)

    s1 += ops

s2 = 0
SUM = 0
for i in range(len(a)):
    nxt = SUM + a[i]

    # plus
    if i % 2 == 1:
        if nxt > 0:
            SUM = nxt
            ops = 0
        else:
            SUM = 1
            ops = (1 - nxt)
    # minus
    else:
        if nxt < 0:
            SUM = nxt
            ops = 0
        else:
            SUM = -1
            ops = abs(-1 - nxt)

    s2 += ops

print(min(s1, s2))


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

if A[0] != 0:
    ans1 = 0
    sum = A[0]
else:
    ans1 = 1
    sum = 1
# A[0]=0 のときは1にする。下で-1にするパターンも試している。なお0は不可。

for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        nextsum = 1 if sum < 0 else -1
        # fugo = sum // abs(sum) 割り算のときは0に気をつけろ！
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum = nextsum
        ans1 += dif

#A[0]を反転したほうがいいパターンの処理
ans2 = abs(A[0]) + 1
sum = 1 if A[0] < 0 else -1
#ある意味、ここでA[0]=0のときに-1にすることもやっている

for a in A[1:]:
    if (sum + a) * sum < 0:
        sum += a
    else:
        nextsum = 1 if sum < 0 else -1
        a_should_be = nextsum - sum
        dif = abs(a_should_be - a)
        sum = nextsum
        ans2 += dif
        
print(min(ans1, ans2))


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

def chk(x,t):
  ans=0
  s=0
  for i in x:
    s += i
    if t == True and s < 1:
      ans += 1 - s
      s = 1
    elif t == False and s > -1:
      ans += 1 + s
      s = -1
    t = not t
    
  return ans

print(min(chk(a,True),chk(a,False)))

# Example run
# Input:
5330
3
# Output:
0
import sys
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
a = list(map(int, input().split()))
b = a[:]
# 無変更チェック
counter_1=0
S=int(a[0])
if a[0]!=0:
  for i in range(1,n):
    if S<0 and S+int(a[i])<=0:
      break
    elif S>0 and S+int(a[i])>=0:
      break
    S+=int(a[i])
    if i==n-1:
      print(counter_1)
      sys.exit()
# a[0]を1に変えた場合の計算
counter_1=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_1+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_1+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_2=abs(int(a[0])+1)
a[0]=-1
S=a[0]
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_2+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_2+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
print(min(counter_1,counter_2))

# Example run
# Input:
-3753932
42339391
# Output:
42339390
N = int(input())
a = list(map(int, input().split()))

def calc_tmp_ans(tmp_ans, cum_sum):
    for i in range(1, N):
        #print(i, tmp_ans)
        prev_cum_sum = cum_sum
        cum_sum += a[i]
        if cum_sum * prev_cum_sum >= 0:
            tmp_ans += abs(cum_sum) + 1
            if prev_cum_sum > 0:
                cum_sum = -1
            else:
                cum_sum = 1
    return tmp_ans

ans = 1000000000000000
if a[0] == 0:
    ans = min(ans, calc_tmp_ans(1, 1))
    ans = min(ans, calc_tmp_ans(-1, 1))
else:
    tmp_ans = 0
    cum_sum = a[0]
    ans = min(ans, calc_tmp_ans(tmp_ans, cum_sum))
    if a[0] > 0:
        ans = min(ans, calc_tmp_ans(a[0] + 1, -1))
    else:
        ans = min(ans, calc_tmp_ans(abs(a[0]) + 1, 1))
print(ans)

# Example run
# Input:
-81206326
-156960
# 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(str(counter))

# Example run
# Input:
212
-11989124
# Output:
0
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7


# segment tree

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x, y: x + y, default=0):
        self.size = 2 ** (size - 1).bit_length()  # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default] * (self.size * 2)  # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)  # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


n = ir()
a = lr()
seg1 = SegmentTree(n, lambda x, y: x + y, 0)
seg2 = SegmentTree(n, lambda x, y: x + y, 0)
for i, num in enumerate(a):
    seg1.update(i, num)  # 0オリジンのi個目をnumに更新 O(n)
    seg2.update(i, num)  # 0オリジンのi個目をnumに更新 O(n)
ans1 = 0
ans2 = 0
pflag = True
pflag2 = False
for i in range(1,n+1):
    now1 = seg1.query(0,i)
    if pflag and now1 <= 0:
        seg1.update(i-1, a[i-1]-now1+1)
        ans1+=(1-now1)
    elif (not pflag) and now1 >= 0:
        seg1.update(i-1, a[i-1]-now1-1)
        ans1+=(now1+1)
    now2 = seg2.query(0,i)
    if pflag2 and now2 <= 0:
        seg2.update(i-1, a[i-1]-now2+1)
        ans2+=(1-now2)
    elif (not pflag2) and now2 >= 0:
        seg2.update(i-1, a[i-1]-now2-1)
        ans2+=(now2+1)
    pflag = not pflag
    pflag2 = not pflag2
print(min(ans1,ans2))


# Example run
# Input:
-2041
215616622
# Output:
0
N = input()
a = list(map(int, input().split()))
 
def f(x):
  cnt = 0
  cur = 0
  for ai in a:
    cur += ai
    cur *= x
    if cur <= 0:
      cnt += 1 - cur
      cur = 1
    x *= -1
  return cnt
 
print(min(f(1), f(-1)))

# Example run
# Input:
S,P{>RB
-1
# Output:
0
_ = input()
aa = list(map(int,input().split()))

sums_1,sums_2 = 0,0
ans_1,ans_2 = 0,0

for i in range(len(aa)):
    tmp = sums_1 + aa[i]
    if (i % 2 == 0 and tmp <= 0) or (i % 2 == 1 and tmp >= 0):
        sums_1 = (-1)**(i % 2)
        ans_1 += abs(tmp)+1
    else:
        sums_1 = tmp

for i in range(len(aa)):
    tmp = sums_2 + aa[i]
    if (i % 2 == 0 and tmp >= 0) or (i % 2 == 1 and tmp <= 0):
        sums_2 = (-1)**(i % 2 + 1)
        ans_2 += abs(tmp)+1
    else:
        sums_2 = tmp

print(min(ans_1,ans_2))

# Example run
# Input:
,.2]y,5m
1854844
# Output:
0
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    total1 = 0
    total2 = 0
    ans1 = 0
    ans2 = 0
    for i in range(n):
        total1 += a_list[i]
        if i % 2 != 0 and total1 <= 0:
            ans1 += abs(total1) + 1
            total1 = 1
        elif i % 2 == 0 and total1 >= 0:
            ans1 += total1 + 1
            total1 = -1
    for j in range(n):
        total2 += a_list[j]
        if j % 2 != 0 and total2 >= 0:
            ans2 += total2 + 1
            total2 = -1
        elif j % 2 == 0 and total2 <= 0:
            ans2 += abs(total2) + 1
            total2 = 1
    print(min(ans1, ans2))
            

if __name__ == '__main__':
    main()

# Example run
# Input:
-7038374
-6
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]
s0 = a[0]
count=0
if a[0]==0:
  s0+=1
  count+=1
for i in range(1,n):
  s1 = s0+a[i]
  if s0*s1>=0:
    if s1>0:
      a[i]-=(abs(s1)+1)
      count+=(abs(s1)+1)
    elif s1<0:
      a[i]+=(abs(s1)+1)
      count+=(abs(s1)+1)
    elif s1==0:
      if s0>0:
        a[i]-=1
        count+=1
      elif s0<0:
        a[i]+=1
        count+=1
  s0 += a[i]
print(count)

# Example run
# Input:
-1002
45236
# Output:
0
n = int(input())
A = list(map(int, input().split()))
s = 0
num = 0
sign = "+"
for a in A:
    s += a
    if sign == "+":
        if s > 0:
            pass
        else:
            num += abs(s) + 1
            s = 1
        sign = "-"
        continue
    if sign == "-":
        if s < 0:
            pass
        else:
            num += s + 1
            s = -1
        sign = "+"
        continue
s = 0
num2 = 0
sign = "-"
for a in A:
    s += a
    if sign == "+":
        if s > 0:
            pass
        else:
            num2 += abs(s) + 1
            s = 1
        sign = "-"
        continue
    if sign == "-":
        if s < 0:
            pass
        else:
            num2 += s + 1
            s = -1
        sign = "+"
        continue
print(min(num, num2))


# Example run
# Input:
-151310
-18331
# Output:
0
n = int(input())
l = [int(x) for x in input().split()]


def count(ls, front):
    # replace ls[0] by front
    res = abs(front - ls[0])
    sm = front
    for i in range(1, n):
        temp = ls[i]
        if sm > 0 and ls[i] > -sm-1:
            res += abs(-sm-1 - ls[i])
            temp = -sm-1
        elif sm < 0 and ls[i] < -sm+1:
            res += abs(-sm+1 - ls[i])
            temp = -sm+1
        sm += temp
    return res


ans = 0
if l[0] == 0:
    ans = min(count(l, 1), count(l, -1))
else:
    ans = min(count(l, l[0]), count(l, -l[0] // abs(l[0])))
print(ans)

# Example run
# Input:
-5952
-28
# 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
            else:
                if a[i-1]>0:
                    sum=-1
                    cnt+=1
                elif a[i-1]<0:
                    sum=1
                    cnt+=1
        elif sum>0:
            z=sum+a[i]
            if z>=0:
                cnt+=(z+1)
                sum=-1
            elif z<0:
                sum=z
    cnt_plus=cnt
    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
            else:
                if a[i-1]>0:
                    sum=-1
                    cnt+=1
                elif a[i-1]<0:
                    sum=1
                    cnt+=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
        else:
            if a[i-1]>0:
                sum=-1
                cnt+=1
            elif a[i-1]<0:
                sum=1
                cnt+=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:
-14
0
# Output:
1
n = int(input())
a = list(map(int, input().split()))

def pm(a, t):
    ans = 0
    s = 0
    for i in a:
        s += i
        if t == 1 and s<1:
            ans += -s+1
            s = 1
        elif t==-1 and s>-1:
            ans += s+1
            s = -1
        t *= -1
    return ans
  
print(min(pm(a, 1), pm(a, -1)))

# Example run
# Input:
2147483647
71
# Output:
0
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 15:51:53 2018

@author: maezawa
"""
def f(n, a0, cnt, sa):
    a = a0[:]
    for i in range(n-1):
        sa += a[i]
        na = -sa//abs(sa)*(abs(sa)+1)
        if abs(a[i+1]) > abs(na) and a[i+1]*na > 0:
            continue
        else:
            cnt += abs(na-a[i+1])
            a[i+1] = na
    return cnt

n = int(input())
a = list(map(int, input().split()))
sa = 0
cnt = 0
if a[0] == 0:
    a[0] = 1
    cnt =1
    cnt0 = f(n, a, cnt, sa)
    a[0] = -1
    cnt1 = f(n, a, cnt, sa)
    cnt = min([cnt0,cnt1])
else:
    cnt = f(n, a, cnt, sa)
        

print(cnt)
    

# Example run
# Input:
-48
465
# Output:
0
import copy

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

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

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

print(min(ans_a,ans_b))

# Example run
# Input:
-39
2569
# Output:
0
def c(ints):
    
    for i in range(len(ints)):
        if ints[i] != 0:
            sig = 1 if ints[i] > 0 else -1
            sig_ = -sig
            total = ints[i]
            total_ = -sig
            mov = i
            mov_ = abs(total) + 1
            if i > 0:
                mov += 1
                mov_ += 2
            j = i
            break
        if i == len(ints) - 1:
            return i + 1
    
    for i_ in ints[j+1:]:
        tmp = total + i_
        tmp_ = total_ + i_
        if tmp == 0:
            mov +=1
            tmp = -sig
        elif sig * tmp > 0:
            mov += abs(tmp) + 1
            tmp = -sig
            
        if tmp_ == 0:
            mov_ +=1
            tmp_ = -sig_
        elif sig_ * tmp_ > 0:
            mov_ += abs(tmp_) + 1
            tmp_ = -sig_
            
        sig *= -1
        total = tmp
        sig_ *= -1
        total_ = tmp_
    return min(mov, mov_)

_ = input()
inp = input()
inp = inp.split(' ')
inp = [int(i_) for i_ in inp]
print(c(inp))

# Example run
# Input:
+CP)0CA
43251559
# Output:
0
n = int(input())
a = [int(_) for _ in input().split()]
new_a_plus = [a[i] for i in range(n)]
new_a_minus = [a[i] for i in range(n)]

count_plus = 0
if a[0] <= 0:
    new_a_plus[0] = 1
    count_plus += 1 - a[0]

for i in range(1, n):
    if i % 2 == 0:
        if sum(new_a_plus[:i+1]) <= 0:
            new_a_plus[i] = -sum(new_a_plus[:i])+1
            count_plus += new_a_plus[i] - a[i]
    else:
        if sum(new_a_plus[:i+1]) >= 0:
            new_a_plus[i] = -sum(new_a_plus[:i])-1
            count_plus += a[i] - new_a_plus[i]

count_minus = 0
if a[0] >= 0:
    new_a_minus[0] = -1
    count_minus += a[0] + 1

for i in range(1, n):
    if i % 2 == 0:
        if sum(new_a_minus[:i+1]) >= 0:
            new_a_minus[i] = -sum(new_a_minus[:i])-1
            count_minus += a[i] - new_a_minus[i]
    else:
        if sum(new_a_minus[:i+1]) <= 0:
            new_a_minus[i] = -sum(new_a_minus[:i])+1
            count_minus += new_a_minus[i] - a[i]

print(min(count_plus, count_minus))

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

S,cnt,res1 = 0,0,0
for a in A:
	S += a
	cnt += 1
	if cnt%2 == 1 and S <= 0:
		res1 += abs(S-1)
		S = 1
	elif cnt%2 == 0 and S >= 0:
		res1 += S+1
		S = -1

S,cnt,res2 = 0,0,0
for a in A:
	S += a
	cnt += 1
	if cnt%2 == 1 and S >= 0:
		res2 += S+1
		S = -1
	elif cnt%2 == 0 and S <= 0:
		res2 += abs(S-1)
		S = 1

print(min(res1,res2))

# Example run
# Input:
-1
60
# Output:
0
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = [a[0]]
for i in range(1,n):
  cnt.append(cnt[-1]+a[i])
cnt_o = cnt[::2]
cnt_e = cnt[1::2]
o = sum(cnt_o)
e = sum(cnt_e)
ans = 0
c = 0
if o >= e:
  for i in range(n):
    cnt[i] += c
    if (i+1) % 2 != 0:
      if cnt[i] > 0:
        pass
      else:
        ans += abs(cnt[i])+1
        c += abs(cnt[i])+1
    else:
      if cnt[i] < 0:
        pass
      else:
        ans += cnt[i]+1
        c -= a[i]+1
else:
  for i in range(n):
    cnt[i] += c
    if (i+1) % 2 != 0:
      if cnt[i] < 0:
        pass
      else:
        ans += cnt[i]+1
        c -= cnt[i]+1
    else:
      if cnt[i] > 0:
        pass
      else:
        ans += abs(cnt[i])+1
        c += abs(a[i])+1
if sum(cnt) == 0:
  print(ans+1)
else:
  print(ans)

# Example run
# Input:
-831
110
# Output:
0