Problem:
 Score : 300 points    Problem Statement You are given an integer sequence of length N . The i -th term in the sequence is a_i .
In one operation, you can select a term and either increment or decrement it by one.  At least how many operations are necessary to satisfy the following conditions?   For every i  (1≤i≤n) , the sum of the terms from the 1 -st through i -th term is not zero.  For every i  (1≤i≤n-1) , the sign of the sum of the terms from the 1 -st through i -th term, is different from the sign of the sum of the terms from the 1 -st through (i+1) -th term.       Constraints  2 ≤ n ≤ 10^5  |a_i| ≤ 10^9  Each a_i is an integer.         Input Input is given from Standard Input in the following format:  n  a_1  a_2  ...  a_n       Output Print the minimum necessary count of operations.        Sample Input 1 4
1 -3 1 0      Sample Output 1 4  For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1 , respectively, which satisfy the conditions.       Sample Input 2 5
3 -6 4 -5 7      Sample Output 2 0  The given sequence already satisfies the conditions.       Sample Input 3 6
-1 4 3 2 -5 4      Sample Output 3 8

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

def find(a,flag):
	c = 0
	s = 0
	for i in range(n):
		if flag and s + a[i] > 0:
			flag = False
			s = s + a[i]
		elif flag:
			c = c + abs(s + a[i])+1
			flag = False
			s = 1
		elif not flag and s + a[i] < 0:
			flag = True
			s = s + a[i]
	
		else:
			c = c + abs(s+a[i])+1
			flag = True
			s = -1
	return c

cplus = find(a,True)
cmin = find(a,False)
print(min(cplus,cmin))

Solution (Python):
N = int(input())
src = list(map(int,input().split()))

tmp1 = tmp2 = 0
ans1 = ans2 = 0
for i,a in enumerate(src):
    tmp1 += a
    tmp2 += a
    if i%2:
        if tmp1 <= 0:
            ans1 += 1 - tmp1
            tmp1 = 1
        if tmp2 >= 0:
            ans2 += tmp2 + 1
            tmp2 = -1
    else:
        if tmp2 <= 0:
            ans2 += 1 - tmp2
            tmp2 = 1
        if tmp1 >= 0:
            ans1 += tmp1 + 1
            tmp1 = -1
print(min(ans1,ans2))

Solution (Python):
def solve():
    n = int(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()

Solution (Python):
n = int(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))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num1, num2 = 0, 0
s = 0
for i in range(n):
    s += a[i]
    if i % 2 == 0 and s <= 0:
        num1 += 1 - s
        s = 1
    elif i % 2 == 1 and s >= 0:
        num1 += s + 1
        s = -1

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

print(min(num1, num2))

Solution (Python):
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)

Solution (Python):
def sign(number):
    if number < 0:
        return -1
    elif number > 0:
        return 1
    else:
        return 0


n = int(input())
a = list(map(int, input().split()))
c_sum = 0
cnt_lst = []

for i in range(1, -2, -2):
    code = i
    cnt, c_sum = 0, 0
    for j in range(n):
        if sign(c_sum+a[j]) == code:
            c_sum += a[j]

        else:
            cnt += abs(code-(c_sum+a[j]))
            c_sum = code

        code *= -1

    cnt_lst.append(cnt)

print(min(cnt_lst))

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]

ans=0
s=0
for i in range(N):
  s+=A[i]
  if i % 2 ==0:
    if s<=0:
      ans+=(abs(s)+1)
      s=1
  else:
    if s>=0:
      ans+=(abs(s)+1)
      s=-1

ans2=0
s2=0
for i in range(N):
  s2+=A[i]
  if i % 2 ==0:
    if s2>=0:
      ans2+=(abs(s2)+1)
      s2=-1
  else:
    if s2<=0:
      ans2+=(abs(s2)+1)
      s2=1
print(min(ans,ans2))

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

s = 0
ans1 = 0
for k in range(N):
    s += A[k]
    if k%2==0:
        if s <= 0:
            ans1 += -s+1
            s = 1
    else:
        if s >= 0:
            ans1 += s+1
            s = -1

s = 0
ans2 = 0
for k in range(N):
    s += A[k]
    if k%2==0:
        if s >= 0:
            ans2 += s+1
            s = -1
    else:
        if s <= 0:
            ans2 += -s+1
            s = 1

