Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
# -*- coding:utf-8 -*-

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

    """考え方
    ruiseki[i] := i番目までの累積和

    ・ruiseki[i]のiが偶数番目を+にするパターン
    ・ruiseki[i]のiが偶数番目を-にするパターン

    の2通りを求め、小さい方を答えにする
    """

    # 偶数番目を+にするパターン
    ans1 = 0
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    if ruiseki[0] == 0:
        ruiseki[0] = 1
        ans1 += 1

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

        if i%2 != 0:
            # iが奇数
            if ruiseki[i] >= 0:
                diff = abs(ruiseki[i] - (-1))
                ans1 += diff
                ruiseki[i] = -1
        else:
            # iが偶数
            if ruiseki[i] <= 0:
                diff = abs(ruiseki[i] - 1)
                ans1 += diff
                ruiseki[i] = 1
    
    # 偶数番目を-にするパターン
    ans2 = 0
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    if ruiseki[0] == 0:
        ruiseki[0] = -1
        ans2 += 1

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

        if i%2 != 0:
            # iが奇数
            if ruiseki[i] <= 0:
                diff = abs(ruiseki[i] - 1)
                ans2 += diff
                ruiseki[i] = 1
        else:
            # iが偶数
            if ruiseki[i] >= 0:
                diff = abs(ruiseki[i] - (-1))
                ans2 += diff
                ruiseki[i] = -1
    
    print(min(ans1, ans2))


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

    ans = 0
    """
    (1) A = [0, 0, 0, 0, 0, 100, ...] みたいなときは
        A = [-1, 2, -2, 2, -2, 100, ...] にしたい
    (2) A = [0, 0, 0, 0, 100, ...] みたいなときは
        A = [1, -2, 2, -2, 100, ...] にしたい
    """
    if A[0] == 0:
        hugou = 1  # 最後の符号(1:+, -1:-)
        for i in range(1, N):
            if A[i] == 0:
                continue
            if A[i] > 0:
                hugou = 1
                break
            else:
                hugou = -1
                break
        
        for j in range(i-1, 0, -1):
            if hugou == -1:
                A[j] = 2
            else:
                A[j] = -2
            hugou *= -1
            ans += 2
        
        if hugou > 0:
            A[0] = -1
        else:
            A[0] = 1
        ans += 1

    # ruiseki[i] := i番目までの累積和
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    for i in range(1, N):
        i_sum = A[i] + ruiseki[i-1]

        if ruiseki[i-1] > 0:
            # ruiseki[i]をマイナス値にする必要がある
            if i_sum < 0:
                ruiseki[i] = i_sum
            else:
                diff = abs(i_sum - (-1))
                ans += diff
                A[i] -= diff
                i_sum -= diff
                ruiseki[i] = i_sum
        elif ruiseki[i-1] < 0:
            # ruiseki[i]をプラス値にする必要がある
            if i_sum > 0:
                ruiseki[i] = i_sum
            else:
                diff = abs(i_sum - 1)
                ans += diff
                A[i] += diff
                i_sum += diff
                ruiseki[i] = i_sum
    
    print(ans)

        


if __name__ == "__main__":
    solve()


# Example run
# Input:
1
8030667
# Output:
0
def main():
    N = int(input())

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

    # first positive
    sign = 1
    S = 0
    cost = 0
    for a in A:
        S += a
        if S * sign > 0:
            pass
        else:
            cost += abs(S) + 1
            S = sign
        sign *= -1
    p = cost

    # first negative
    sign = -1
    S = 0
    cost = 0
    for a in A:
        S += a
        if S * sign > 0:
            pass
        else:
            cost += abs(S) + 1
            S = sign
        sign *= -1
    q = cost

    print(min(p,q))


if __name__ == "__main__":
    main()


# Example run
# Input:
-104837
-69520
# Output:
0
def first_positive(n,a):
    count = 0
    sum = a[0]
    #正ならTrue
    flag = True

    if a[0] <= 0:
        sum = 1
        count += abs(1 - a[0])

    for i in range(1,n):
        if sum + a[i] < 0 and flag == True:
            sum += a[i]
            flag = False
            continue
        elif sum + a[i] < 0 and flag == False:
            flag = True
            count += abs(1 - sum - a[i])
            sum = 1
        elif sum + a[i] >= 0 and flag == True:
            flag = False
            count += abs(-1 - sum - a[i])
            sum = -1
        elif sum + a[i] >= 0 and flag == False:
            sum += a[i]
            flag = True
            continue

    return count

