CodeEff/ECCO huggingface dataset:
# Original solution
import copy
n = int(eval(input()))
a = list(map(int,input().split()))
b = copy.copy(a)
#sum_a = []
#sum_b = []
ans_a = 0
ans_b = 0
for i in range(n):
    if i%2==0:
        if sum(a[:i+1])>0:
            #sum_a.append(sum(a[:i+1]))
            tmp = 0
        else:
            tmp = abs(sum(a[:i+1]))+1
            a[i] += tmp
            ans_a += tmp
            #sum_a.append(sum(a[:i+1]))
    else:
        if sum(a[:i+1])<0:
            #sum_a.append(sum(a[:i+1]))
            tmp = 0
        else:
            tmp = abs(sum(a[:i+1]))+1
            a[i] -= tmp
            ans_a += tmp
            #sum_a.append(sum(a[:i+1]))
    if i%2==1:
        if sum(b[:i+1])>0:
            #sum_b.append(sum(b[:i+1]))
            tmp = 0
        else:
            tmp = abs(sum(b[:i+1]))+1
            b[i] += tmp
            ans_b += tmp
            #sum_b.append(sum(b[:i+1]))
    else:
        if sum(b[:i+1])<0:
            #sum_b.append(sum(b[:i+1]))
            tmp = 0
        else:
            tmp = abs(sum(b[:i+1]))+1
            b[i] -= tmp
            ans_b += tmp
            #sum_b.append(sum(b[:i+1]))

#print(a)
#print(sum_a)
print((min(ans_a,ans_b)))

# Optimized solution
import copy
n = int(eval(input()))
a = list(map(int,input().split()))
b = copy.copy(a)
ans_a = 0
ans_b = 0
sum_a = 0
sum_b = 0
for i in range(n):
    if i%2==0:
        if sum_a+a[i]>0:
            tmp = 0
        else:
            tmp = abs(sum_a+a[i])+1
            a[i] += tmp
            ans_a += tmp
    else:
        if sum_a+a[i]<0:
            tmp = 0
        else:
            tmp = abs(sum_a+a[i])+1
            a[i] -= tmp
            ans_a += tmp
    sum_a+=a[i]
    if i%2==1:
        if sum_b+b[i]>0:
            tmp = 0
        else:
            tmp = abs(sum_b+b[i])+1
            b[i] += tmp
            ans_b += tmp
    else:
        if sum_b+b[i]<0:
            tmp = 0
        else:
            tmp = abs(sum_b+b[i])+1
            b[i] -= tmp
            ans_b += tmp
    sum_b+=b[i]
#print(a)
#print(sum_a)
print((min(ans_a,ans_b)))
# Original solution
from collections import defaultdict


def solve(pre_is_positive, total, ans, a_list):
    for a in a_list:
        total += a
        if pre_is_positive:
            if total == 0:
                ans += 1
                total = -1
            elif total > 0:
                ans += abs(total) + 1
                total = -1
        elif not pre_is_positive:
            if total == 0:
                ans += 1
                total = 1
            elif total < 0:
                ans += abs(total) + 1
                total = 1

        pre_is_positive = total > 0

    return ans


def main():
    n = int(eval(input()))
    a_list = list(map(int, input().split()))

    total = a_list[0]
    if total == 0:
        ans = solve(True, 1, 1, a_list[1:])
        ans = min(ans, solve(False, -1, 1, a_list[1:]))
    elif total > 0:
        ans = solve(True, total, 0, a_list[1:])
        ans = min(ans, solve(False, -1, abs(total) + 1, a_list[1:]))
    else:
        ans = solve(False, total, 0, a_list[1:])
        ans = min(ans, solve(True, 1, abs(total) + 1, a_list[1:]))
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
from collections import defaultdict


def solve(pre_is_positive, a_list):
    total = 0
    ans = 0
    for a in a_list:
        total += a
        if pre_is_positive and total >= 0:
            ans += abs(total) + 1
            total = -1
        elif not pre_is_positive and total <= 0:
            ans += abs(total) + 1
            total = 1
        pre_is_positive = total > 0

    return ans