print(min(ans1,ans2))

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
even = 0
e_sum = 0
odd = 0
o_sum = 0
for i in range(n):
  e_sum += l[i]
  if i % 2 == 0 and e_sum <= 0:
    even += abs(e_sum)+1
    e_sum = 1
  elif not i % 2 == 0 and e_sum >= 0:
    even += abs(e_sum)+1
    e_sum = -1

for i in range(n):
  o_sum += l[i]
  if i % 2 == 0 and o_sum >= 0:
    odd += abs(o_sum)+1
    o_sum = -1
  elif not i % 2 == 0 and o_sum <= 0:
    odd += abs(o_sum)+1
    o_sum = 1

print(min(even, odd))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ten=0
ans=0
s=[0]*n
for i in range(n):
    s[i]=a[i]+ten
    if i%2==0:
        if s[i]<=0:
            ans+=abs(1-s[i])
            ten=1
        else:
            ten=s[i]
    elif i%2==1:
        if 0<=s[i]:
            ans+=abs(-1-s[i])
            ten=-1
        else:
            ten=s[i]
ten_2=0
ans_2=0
s_2=[0]*n
for i in range(n):
    s_2[i]=a[i]+ten_2
    if i%2==0:
        if 0<=s_2[i]:
            ans_2+=abs(-1-s_2[i])
            ten_2=-1
        else:
            ten_2=s_2[i]
    elif i%2==1:
        if s_2[i]<=0:
            ans_2+=abs(1-s_2[i])
            ten_2=1
        else:
            ten_2=s_2[i]
print(min(ans,ans_2))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = a[::]
ans1 = ans2 = 0
sign = 1
total = 0
for i in range(n):
    total += a[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans1 += k
        total = sign
    sign *= -1

sign = -1
total = 0
for i in range(n):
    total += b[i]
    if total * sign <= 0:
        k = abs(total - sign)
        ans2 += k
        total = sign
    sign *= -1
print(min(ans1, ans2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ansa,ansb,t=0,0,0
for i in range(n):
    t+=a[i]
    if i%2==1:
        if t>=0:
            ansa+=abs(t+1)
            t=-1
    else:
        if t<=0:
            ansa+=abs(t-1)
            t=1
t=0
for i in range(n):
    t+=a[i]
    if i%2==1:
        if t<=0:
            ansb+=abs(t-1)
            t=1
    else:
        if t>=0:
            ansb+=abs(t+1)
            t=-1
print(min(ansa, ansb))

Solution (Python):
n = int(input())
a_list = list(map(int, input().split(' ')))

def count_manipulation(a_list, start):
    assert start in (0, 1)
    sum = 0
    count = 0
    for i, a in enumerate(a_list):
        sum += a
        if i % 2 == start:
            if sum > 0:
                continue
            else:
                diff = 1 - sum
                count += diff
                sum += diff
        else:
            if sum < 0:
                continue
            else:
                diff = sum - (-1)
                count += diff
                sum -= diff
    return count

count_plus = count_manipulation(a_list, 0)
count_minus = count_manipulation(a_list, 1)
print(min(count_plus, count_minus))

Solution (Python):
n = int(input())
a_list = list(map(int, input().split(' ')))

def count_manipulation(a_list, start):
    assert start in (0, 1)
    sum = 0
    count = 0
    for i, a in enumerate(a_list):
        sum += a
        if i % 2 == start:
            if sum > 0:
                continue
            else:
                diff = 1 - sum
                count += diff
                sum += diff
        else:
            if sum < 0:
                continue
            else:
                diff = sum - (-1)
                count += diff
                sum -= diff
    return count

count_plus = count_manipulation(a_list, 0)
count_minus = count_manipulation(a_list, 1)
print(min(count_plus, count_minus))

Solution (Python):
def smaller(x, y):
	if x < y: return x
	else: return y

def judge(a, posneg):
	cnt = 0
	cur = posneg
	sum = 0
	for i in range(0, len(a)):
		sum = sum + a[i]
		sumt = sum * cur
		if sumt < 1:
			cnt = cnt + abs(cur - sum)
			sum = cur
		cur = -1 * cur
	return cnt

n = int(raw_input())
a = map(int, raw_input().split())
print smaller(judge(a, 1), judge(a, -1))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
sums = 0
count = 0
for i in range(n):
    sums = sums + a[i]
    if i % 2 ==0 :
        if sums > 0:
            None
        else:
            count = count + 1 -sums
            sums = 1
    else:
        if sums < 0:
            None
        else:
            count = count + 1 + sums
            sums = -1
            
count2 = 0
sums2 = 0
for i in range(n):
    sums2 = sums2 + a[i]
    if i % 2 ==1 :
        if sums2 > 0:
            None
        else:
            count2 = count2 + 1 -sums2
            sums2 = 1
    else:
        if sums2 < 0:
            None
        else:
            count2 = count2 + 1 + sums2
            sums2 = -1
            
print(min(count,count2))

Solution (Python):
n = int(input())
array = list(map(int, input().split()))

total = 0
flag = -1
minus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        minus += abs(total*flag)+1
        total = flag
    flag *= -1

total = 0
flag = 1
plus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        plus += abs(total*flag)+1
        total = flag
    flag *= -1

print(min(minus, plus))

Solution (Python):
N = int(input())
src = list(map(int,input().split()))

cum1 = cum2 = 0
ans1 = ans2 = 0
for i,a in enumerate(src):
    cum1 += a
    cum2 += a
    if i%2:
        if cum1 >= 0:
            ans1 += cum1+1
            cum1 = -1
        if cum2 <= 0:
            ans2 += 1-cum2
            cum2 = 1
    else:
        if cum1 <= 0:
            ans1 += 1-cum1
            cum1 = 1
        if cum2 >= 0:
            ans2 += cum2+1
            cum2 = -1

print(min(ans1,ans2))

Solution (Python):


N=int(input())
s=list(map(int,input().split()))
def f(N,s,t):
    ss=0
    w=0
    for i in range(N):
        ss+=s[i]
        if t==1:
            if ss<=0:
                w+=1-ss
                ss=1
            t=-1    
        elif t==-1:
            if ss>=0:
                w+=1+ss
                ss=-1
            t=1
    return w
t=1
a=f(N,s,t)
t=-1
b=f(N,s,t)
print(min(a,b))

Solution (Python):
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()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=cut=total=0
for i in range(n):
    total+=a[i]
    if i%2==0:
        if total<=0:
            cnt+=abs(1-total)
            total=1
    else:
        if 0<=total:
            cnt+=abs(-1-total)
            total=-1
total=0
for i in range(n):
    total+=a[i]
    if i%2==0:
        if 0<=total:
            cut+=abs(-1-total)
            total=-1
    else:
        if total<=0:
            cut+=abs(1-total)
            total=1
print(min(cut,cnt))

Solution (Python):
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))

Solution (Python):
n = int(input())
a = [int(x) for x in 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))