def first_negative(n,a):
    count = 0
    sum = a[0]
    #正ならTrue
    flag = True

    if a[0] >= 0:
        sum = -1
        count += abs(-1 - a[0])

    for i in range(1,n):
        if sum + a[i] < 0 and flag == True:
            sum += a[i]
            flag = False
            continue
        elif sum + a[i] < 0 and flag == False:
            flag = True
            count += abs(1 - sum - a[i])
            sum = 1
        elif sum + a[i] >= 0 and flag == True:
            flag = False
            count += abs(-1 - sum - a[i])
            sum = -1
        elif sum + a[i] >= 0 and flag == False:
            sum += a[i]
            flag = True
            continue

    return count

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]

    p = first_positive(n,a)
    n = first_negative(n,a)

    if p < n:
        print(p)
    else:
        print(n)


# Example run
# Input:
-227170451
13499019
# Output:
0
N = int(input())
A = [i for i in map(int,input().split())]

ruiseki = [0] * N
ans = 2 ** 30 + 1
for j in range(2):
    cnt= 0
    ruiseki[0] = A[0]
    if j == 0:
        if A[0] <= 0:
            ruiseki[0] = 1
            cnt += 1 - A[0]
    else:
        if A[0] >= 0:
            ruiseki[0] = -1
            cnt += 1 + A[0]
    for i in range(1,N):
        ruiseki[i] = ruiseki[i-1]+A[i]
        totalp = 0
        if ruiseki[i] * ruiseki[i-1] >0:
            totalp= (int(ruiseki[i])>0)*(-1)*(1 + ruiseki[i]) +  (int(ruiseki[i])<0) * (1 - ruiseki[i])

        elif ruiseki[i] == 0:
            if ruiseki[i-1] > 0:
                totalp = -1
            else:
                totalp = 1
        ruiseki[i] += totalp 
        cnt += abs(totalp)
    ans = min(ans,cnt)
        
print(ans)
        
        
        

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

sa = 0
count = [0, 0]

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 0:
        count[0] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 1:
        count[0] += 1 + sa
        sa = -1

sa = 0

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 1:
        count[1] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 0:
        count[1] += 1 + sa
        sa = -1

print(min(count))

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

# Example run
# Input:
-746
-63
# Output:
0
N = int(input())
A = [int(x) for x in input().split()]


# plusスタートにする
ans1 = 0
c = 0
plus = True
for a in A:
    c += a
    if plus:
        if c <= 0:
            ans1 += abs(c) + 1
            c = 1
        plus = False
    else:
        if c >= 0:
            ans1 += abs(c) + 1
            c = -1
        plus = True

# minusスタートにする
ans2 = 0
c = 0
plus = False
for a in A:
    c += a
    if plus:
        if c <= 0:
            ans2 += abs(c) + 1
            c = 1
        plus = False
    else:
        if c >= 0:
            ans2 += abs(c) + 1
            c = -1
        plus = True

print(min(ans1, ans2))


# Example run
# Input:
15761764
-37
# Output:
0
# ABC059C - Sequence (ARC072C)
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = [0] * 2
    
    # start with positive number
    cur = 0
    for i, j in enumerate(lst):
        cur += j
        if i % 2 == 0 and cur <= 0:
            cnt[0] += abs(cur) + 1
            cur = 1
        elif i % 2 == 1 and cur >= 0:
            cnt[0] += abs(cur) + 1
            cur = -1

    # start with negative number
    cur = 0
    for i, j in enumerate(lst):
        cur += j
        if i % 2 == 0 and cur >= 0:
            cnt[1] += abs(cur) + 1
            cur = -1
        elif i % 2 == 1 and cur <= 0:
            cnt[1] += abs(cur) + 1
            cur = 1

    print(min(cnt))


if __name__ == "__main__":
    main()


# Example run
# Input:
-39645188
-202
# Output:
0
N = int(input())
*A, = map(int,input().split())
ans1 = 0
S = A[0]
if S <= 0:
    ans1 = abs(S)+1
    S = 1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans1 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
ans2 = 0
S = A[0]
if S >= 0:
    ans2 = abs(S)+1
    S = -1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans2 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
print(min(ans1,ans2))

# Example run
# Input:
0
8131
# Output:
0
def count_op(n, a):
    i_sum = a[0]
    op_num = 0
    for i in range(1, n):
        tmp_sum = i_sum + a[i]
        if i_sum > 0:
            if tmp_sum == 0:
                op_num += 1
                a[i] -= 1
                tmp_sum -= 1
            elif tmp_sum > 0:
                op_num += tmp_sum + 1
                a[i] -= tmp_sum + 1
                tmp_sum = -1
        else:
            if tmp_sum == 0:
                op_num += 1
                a[i] += 1
                tmp_sum += 1
            elif tmp_sum < 0:
                op_num += -tmp_sum + 1
                a[i] += -tmp_sum + 1
                tmp_sum = 1
        i_sum = tmp_sum
    return op_num

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