def main():
    n = int(eval(input()))
    a_list = list(map(int, input().split()))
    print((min(solve(True, a_list), solve(False, a_list))))


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
sum1 = sum2 = cost1 = cost2 = 0
for i in range(n):
    cur = a[i]
    sum1 += cur
    if (sum1<=0, sum1>=0)[i%2]:
        cost1 += 1+sum1*[-1,1][i%2]
        sum1 = [1,-1][i%2]
    sum2 += cur
    if (sum2>=0, sum2<=0)[i%2]:
        cost2 += 1+sum2*[1,-1][i%2]
        sum2 = [-1,1][i%2]
print((min(cost1, cost2)))

# Optimized solution
def solve():
    n = int(eval(input()))
    a = list(map(int,input().split()))
    sum1 = sum2 = cost1 = cost2 = 0
    for i in range(n):
        cur = a[i]
        sum1 += cur
        if (sum1<=0, sum1>=0)[i%2]:
            cost1 += 1+sum1*[-1,1][i%2]
            sum1 = [1,-1][i%2]
        sum2 += cur
        if (sum2>=0, sum2<=0)[i%2]:
            cost2 += 1+sum2*[1,-1][i%2]
            sum2 = [-1,1][i%2]
    print((min(cost1, cost2)))
if __name__ == '__main__':
    solve()
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()

    sm, r1 = 0, 0
    for n in range(N):
        sm += A[n]
        if n % 2 == 0 and sm < 1:
            r1 += abs(sm) + 1
            sm = 1
        elif n % 2 != 0 and sm > -1:
            r1 += abs(sm) + 1
            sm = -1

    sm, r2 = 0, 0
    for n in range(N):
        sm += A[n]
        if n % 2 == 0 and sm > -1:
            r2 += abs(sm) + 1
            sm = -1
        elif n % 2 != 0 and sm < 1:
            r2 += abs(sm) + 1
            sm = 1

    print((min(r1, r2)))


if __name__ == '__main__':
    main()


# Optimized solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()

    # 偶数番目の合計を負
    # 奇数番目の合計を正にするパターン
    sm, r1 = 0, 0
    for n in range(N):
        sm += A[n]
        if n % 2 == 0 and sm < 1:
            r1 += abs(sm) + 1
            sm = 1
        elif n % 2 != 0 and sm > -1:
            r1 += abs(sm) + 1
            sm = -1

    # 偶数番目の合計を正
    # 奇数番目の合計を負にするパターン
    sm, r2 = 0, 0
    for n in range(N):
        sm += A[n]
        if n % 2 == 0 and sm > -1:
            r2 += abs(sm) + 1
            sm = -1
        elif n % 2 != 0 and sm < 1:
            r2 += abs(sm) + 1
            sm = 1

    # 操作数が小さいほうを出力
    print((min(r1, r2)))


if __name__ == '__main__':
    main()
# Original solution
eval(input())
iter_ = iter(map(int, input().rstrip("\n").split()))

sum_ = next(iter_)
ans = 0

for num in iter_:
    if sum_ == 0:
        sum_ += 1
        ans += 1
    presum = sum_
    sum_ += num
    while presum * sum_ >= 0:
        sum_ += -1 if presum > 0 else 1
        ans += 1

print(ans)

# Optimized solution
eval(input())
seq = list(map(int, input().rstrip("\n").split()))

iter_ = iter(seq)
ans1 = 0
for i, num in enumerate(iter_):
    if i == 0:
        sum_ = num
        if sum_ > 0:
            pass
        else:
            ans1 += abs(sum_ - 1)
            sum_ = 1
    else:
        sum_ += num
        if i % 2:
            if sum_ < 0:
                pass
            else:
                ans1 += abs(sum_ + 1)
                sum_ = -1
        else:
            if sum_ > 0:
                pass
            else:
                ans1 += abs(sum_ - 1)
                sum_ = 1