Solution (Python):
def sign(p):
    if p<0:
        return -1
    elif p>0:
        return 1
    else:
        return 0
N=int(input())
a=[int(i) for i in input().split()]
m=[0,0]
for sgn in [-1,1]:
    x=0
    S=0
    for i in range(N):
        S+=a[i]
        if sign(S)==sgn*(-1)**(i%2) or sign(S)==0:
            x+=abs(S)+1
            S=sgn*(-1)**((i+1)%2)
    m[(sgn+1)//2]=x
print(min(m))

Solution (Python):
def ops_needed(x, target):
    if abs(target - x) < abs(x):
        return 0
    else:
        return target - x

def count_ops(a, first_target):
    total_ops = 0
    accum = 0
    for i, ai in enumerate(a):
        new_accum = accum + a[i]
        if i % 2 == 1:
            ops = ops_needed(new_accum, first_target)
        else:
            ops = ops_needed(new_accum, -1 * first_target)
        total_ops += abs(ops)
        accum = new_accum + ops
    return total_ops
        

if __name__ == '__main__':
    _ = int(input())
    a = list(map(int, input().split()))
    print(min(count_ops(a, 1), count_ops(a, -1)))

Solution (Python):
def k(n, a, p):
    x = 0
    c = 0
    for i in range(n):
        s = x + a[i]
        if p and s > 0 or not p and s < 0: x = s
        else:
            c += abs(s) + 1
            if p: x = 1
            else: x = -1
        p = not p
    return c

n = int(input())
a = [int(x) for x in input().split()]
print(min(k(n, a, True), k(n, a, False)))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
def calc(t):
	global a
	ans = 0
	s = 0
	for i in a:
		s += i
		if s * t <= 0:
			ans += abs(s-t)
			s = t
		t *= -1
	return ans
print(min(calc(1),calc(-1)))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = [0,0]
total = 0
for i in range(n):
    total += a[i]
    if i%2==0:
        if total<=0:
            ans[0] += abs(total)+1
            total = 1
    else:
        if total>=0:
            ans[0] += abs(total)+1
            total = -1

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

print(min(ans))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
num,answer1= a[0],0
if a[0]==0:
	num,answer1 = 1,1
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer1 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
if a[0]==0: num,answer2 = -1,1
else: num,answer2 = -a[0]//abs(a[0]),abs(a[0]-(-a[0]//abs(a[0])))
for i in range(1,n):
	if num*(num+a[i]) >= 0:
		x = (-num)//abs(num)
		answer2 += abs((x-num)-a[i])
		num = x
	else:
		num += a[i]
print(min(answer1,answer2))

Solution (Python):


n=int(raw_input())
a=map(int,raw_input().split())
def f(a,s):
 ac=0
 cnt=0
 for i in xrange(n):
  ac+=a[i]
  if i%2:
   if s*ac>=0:
    cnt+=1+s*ac
    ac=-s
  else:
   if s*ac<=0:
    cnt+=1-s*ac
    ac=s
 return cnt
print min(f(a,1),f(a,-1))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum=a[0]
if(sum==0):
  opp=1
  sum=1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opp+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  opm=1
  sum=-1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opm+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  op=min(opm,opp)
else:
  opp=0
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opp+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  sum=a[0]
  opm=abs(sum)+1
  if(sum>0):sum=-1
  else:sum=1
  for i in a[1:]:
    if(sum*(sum+i)>=0):
      opm+=abs(sum+i)+1
      if(sum<0):sum=1
      else:sum=-1
    else:sum+=i
  op=min(opp,opm)
    
print(op)

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]