if a[0] != 0:
    b = a[:]
    a_num = count_op(n, a)
    b_num = 0
    if b[0] > 0:
        b_num += b[0] + 1
        b[0] = -1
    else:
        b_num += -b[0] + 1
        b[0] = 1
    b_num += count_op(n, b)
    print(min(a_num, b_num))
else:
    b = a[:]
    a[0] = 1
    a_num = count_op(n, a) + 1
    b[0] = -1
    b_num = count_op(n, b) + 1
    print(min(a_num, b_num))

# Example run
# Input:
-473
-7
# Output:
0
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math

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

def main(c,temp):
    if temp>0:
        flag=1
    elif temp<0:
        flag=0
    for i in range(1,n):
        temp+=A[i]
        if flag:
            if temp>=0:
                c+=temp-(-1)
                temp=-1
            flag=0
        else:
            if temp<=0:
                c+=1-temp
                temp=1
            flag=1
    return(c)

temp=A[0]
if temp:
    print(main(0,temp))
else:
    temp=1
    a=main(1,temp)
    temp=-1
    b=main(1,temp)
    print(min(a,b))


# Example run
# Input:
-68
-31
# Output:
0
n = int(input())
a = list(map(int, input().split()))
i = 0
sum_before = 0
sum_after = 0
count = 0
while i < n:
    sum_after = sum_before + a[i]
    if sum_after * sum_before > 0 or sum_after == 0:
        if sum_after < 0:
            a[i] = a[i] - sum_after + 1
        elif sum_after > 0:
            a[i] = a[i] - sum_after - 1
        elif sum_before < 0:
            a[i] += 1
        else:
            a[i] -= 1
        count += abs(sum_after) + 1
        sum_after = sum_before + a[i]
    i += 1
    sum_before = sum_after
#print(a)
print(count)
 




# Example run
# Input:
-83
0
# Output:
0
n = int(input())
a = list(map(int,input().split()))
count=0
if a[0]>0:
  for i in range(n):
    if i%2==0:
      if sum(a[:i+1])<0:
        count+=-1*sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])+1
    else:
      if sum(a[:i+1])>0:
        count+=sum(a[:i+1])+1
        a[i]-=sum(a[:i+1])-1
else:
  for i in range(n):
    if i%2==0:
      if sum(a[:i+1])>0:
        count+=sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])-1
    else:
      if sum(a[:i+1])<0:
        count+=-1*sum(a[:i+1])+1
        a[i]+=-1*sum(a[:i+1])+1
if sum(a)==0:
  count+=1
print(count)

# Example run
# Input:
-31
-58867430
# Output:
0
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    n = inputInt()
    a = inputList()
    aa = []
    for i,val in enumerate(a):
        if i == 0:
            aa.append(val)
        else:
            tmp = val + aa[i-1]
            aa.append(tmp)
            
    barans = 0
    ans = 0
    flg = True
    for i,val in enumerate(aa):
        if i == 0:
            if val <= 0:
                barans = 1 - val
                ans += barans
        else:
            val_sin = val + barans
            if flg == True:
                flg = False
                if val_sin >= 0:
                    tmp = 1 + val_sin
                    ans += tmp
                    barans -= tmp
            else:
                flg = True
                if val_sin <= 0:
                    tmp = 1 - val_sin
                    ans += tmp
                    barans += tmp
        
    barans = 0
    ansans = 0
    flg = False
    for i,val in enumerate(aa):
        if i == 0:
            if val >= 0:
                barans = 1 + val
                ansans += barans
                barans = -1 * barans
        else:
            val_sin = val + barans
            if flg == True:
                flg = False
                if val_sin >= 0:
                    tmp = 1 + val_sin
                    ansans += tmp
                    barans -= tmp
            else:
                flg = True
                if val_sin <= 0:
                    tmp = 1 - val_sin
                    ansans += tmp
                    barans += tmp
        
    #print("{} {}".format(ans, ansans))
    print(min(ans,ansans))
        
    
if __name__ == "__main__":
	main()


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

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

if A[0] != 0:
    ans = 0
    S = A[0]
    f = A[0]//abs(A[0])
else:
    if ff == -1:
        ans = 1
        S = 1
        f = 1
    else:
        if ff % 2 == 0:
            ans = 1
            S = 1
            f = 1
        else:
            ans = 1
            S = -1
            f = -1