iter_ = iter(seq)
ans2 = 0
for i, num in enumerate(iter_):
    if i == 0:
        sum_ = num
        if sum_ < 0:
            pass
        else:
            ans2 += abs(sum_ + 1)
            sum_ = -1
    else:
        sum_ += num
        if i % 2:
            if sum_ > 0:
                pass
            else:
                ans2 += abs(sum_ - 1)
                sum_ = 1
        else:
            if sum_ < 0:
                pass
            else:
                ans2 += abs(sum_ + 1)
                sum_ = -1

print((min(ans1, ans2)))
# Original solution
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,fractions
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
def inpl_str(): return list(sys.stdin.readline().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n = inp()
a = inpl()
acc = list(itertools.accumulate(a))
#+-+-+-
cnt = 0
tmp = 0
for i in range(n):
    if i%2==0:
        tt = acc[i] + tmp
        if tt <= 0:
            cnt += 1 - tt
            tmp += 1 - tt
    else:
        tt = acc[i] + tmp
        if tt >= 0:
            cnt += tt + 1
            tmp -= tt + 1
ans = cnt
#-+-+-+
cnt = 0
tmp = 0
for i in range(n):
    if i%2:
        tt = acc[i] + tmp
        if tt <= 0:
            cnt += 1 - tt
            tmp += 1 - tt
    else:
        tt = acc[i] + tmp
        if tt >= 0:
            cnt += tt + 1
            tmp -= tt + 1
    # print(i,cnt,tmp,tt)
print((min(ans,cnt)))

# Optimized solution
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
now = 0
res = INF
cnt = 0
for i in range(n):
    now += a[i]
    if i%2 == 0:
        if now <= 0:
            cnt += 1-now
            now = 1
    else:
        if now >= 0:
            cnt += now+1
            now = -1
    # print(i,now,cnt)
res = min(res,cnt)
now = 0
cnt = 0
for i in range(n):
    now += a[i]
    if i%2:
        if now <= 0:
            cnt += -now + 1
            now = 1
    else:
        if now >= 0:
            cnt += now + 1
            now = -1
    # print(i,now,cnt)    
res = min(res,cnt)
print(res)
# Original solution
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=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_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print((min(counter_1,counter_2,counter_3)))

# Optimized solution
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=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_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print((min(counter_1,counter_2,counter_3)))
# Original solution
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=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_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print((min(counter_1,counter_2,counter_3)))

# Optimized solution
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+a[i]<=0:
    counter_1+=-S-a[i]+1
    a[i]=-S+1
  elif S>0 and S+a[i]>=0:
    counter_1+=S+a[i]+1
    a[i]=-S-1
  S+=a[i]
# a[0]を1に変えた場合の計算
counter_2=abs(b[0]-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+b[i]<=0:
    counter_2+=-S-b[i]+1
    b[i]=-S+1
  elif S>0 and S+b[i]>=0:
    counter_2+=S+b[i]+1
    b[i]=-S-1
  S+=b[i]
# a[0]を-1に変えた場合の計算
counter_3=abs(c[0]+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+c[i]<=0:
    counter_3+=-S-c[i]+1
    c[i]=-S+1
  elif S>0 and S+c[i]>=0:
    counter_3+=S+c[i]+1
    c[i]=-S-1
  S+=c[i]
print((min(counter_1,counter_2,counter_3)))
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    bit = [0] * (n+1)
    A = LI()
    def add(i,x):
        while i <= n:
            bit[i] += x
            i += i & -i

    def query(i):
        x = 0
        while i > 0:
            x += bit[i]
            i -= i & -i
        return x

    for i,a in enumerate(A):
        add(i+1,int(a))

    ans = INF
    bit_c = copy.deepcopy(bit)
    for s in (1,-1):
        bit = copy.deepcopy(bit_c)
        cnt = 0
        x = s
        for i in range(1,n+1):
            z = query(i)
            if z * x <= 0:
                add(i,x-z)
                cnt += abs(x-z)
            x = -x
        ans = min(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    bit = [0] * (n+1)

    def add(i,x):
        while i <= n:
            bit[i] += x
            i += i & -i

    def query(i):
        x = 0
        while i > 0:
            x += bit[i]
            i -= i & -i
        return x

    for i,a in enumerate(LI()):
        add(i+1,int(a))

    ans = INF

    b = [bit,copy.copy(bit)]
    for s in (1,-1):
        bit = b[(s+1)//2]
        cnt = 0
        x = s
        for i in range(1,n+1):
            z = query(i)
            if z * x <= 0:
                add(i,x-z)
                cnt += abs(x-z)
            x = -x
        ans = min(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    bit = [0] * (n+1)

    def add(i,x):
        while i <= n:
            bit[i] += x
            i += i & -i

    def query(i):
        x = 0
        while i > 0:
            x += bit[i]
            i -= i & -i
        return x

    for i,a in enumerate(LI()):
        add(i+1,int(a))

    ans = INF

    b = [bit,copy.copy(bit)]
    for s in (1,-1):
        bit = b[(s+1)//2]
        cnt = 0
        x = s
        for i in range(1,n+1):
            z = query(i)
            if z * x <= 0:
                add(i,x-z)
                cnt += abs(x-z)
            x = -x
        ans = min(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    a = LI()
    ans = INF
    for s in (1,-1):
        acc = 0
        cnt = 0
        x = s
        for i in range(n):
            acc += a[i]
            if acc * x <= 0:
                cnt += abs(x-acc)
                acc = x
            x = -x
        ans = min(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 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

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


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
currentSum = 0
count3 = 0
count4 = 0

currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count3 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] <= 0 and restSum == 0:
        count3 += abs(currentSum) + 1
        currentSum = 1
        
currentSum = 0
for i in range(N):
    restSum = currentSum
    currentSum += A[i]
    if currentSum <= 0 and restSum < 0:
        count4 += abs(currentSum) + 1
        currentSum = 1
    elif currentSum >= 0 and restSum > 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
    elif A[i] >= 0 and restSum == 0:
        count4 += abs(currentSum) + 1
        currentSum = -1
        
print((min(count3, count4)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
if a[0] < 0:
    flag = -1
else:
    flag = 1
for i in range(1,n):
    if flag == -1:
        if sum(a[0:i]) + a[i] <= 0:
            cnt += -(sum(a[0:i]) + a[i]) + 1
            a[i] = -sum(a[0:i]) + 1
        flag = 1
    elif flag == 1:
        if sum(a[0:i]) + a[i] >= 0:
            cnt += sum(a[0:i]) + a[i] + 1
            a[i] = -sum(a[0:i]) - 1
        flag = -1
print(cnt)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i]
    if i%2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
    elif i%2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
for i in range(n):
    sum2 += a[i]
    if i%2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
    elif i%2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
print((min(ans1,ans2)))
# Original solution

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



res1 = 0
sum = 0
# sei, hu, sei, hu....
# guu, ki, guu, ki
for i in range(n):
    sum += a[i]
    if sum <= 0 and i%2 == 0:
        res1 += abs(sum) + 1
        sum = 1
    elif sum >= 0 and i%2 == 1:
        res1 += abs(sum) + 1
        sum = -1
    # hutuunitoku


res2 = 0
sum = 0
# hu, sei, hu, sei....
# guu, ki, guu, ki
for i in range(n):
    sum += a[i]
    if sum <= 0 and i%2 == 1:
        res2 += abs(sum) + 1
        sum = 1
    elif sum >= 0 and i%2 == 0:
        res2 += abs(sum) + 1
        sum = -1
    # hutuunitoku

print((min(res1, res2)))


# Optimized solution

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


def solve(s1, s2):
    "if start == true, assume the first of the sum is positive."
    res = 0
    sum = 0
    for i in range(n):
        sum += a[i]
        if sum <= 0 and i % 2 == s1:
            res += abs(sum) + 1
            sum = 1
        elif sum >= 0 and i % 2 == s2:
            res += abs(sum) + 1
            sum = -1
    return res


print((min(solve(0, 1), solve(1, 0))))
# Original solution
n = int(eval(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)

# Optimized solution
N = int(eval(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)