def judge(A,t):
    a_sum = 0
    cnt = 0
    for i in range(len(A)):
        a_sum += A[i]
        if i % 2 == 0:
            if t*a_sum  <= 0:
                cnt += 1-t*a_sum
                a_sum = t
        
        else:
            if t*a_sum >= 0:
                cnt += 1 + t*a_sum
                a_sum = -t
    
    return cnt
    
print(min(judge(A,1),judge(A,-1)))

Solution (Python):
def c_Sequence(N, A):
    total = 0  
    tmp1 = 0  
    for i in range(N):
        total += A[i]
        
        if i % 2 == 0:
            if total >= 0:
                tmp1 += abs(-1 - total)
                total -= abs(-1 - total)
        else:
            if total <= 0:
                tmp1 += 1 - total
                total += 1 - total

    total = 0
    tmp2 = 0
    for i in range(N):
        total += A[i]
        
        if i % 2 == 0:
            if total <= 0:
                tmp2 += 1 - total
                total += 1 - total
        else:
            if total >= 0:
                tmp2 += abs(-1 - total)
                total -= abs(-1 - total)
    ans = min(tmp1, tmp2)
    return ans
N = int(input())
A = [int(i) for i in input().split()]
print(c_Sequence(N, A))

Solution (Python):
N = int(input())
a = list(map(int,input().split(" ")))


def is_positive(sumval,modify):
	if sumval <= 0:
		modify += abs(sumval - 1)
		sumval = 1

	return sumval,modify

def is_negative(sumval,modify):
	if sumval >= 0:
		modify += abs(sumval + 1)
		sumval = (-1)


	return sumval,modify

pos_sum,pos_modi = is_negative(a[0],0)
neg_sum,neg_modi = is_positive(a[0],0)

for i in range(1,N):
	tmp_sum,tmp_modi = is_positive(pos_sum + a[i],pos_modi)
	pos_sum,pos_modi = is_negative(neg_sum + a[i],neg_modi)
	neg_sum = tmp_sum
	neg_modi = tmp_modi

print(min(pos_modi,neg_modi))

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

gokei = 0
ans1 = 0

for i in range(N):
    gokei += A[i]
    
    if i % 2 == 0:
        if gokei >= 0:
            ans1 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)
    if i % 2 == 1:
        if gokei <= 0:
            ans1 += 1 - gokei
            gokei += (1 - gokei)


gokei = 0
ans2 = 0
for i in range(N):
    gokei += A[i]
    
    if i % 2 == 0:
        if gokei <= 0:
            ans2 += 1 - gokei
            gokei += (1 - gokei)
    else:
        if gokei >= 0:
            ans2 += abs(-1 - gokei)
            gokei -= abs(-1 - gokei)