for a in A[1:]:
    S += a
    if S == 0:
        ans += 1
        S = -f
    else:
        if S/abs(S) != f*(-1):
            ans += abs(S)+1
            S = -f
    f *= -1
print(ans)


# Example run
# Input:
2
-1168909
# Output:
0
n = int(input())
a = list(map(int,input().split()))
b = [a_ for a_ in a]
 
ans = 10**14
for a0 in [-1,a[0],1]:
    if a0 == 0:
        continue
    ans_ = abs(a[0]-a0)
    b[0] = a0
    sign = b[0] > 0
    for i in range(1,n):
        b[i] = a[i]+b[i-1]
        if sign:
            if b[i] >= 0:
                ans_ += b[i]+1
                b[i] = -1
        else:
            if b[i] <= 0:
                ans_ += 1-b[i]
                b[i] = 1
        sign = not sign
    ans = min(ans, ans_)
print(ans)

# Example run
# Input:
-1504387
31
# Output:
0
from functools import lru_cache
n = int(input())
s = list(map(int, input().split()))


@lru_cache(maxsize=None)
def cost_e():
    res = 0
    sum = 0
    for j, y in enumerate(s, 1):
        tmp = sum + y
        if j & 1 and tmp >= 0:
            sum = -1
            res += abs(tmp) + 1
        elif not j & 1 and tmp <= 0:
            sum = 1
            res += abs(tmp) + 1
        else:
            sum = tmp
    return res


@lru_cache(maxsize=None)
def cost_o():
    res = 0
    sum = 0
    for j, y in enumerate(s, 1):
        tmp = sum + y
        if j & 1 and tmp <= 0:
            sum = 1
            res += abs(tmp) + 1
        elif not j & 1 and tmp >= 0:
            sum = -1
            res += abs(tmp) + 1
        else:
            sum = tmp
    return res


print(cost_e(), cost_o())


# Example run
# Input:
-97071
36241
# Output:
36242 0
N = int(input())
arr = list(map(int,input().split()))
def S1(a,b):
    c,total,ans = 0,0,0
    for t in arr:
        c += 1
        if c % 2 == a:
            if total+t <= 0:
                ans += abs(total+t)+1
                total = 1
                continue
        elif c % 2 == b:
            if total+t >= 0:
                ans += abs(total+t)+1
                total = -1
                continue
        total += t
    return ans
print(min(S1(1,0),S1(0,1)))

# Example run
# Input:
10921
86342186
# Output:
0
def f(c, cost):
    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
    return c, cost


n = int(input())
a = list(map(int, input().split()))
cost = (a[0] == 0)
c = a[0] + (a[0] == 0)
c, cost = f(c, cost)
tmp = cost
cost = 0
if a[0] >= 0:
    cost = a[0] + 1
    c = -1
else:
    cost = -a[0] + 1
    c = 1
c, cost = f(c, cost)
print(min(cost, tmp))


# Example run
# Input:
-39
2569
# Output:
False
def sequence(lis, first_value):
    count = 0
    now_sum = first_value
    pre_sum = first_value
    for num in lis[1:]:
        now_sum += num
        while now_sum == 0 or now_sum * pre_sum > 0:
            now_sum -= pre_sum/abs(pre_sum)
            count += 1
        pre_sum = now_sum
    return count

n = int(input())
a = [int(i) for i in input().split()]
if a[0] == 0:
    print(min(sequence(a, 1), sequence(a, -1))+1)
else:
    print(sequence(a, a[0]))

# Example run
# Input:
1854844
457058
# Output:
0
n = int(input())
a = [int(x) for x in input().split()]
ans = 2**60

if a[0] == 0:
  s = 1
  cnt = 1
  for i in range(1,n):
    ns = s + a[i]
    if s * ns < 0:
      s = ns
      continue
    else:
      cnt += abs(ns)+1
      s = -1 if ns > 0 else 1
  ans = min(ans, cnt)

  s = -1
  cnt = 1
  for i in range(1,n):
    ns = s + a[i]
    if s * ns < 0:
      s = ns
      continue
    else:
      cnt += abs(ns)+1
      s = -1 if ns > 0 else 1
  ans = min(ans, cnt)
  
else:
  s = a[0]
  cnt = 0
  for i in range(1,n):
    ns = s + a[i]
    if s * ns < 0:
      s = ns
      continue
    else:
      cnt += abs(ns)+1
      s = -1 if ns > 0 else 1
  ans = min(ans, cnt)
  
  s = -1 if a[0] > 0 else 1
  cnt = abs(a[0])+1
  for i in range(1,n):
    ns = s + a[i]
    if s * ns < 0:
      s = ns
      continue
    else:
      cnt += abs(ns)+1
      s = -1 if ns > 0 else 1
  ans = min(ans, cnt)

print(ans)

# Example run
# Input:
0
-1859885
# Output:
0
N = int(input())
A = tuple(map(int, input().split(' ')))

cs = A[0]
ans1 = 0
for na in A[1:]:
    if cs >= 0:
        cs += na
        if cs < 0:
            continue

        ans1 += cs + 1
        cs = -1
    else:
        cs += na
        if cs > 0:
            continue

        ans1 += -cs + 1
        cs = 1

if A[0] > 0:
    cs = -1
else:
    cs = 1
ans2 = A[0] + 1
for na in A[1:]:
    if cs >= 0:
        cs += na
        if cs < 0:
            continue

        ans2 += cs + 1
        cs = -1
    else:
        cs += na
        if cs > 0:
            continue

        ans2 += -cs + 1
        cs = 1

print(min(ans1, ans2))


# Example run
# Input:
-1
815
# 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 calc_num_op(cumul, a):
    tmp_cumul = cumul + a
    #  print('current cumul:', cumul)
    #  print('current a:', a)
    #  print('bare cumul:', tmp_cumul)
    #  print('goodiness:', tmp_cumul != 0 and cumul // abs(cumul) != tmp_cumul // abs(tmp_cumul))
    if (cumul <= 0 and tmp_cumul <= 0):
        return abs(-cumul - a + 1), 1
    if (cumul >= 0 and tmp_cumul >= 0):
        return abs(-cumul - a - 1), -1
    return 0, tmp_cumul


def solve(arr, sign):
    num_op = 0
    cumul = arr[0]
    #  print('current cumul:', cumul)
    if cumul == 0:
        num_op += 1
        cumul += 1 if sign == '+' else -1
        #  print('modified cumul:', cumul)
    for a in arr[1:]:
        delta, cumul = calc_num_op(cumul, a)
        #  print('delta:', delta)
        #  print('modified cumul:', cumul)
        num_op += delta
    return num_op


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

    op_plus = solve(arr, '+')
    #  print('op plus:', op_plus)
    op_minus = solve(arr, '-')
    #  print('op minus:', op_minus)

    print(min(op_plus, op_minus))


if __name__ == '__main__':
    main()


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

ans = float('inf')

cA = A[:]
cs = 0
cnt = 0
for i, a in enumerate(cA):
    if i%2 == 0: #ここまでの累積和が正
        if cs + a > 0:
            cs += a
        else:
            cA[i] += 1-(cs+a)
            cnt += 1-(cs+a)
            cs = 1
    else:
        if cs + a < 0:
            cs += a
        else:
            cA[i] += -1-(cs+a)
            cnt += abs(-1-(cs+a))
            cs = -1
ans = min(ans,cnt)

cA = A[:]
cs = 0
cnt = 0
for i, a in enumerate(cA):
    if i%2 == 1: #ここまでの累積和が正
        if cs + a > 0:
            cs += a
        else:
            cA[i] += 1-(cs+a)
            cnt += 1-(cs+a)
            cs = 1
    else:
        if cs + a < 0:
            cs += a
        else:
            cA[i] += -1-(cs+a)
            cnt += abs(-1-(cs+a))
            cs = -1
ans = min(ans,cnt)
print(ans)

# Example run
# Input:
260615611
20794
# Output:
0
N = int(input())
A = [int(x) for x in input().split()]

def F(A, sgn):
  cnt = 0
  cum = 0
  for a in A:
    sgn *= -1
    cum += a
    if cum * sgn > 0:
      continue
    if sgn > 0:
      cnt += 1 - cum
      cum = 1
    else:
      cnt += cum + 1
      cum = -1
  return cnt

answer = min(F(A,1), F(A,-1))
print(answer)

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

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

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


# Example run
# Input:
xed)
431
# Output:
0
n = int(input())
b = [int(x) for x in input().split()]
a = list()
temp = 0
count1 = 0
count2 = 0

a = b.copy()

if a[0] == 0:
	a[0] = 1
	count1 = 1

sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		count1 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

a = b.copy()

count2 = abs(a[0]) + 1
if a[0] >= 0:
	a[0] = -1
else:
	a[0] = 1
	
sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		count2 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


# Example run
# Input:
-126312
54
# Output:
0
n = int(input())
a = list(map(int,input().split()))
A = 10 ** 15

for i in [1,-1]:
    B = 0
    C = 0
    for j in a:
        B += j
        if B * i <= 0:
            C += abs(B - i)
            B = i
        i *= -1
    A = min(A,C)
print(A)

# Example run
# Input:
386945
3485
# Output:
0