print(min(ans1, ans2))

Solution (Python):

"""
https://abc059.contest.atcoder.jp/tasks/arc072_a
WA
"""
import sys
from sys import stdin
input = stdin.readline


def check_sign(n):
    if n > 0:
        return 1
    elif n < 0:
        return -1
    else:
        return 0


def solve(A):
    p_ans = 0
    n_ans = 0
    i_ans = 0

    
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        p_ans += 1
        total += 1
        prev_sign = 1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            p_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            p_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        n_ans += 1
        total -= 1
        prev_sign = -1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            n_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            n_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    
    total = A[0]
    prev_sign = check_sign(total)
    if prev_sign == 0:
        i_ans += 1
        total += 1
        prev_sign = 1
    else:
        i_ans += (abs(total) + 1)
        if prev_sign > 0:
            prev_sign = -1
            total = -1
        else:
            prev_sign = 1
            total = 1

    for a in A[1:]:
        total += a
        sign = check_sign(total)
        if sign == 0:
            total -= prev_sign
            i_ans += 1
        elif prev_sign != sign:
            prev_sign = sign
        else:
            i_ans += (abs(total) + 1)
            if prev_sign < 0:
                total = 1
                prev_sign = 1
            else:
                total = -1
                prev_sign = -1

    return min(p_ans, n_ans, i_ans)


def main(args):
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import math


"""
e.g. N=3 a=[-1 1 1]
 -1 2  1 :1
 -1 2 -2 :4

e.g. N=3 a=[0 0 -1]
 1  0 -1 :1
 1 -2 -1 :3
 1 -2  2 :6

 -1 0 -1 :1
 -1 2 -1 :3
 -1 2 -2 :4

e.g. N=3 a=[0 0 1]
 1  0 1 :1
 1 -2 1 :3
 1 -2 2 :4

 -1 0  1 :1
 -1 2  1 :3
 -1 2 -2 :6

e.g. N=4 a=[0 0 0 -1]
 1  0 0 -1 :1
 1 -2 0 -1 :3
 1 -2 2 -1 :5
 1 -2 2 -2 :6

 -1 0  0 -1 :1
 -1 2  0 -1 :3
 -1 2 -2 -1 :5
 -1 2 -2  2 :8

e.g. N=4 a=[0 0 0 1]
 1  0 0  1 :1
 1 -2 0  1 :3
 1 -2 2  1 :5
 1 -2 2 -2 :8

 -1 0  0 1 :1
 -1 2  0 1 :3
 -1 2 -2 1 :5
 -1 2 -2 2 :6
"""


def main2():
    """
    累積和は、偶奇,奇偶のどちらかの数列になるので２種類試す
    """
    n = int(input())
    A = list(map(int, input().split()))

    ans = float("inf")
    for sign in (1, -1):
        s, n_op = 0, 0
        for a in A:
            s += a
            
            
            if s * sign <= 0:
                
                n_op += abs(s) + 1
                s = sign

            
            sign *= -1

        ans = min(ans, n_op)

    print(ans)


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

    ans = 0

    
    def sign(x):
        if x == 0:
            return 0
        return int(math.copysign(1, x))

    if a[0] == 0:
        for i in range(1, n):
            if a[i] != 0:
                sign_a = sign(a[i])
                if i % 2 == 0:
                    
                    a[0] = sign_a
                else:
                    a[0] = -sign_a

                ans += 1
                break
    s = a[0]

    for i in range(1, n):
        s1 = s + a[i]
        sign_s = sign(s)
        sign_s1 = sign(s1)

        if s1 == 0 or sign_s == sign_s1:
            
            
            diff = -(sign_s + s + a[i])
            a[i] += diff
            ans += abs(diff)

        s += a[i]

        
    print(ans)

if __name__ == '__main__':
    main2()

Solution (Python):

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


a_even = a[:]
a_even_sum = 0
curr = 0
for i in range(0,n):
	if i % 2 == 0:
		if a_even_sum + a_even[i] < 0:
			curr += abs(1 - (a_even_sum + a_even[i]))
			a_even[i] = abs(1 - a_even_sum)
		elif a_even_sum + a_even[i] == 0:
			curr += 1
			a_even[i] = 1
	else: 
		if a_even_sum + a_even[i] > 0:
			curr += abs(-1 - (a_even_sum + a_even[i]))
			a_even[i] = -abs(-1 - a_even_sum)
		elif a_even_sum + a_even[i] == 0:
			curr += 1
			a_even[i] = -1
	a_even_sum += a_even[i]



res = curr

a_odd = a[:]
a_odd_sum = 0
curr = 0
for i in range(0,n):
	if i % 2 == 0:
		if a_odd_sum + a_odd[i] > 0:
			curr += abs(-1 - (a_odd_sum + a_odd[i]))
			a_odd[i] = -abs(-1 - a_odd_sum)
		elif a_odd_sum + a_odd[i] == 0:
			curr += 1
			a_odd[i] = -1
	else: 
		if a_odd_sum + a_odd[i] < 0:
			curr += abs(1 - (a_odd_sum + a_odd[i]))
			a_odd[i] = abs(1 - a_odd_sum)
		elif a_odd_sum + a_odd[i] == 0:
			curr += 1
			a_odd[i] = 1
	a_odd_sum += a_odd[i]



res = min(res, curr)
print(res)

Solution (Python):
n=input()
a=map(int,raw_input().split())



a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)





b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)


b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)

Solution (Python):
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(input())
    a_list = list(map(int, input().split()))
    print(min(solve(True, a_list), solve(False, a_list)))


if __name__ == "__main__":
    main()

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

INF = float('inf')

ans = INF

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

print(ans)

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
def arrange(a0_is_plus):
    r=0 if a0_is_plus==True else 1
    sumNum=0
    ans=0
    for i,an in enumerate(a):
        sumNum+=an
        if i%2==r and sumNum<=0:
            ans+=1-sumNum
            sumNum=1
        elif i%2!=r and sumNum>=0:
            ans+=sumNum+1
            sumNum=-1
    return ans
print(min(arrange(True),arrange(False)))

Solution (Python):
N = int(input())
src = list(map(int, input().split()))

sum1 = sum2 = src[0]
op1 = op2 = 0
if sum1 < 1:
    op1 += (1 - sum1)
    sum1 = 1
if sum2 > -1:
    op2 += (sum2 + 1)
    sum2 = -1

for i in range(1,N):
    if i%2 == 1:
        if sum1 + src[i] > -1:
            op1 += (sum1 + src[i] + 1)
            sum1 = -1
        else:
            sum1 += src[i]
        if sum2 + src[i] < 1:
            op2 += (1 - sum2 - src[i])
            sum2 = 1
        else:
            sum2 += src[i]
    else:
        if sum2 + src[i] > -1:
            op2 += (sum2 + src[i] + 1)
            sum2 = -1
        else:
            sum2 += src[i]
        if sum1 + src[i] < 1:
            op1 += (1 - sum1 - src[i])
            sum1 = 1
        else:
            sum1 += src[i]

print(min(op1,op2))

Solution (Python):
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)))

Solution (Python):
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(input())
    a_list = list(map(int, input().split()))
    print(min(solve(True, a_list), solve(False, a_list)))


if __name__ == '__main__':
    main()

Solution (Python):
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(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()

Solution (Python):
n = int(input())
l = list(map(int, input().split()))

total = 0
ans1 = 0
ans2 = 0

for i, j in enumerate(l):
    total += j
    if i % 2 == 1:
        if total <= 0:
            ans1 += 1 + abs(total)
            total = 1
    else:
        if total >= 0:
            ans1 += 1 + abs(total)
            total = -1

total = 0

for i, j in enumerate(l):
    total += j
    if i % 2 == 0:
        if total <= 0:
            ans2 += 1 + abs(total)
            total = 1
    else:
        if total >= 0:
            ans2 += 1 + abs(total)
            total = -1

print(min(ans1, ans2))

Solution (Python):
import sys




def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


n = read_int()
a0 = read_int_list()
res = 10 ** 20
for first in [-1, 1]:
    a = list(a0)
    sign = first
    r = 0
    s = 0
    for i in range(n):
        if (s + a[i]) * sign <= 0:
            if sign < 0:
                dif = s + a[i] + 1
                a[i] -= dif
                r += dif
            if sign > 0:
                dif = -(s + a[i]) + 1
                a[i] += dif
                r += dif
        sign *= -1
        s += a[i]
    if res > r:
        res = r
print(res)