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



Sample input:
4
1 -3 1 0


Sample output:
4

Submission status: Wrong Answer

Solution code:
n = int(input())
n_list = list(map(int, input().split()))

count = 0
prev_sum = n_list[0]

for i in n_list[1:]:
  if prev_sum < 0:
    if -prev_sum >= i:
      count += abs((-prev_sum + 1) - i)
      i = -prev_sum + 1
  else:
    if -prev_sum <= i:
      count += abs((-prev_sum - 1) - i)
      i = -prev_sum - 1
  prev_sum += i

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
n_list = list(map(int, input().split()))

count = 0
prev_sum = n_list[0]

for i in n_list[1:]:
  if prev_sum < 0:
    if -prev_sum >= i:
      count += abs((-prev_sum + 1) - i)
      i = -prev_sum + 1
  else:
    if -prev_sum < i:
      count += abs((-prev_sum - 1) - i)
      i = -prev_sum - 1
  prev_sum += i

print(count)

Submission status: Wrong Answer

Solution code:
def count_op(n, a, i_sum):
    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:
    i_sum = a[0]
    print(count_op(n, a, a[0]))
else:
    b = a[:]
    a[0] = 1
    op_num_a = count_op(n, a, a[0]) + 1
    b[0] = -1
    op_num_b = count_op(n, b, b[0]) + 1
    print(min(op_num_a, op_num_b))

Submission status: Wrong Answer

Solution code:
input()
a = list(map(int, input().split()))
s = a[0]
ret = 0
k = 1 if a[0] > 0 else -1
ret2 = k * a[0] + 1
p = -k
for i in a[1:]:
  if s * (s+i) < 0:
    s = s+i
  else:
    t = s + i
    k = 1 if t > 0 else -1
    ret += k * t + 1
    s = -k
  if p * (p+i) < 0:
    p = p+i
  else:
    t = p + i
    k = 1 if t > 0 else -1
    ret2 += k * t + 1
    p = -k
print(min(ret, ret2))

Submission status: Wrong Answer

Solution code:
input()
a = list(map(int, input().split()))
s = a[0]
ret = 0
for i in a[1:]:
  if s * (s+i) < 0:
    s = s+i
  else:
    t = s + i
    k = 1 if t > 0 else -1
    ret += k * t + 1
    s = -k
print(ret)

Submission status: Wrong Answer

Solution code:
input()
a = list(map(int, input().split()))
s = a[0]
ret = 0
for i in a[1:]:
  if s * i > 0:
    t = s + i
    k = 1 if t > 0 else -1
    ret += k * t + 1
    s = -k
  else:
    if s * (s+i) < 0:
      s = s+i
    else:
      k = 1 if s > 0 else -1
      ret += k*(s+i)+1
      s = -k
print(ret)

Submission status: Wrong Answer

Solution code:
input()
a = list(map(int, input().split()))
s = a[0]
ret = 0
for i in a[1:]:
  if s * i > 0:
    t = s + i
    k = 1 if t > 0 else -1
    ret += k * t + 1
    s = -k
  else:
    if s * (s+i) < 0:
      s = s+i
    else:
      ret += s+i+1
      s = -1 if s > 0 else 1
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

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

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

ans = int(min(ans_even, ans_odd))

print(ans)

Submission status: Wrong Answer

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

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

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

ans = min(ans_even, ans_odd)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(int, input().split())
sum_b = 0
cnt_b = 0
sum_c = 0
cnt_c = 0
for i,a in enumerate(A):
  sum_b += a
  if (sum_b > 0) != ((i % 2) > 0):
    cnt_b += abs(sum_b) + 1
    sum_b = 1 if ((i % 2) > 0) else -1
  sum_c += a
  if (sum_c >= 0) == ((i % 2) > 0):
    cnt_c += abs(sum_c) + 1
    sum_c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = [int(ai) for ai in input().split()]

def search(a, flip=False):
    if not flip:
        count = 0
    else:
        count = abs(a[0]) + 1
        a[0] = 1 if a[0] < 0 else -1
    a_sum = a[0]
    for ai in a[1:]:
        tmp_sum = a_sum + ai
        if tmp_sum < 0 and a_sum < 0:
            c = abs(tmp_sum) + 1
        elif tmp_sum > 0 and a_sum > 0:
            c = -abs(tmp_sum) - 1
        elif tmp_sum == 0 and a_sum < 0:
            c = 1
        elif tmp_sum == 0 and a_sum > 0:
            c = -1
        else:
            c = 0
        count += abs(c)
        a_sum = tmp_sum + c
    return count

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
sum_b = 0
cnt_b = 0
sum_c = 0
cnt_c = 0
for i,a in enumerate(A):
  sum_b += a
  if (sum_b > 0) != ((i % 2) > 0):
    cnt_b += abs(sum_b) + 1
    sum_b = 1 if ((i % 2) > 0) else -1
  sum_c += a
  if (sum_c > 0) == ((i % 2) > 0):
    cnt_c += abs(sum_c) + 1
    sum_c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(int, input().split())
sum_b = 0
cnt_b = 0
sum_c = 0
cnt_c = 0
for i,a in enumerate(A):
  sum_b += a
  if (sum_b > 0) != ((i % 2) > 0):
    cnt_b += abs(sum_b) + 1
    sum_b = 1 if ((i % 2) > 0) else -1
  sum_c += a
  if (sum_c > 0) == ((i % 2) > 0):
    cnt_c += abs(sum_c) + 1
    sum_c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = [int(ai) for ai in input().split()]

def search(a, flip=False):
    if not flip:
        count = 0
    else:
        count = abs(a[0]) + 1
        a[0] = 1 if a[0] < 0 else -1

    a_sum = 0
    for i, ai in enumerate(a):
        if i == 0:
            a_sum += ai
        else:
            tmp_sum = a_sum
            tmp_sum += ai
            if tmp_sum < 0 and a_sum < 0:
                c = abs(tmp_sum) + 1
            elif tmp_sum > 0 and a_sum > 0:
                c = -abs(tmp_sum) - 1
            elif tmp_sum == 0 and a_sum < 0:
                c = 1
            elif tmp_sum == 0 and a_sum > 0:
                c = -1
            else:
                c = 0
            count += abs(c)
            a_sum = tmp_sum + c
    return count

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

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = [int(ai) for ai in input().split()]

def search(a, flip=False):
    if flip:
        count = 0
    else:
        count = abs(a[0]) + 1
        a[0] = 1 if a[0] < 0 else -1
    a_sum = a[0]
    for ai in a[1:]:
        tmp_sum = a_sum + ai
        if tmp_sum < 0 and a_sum < 0:
            c = +1 - tmp_sum
            a_sum = 1
        elif tmp_sum > 0 and a_sum > 0:
            c = -1 - tmp_sum
            a_sum = -1
        elif tmp_sum == 0 and a_sum < 0:
            c = 1
            a_sum = 1
        elif tmp_sum == 0 and a_sum > 0:
            c = 1
            a_sum = -1
        else:
            c = 0
        count += abs(c)
        a_sum = tmp_sum + c

    return count

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ai=input().split()
ai=[int(x) for x in ai]

Sn=[0]
op=0
for i in range(n-1):
    Si=Sn[i]+ai[i]
    Sip=Si+ai[i+1]

    if(Si>0 and Sip>0):
        if(Sip>=Si):
            op+=Si+1
            Si=-1
        elif(Sip<Si):
            op+=Sip+1
            ai[i + 1]+=-Sip-1

    if(Si < 0 and Sip < 0):
        if(-Sip>=-Si):
            op += -Si + 1
            Si =  1
        elif(-Sip<-Si):
            op += -Sip + 1
            ai[i + 1]+=-Sip+1

    if(Si==0):
        Si=1
        op+=1

    Sn.append(Si)

Si=Sn[n-1]+ai[n-1]
if(Si==0):
    Si+=1
    op+=1

print(op)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(ai) for ai in input().split()]

count = 0
a_sum = a[0]
for ai in a[1:]:
    next_sum = a_sum + ai
    if next_sum * a_sum < 0:
        a_sum = next_sum
        continue
    count += abs(next_sum) + 1

    if a_sum < 0:
        a_sum = 1
    else:
        a_sum = -1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(ai) for ai in input().split()]

count = 0
a_sum = a[0]
for ai in a[1:]:
    tmp_sum = a_sum + ai
    if tmp_sum < 0 and a_sum < 0:
        c = +1 - tmp_sum
        a_sum = 1
    elif tmp_sum > 0 and a_sum > 0:
        c = -1 - tmp_sum
        a_sum = -1
    elif tmp_sum == 0 and a_sum < 0:
        c = 1
        a_sum = 1
    elif tmp_sum == 0 and a_sum > 0:
        c = 1
        a_sum = -1
    else:
        c = 0
    count += abs(c)
    a_sum = tmp_sum + c

print(count)

Submission status: Wrong Answer

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

def find(a):
	f = "+" if a[0] < 0 else "-"
	s = a[0]
	c = 0
	#print((s,f,c))
	for i in range(1,n):
		if f == "+" and s + a[i] > 0:
			f = "-"
			s = s + a[i]
	#		print((s,f,c))
		elif f == "+":
			c = c + abs(s + a[i])+1
			f = "-"
			s = 1
	#		print((s,f,c))
		elif f == "-" and s + a[i] < 0:
			f = "+"
			s = s + a[i]
	#		print((s,f,c))
		else:
			c = c + abs(s+a[i])+1
			f = "+"
			s = -1
	return c

c = find(a)
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
ai=input().split()
ai=[int(x) for x in ai]

Sn=[0]
op=0
for i in range(n-1):
    Si=Sn[i]+ai[i]
    Sip=Si+ai[i+1]

    if(Si>0 and Sip>0):
        if(Sip>=Si):
            op+=Si+1
            Si=-Si-1
        elif(Sip<Si):
            op+=Sip+1
            ai[i + 1]+=-Sip-1

    if(Si < 0 and Sip < 0):
        if(-Sip>=-Si):
            op += -Si + 1
            Si = -Si + 1
        elif(-Sip<-Si):
            op += -Sip + 1
            ai[i + 1]+=-Sip+1

    if(Si==0):
        Si+=1
        op+=1

    Sn.append(Si)

Si=Sn[n-1]+ai[n-1]
if(Si==0):
    Si+=1
    op+=1

print(op)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(ai) for ai in input().split()]

count = 0
a_sum = 0
for i, ai in enumerate(a):
    if i == 0:
        a_sum = ai
    else:
        tmp_sum = a_sum + ai
        if tmp_sum < 0 and a_sum < 0:
            c = +1 - tmp_sum
            a_sum = 1
        elif tmp_sum > 0 and a_sum > 0:
            c = -1 - tmp_sum
            a_sum = -1
        elif tmp_sum == 0 and a_sum < 0:
            c = +1
            a_sum = 1
        elif tmp_sum == 0 and a_sum > 0:
            c = -1
            a_sum = 1
        else:
            c = 0
        count += abs(c)
        a_sum = tmp_sum + c

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
#n = 6
#a = list(map(int,"-1 4 3 2 -5 4".split()))
#a = list(map(int,"-1 4 -4 2 -5 5".split()))

f = "+" if a[0] < 0 else "-"
s = a[0]
c = 0
#print((s,f,c))
for i in range(1,n):
	if f == "+" and s + a[i] > 0:
		f = "-"
		s = s + a[i]
#		print((s,f,c))
	elif f == "+":
		c = c + abs(s + a[i])+1
		f = "-"
		s = 1
#		print((s,f,c))
	elif f == "-" and s + a[i] < 0:
		f = "+"
		s = s + a[i]
#		print((s,f,c))
	else:
		c = c + abs(s+a[i])+1
		f = "+"
		s = -1
#		print((s,f,c))
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(ai) for ai in input().split()]

count = 0
a_sum = 0
for i, ai in enumerate(a):
    if i == 0:
        a_sum = ai
    else:
        tmp_sum = a_sum + ai
        if tmp_sum < 0 and a_sum < 0:
            c = abs(tmp_sum) + 1
        elif tmp_sum > 0 and a_sum > 0:
            c = -abs(tmp_sum) - 1
        elif tmp_sum == 0 and a_sum < 0:
            c = -1
        elif tmp_sum == 0 and a_sum > 0:
            c = 1
        else:
            c = 0
        count += abs(c)
        a_sum = tmp_sum + c

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(int, input().split())
b = 0
cnt_b = 0
c = 0
cnt_c = 0
for i,a in enumerate(A):
  b += a
  c += a
  if (b > 0) != ((i % 2) > 0):
    cnt_b += abs(b) + 1
    b = 1 if ((i % 2) > 0) else -1
  if (c > 0) == ((i % 2) > 0):
    cnt_c += abs(c) + 1
    c = -1 if ((i % 2) > 0) else 1
print(min(cnt_b, cnt_c))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(ai) for ai in input().split()]

count = 0
a_sum = 0
for i, ai in enumerate(a):
    if i == 0:
        a_sum += ai
    else:
        tmp_sum = a_sum
        tmp_sum += ai
        if tmp_sum < 0 and a_sum < 0:
            c = abs(tmp_sum) + 1
        elif tmp_sum > 0 and a_sum > 0:
            c = -abs(tmp_sum) - 1
        elif tmp_sum == 0 and a_sum < 0:
            c = 1
        elif tmp_sum == 0 and a_sum > 0:
            c = -1
        else:
            c = 0
        count += abs(c)
        a_sum = tmp_sum + c
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int, input().split()))
#値のコピーを作るときはスライスする
B=A[:]

#a1の符号を正にする場合
count_1=0
sum_1=0
if A[0]==0:
    A[0]+=1
    count_1+=1
    sum_1+=A[0]
elif A[0]>0:
    sum_1+=A[0]
elif A[0]<0:
    A[0]=1
    count_1+=(abs(A[0])+1)
    sum_1+=A[0]

for i in range(1,n):
    #奇数番目の項までの和は正に
    if i%2==0:#奇数番目の項
        if sum_1+A[i]>0:
            sum_1+=A[i]
        elif sum_1+A[i]<0:
            count_1 += (abs(sum_1+A[i])+1)
            sum_1=1
        elif sum_1+A[0]==0:
            count_1+=1
            sum_1=1
        else:
            pass
    #偶数番目の項までの和は負に
    elif i%2==1:#偶数番目の項
        if sum_1+A[i]>0:
            count_1 += (abs(sum_1+A[i])+1)
            sum_1=-1
        elif sum_1+A[i]<0:
            sum_1+=A[i]
        elif sum_1+A[i]==0:
            sum_1 = -1
            count_1+=1
        else:
            pass


#a1の符号を負にする場合
count_2=0
sum_2=0
if B[0]==0:
    B[0]-=1
    count_2+=1
    sum_2+=B[0]
elif B[0]>0:
    B[0]= -1
    count_2+=(abs(B[0])+1)
    sum_2+=B[0]
elif B[0]<0:
    sum_2+=B[0]

for i in range(1,n):
    if i%2==0:#奇数番目の項
    #奇数番目の項までの和は負に
        if sum_2+B[i]>0:
            count_2 += (abs(sum_2+B[i])+1)
            sum_2= -1
        elif sum_2+B[i]<0:
            sum_2+=B[i]
        elif sum_2+B[i]==0:
            sum_2 = -1
            count_2+=1
        else:
            pass
    #偶数番目の項までの和は負に
    elif i%2==1:#偶数番目の項
        if sum_2+B[i]>0:
            sum_2+=B[i]
        elif sum_2+B[i]<0:
            count_2 += (abs(sum_2+B[i])+1)
            sum_2=1
        elif sum_2+B[i]==0:
            count_2+=1
            sum_2=1
        else:
            pass

print(min(count_1,count_2))

Submission status: Wrong Answer

Solution code:
import math

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

cnt = 0
x = []
x.append(a[0])

if a[0] == 0:
    cnt += 1
    if a[1] > 0:
        x[0] = -1
    else:
        x[0] = 1


for i in range(n-1):
    
    if x[i] > 0:
        if x[i]+a[i+1] > -1:
            tmp = int(math.fabs(x[i] + a[i+1]) + 1)
            a[i+1] = a[i+1] - tmp
            cnt += tmp
        x += [x[i] + a[i+1]]
        
    else:
        if x[i]+a[i+1] < +1:
            tmp = int(math.fabs(x[i] + a[i+1]) + 1)
            a[i+1] = a[i+1] + tmp
            cnt += tmp
        x += [x[i] + a[i+1]]

print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

cnt = 0
x = []
x.append(a[0])

for i in range(n-1):
    if x[i] > 0:
        if x[i]+a[i+1] > -1:
            cnt += math.fabs(x[i] + a[i+1]) + 1
            x += [-1]
        else:
            x += [x[i] + a[i+1]]
        
    else:
        if x[i]+a[i+1] < +1:
            cnt += math.fabs(x[i] + a[i+1]) + 1
            x += [1]
        else:
            x += [x[i] + a[i+1]]

print(int(cnt))

Submission status: Wrong Answer

Solution code:
def m():
    n = int(input())
    a = list(map(int, input().split()))
    even = a[1::2]
    odd = a[::2]
    ever_total = 0
    ans = 0
    if sum(even) > sum(odd):
        # マイナススタート
        for i in range(n):
            ever_total += a[i]
            if (i+2) % 2 == 0:
                if ever_total <= 0:
                    pass
                else:
                    ans += abs(a[i-1]) + 1
            else:
                if ever_total >= 0:
                    pass
                else:
                    ans += abs(a[i - 1]) + 1
    else:
        # プラス
        for i in range(n):
            ever_total += a[i]
            if (i+2) % 2 == 0:
                if ever_total >= 0:
                    pass
                else:
                    ans += abs(a[i-1]) + 1
            else:
                if ever_total <= 0:
                    pass
                else:
                    ans += abs(a[i - 1]) + 1
    return ans
print(m())

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
ma=list(map(int,a))
A1=ma[0]
if ma[0]>0:
    NEXT=-1-ma[0]
elif ma[0]<0:
    NEXT=1-ma[0]

ans=0
ans1=0
for k in range(1,N):
    if ma[0] > 0:
        
        if k%2 ==0:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==1:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=2
        
    elif ma[0]<0:
        
        if k%2 ==1:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==0:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=2
                
for k in range(1,N):
    if ma[0] < 0:
        
        if k%2 ==0:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans1+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==1:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans1+=abs(ma[k]-NEXT)
                NEXT=2
        
    elif ma[0]>0:
        
        if k%2 ==1:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans1+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==0:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans1+=abs(ma[k]-NEXT)
                NEXT=2                
            
print(min(ans1,ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
ma=list(map(int,a))
A1=ma[0]
if ma[0]>0:
    NEXT=-1-ma[0]
elif ma[0]<0:
    NEXT=1-ma[0]

ans=0

for k in range(1,N):
    if ma[0] > 0:
        
        if k%2 ==0:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==1:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=2
        
    elif ma[0]<0:
        
        if k%2 ==1:
            if NEXT<=ma[k]:
                NEXT=NEXT-ma[k]-2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=-2
        elif k%2 ==0:
            if NEXT>=ma[k]:
                NEXT=NEXT-ma[k]+2
            else:
                ans+=abs(ma[k]-NEXT)
                NEXT=2
            
print(ans)

Submission status: Wrong Answer

Solution code:
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()))
csum_lst = [0 for i in range(n)]
csum_lst[0] = a[0]
cnt = 0

for i in range(1, n):
    if a[i] == 0:
        new_a = -(csum_lst[i - 1] + 1 * sign(csum_lst[i - 1]))
        cnt += abs(new_a - a[i])
        a[i] = new_a

    elif sign(csum_lst[i-1]) == sign(a[i]) or abs(csum_lst[i-1]) >= abs(a[i]):
        new_a = -(csum_lst[i-1]+1*sign(csum_lst[i-1]))
        cnt += abs(new_a-a[i])
        a[i] = new_a

    csum_lst[i] = csum_lst[i-1] + a[i]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
s = A[0]
ans1 = 0

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

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

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
s = A[0]
ans = 0

for k in range(1,N):
    if s*(s+A[k])<=-1:
        s += A[k]
    else:
        if s > 0:
            if s + A[k] >= 0:
                ans += s + A[k] + 1
                s = -1
        elif s < 0:
            if s + A[k] <= 0:
                ans += 1 - s - A[k]
                s = 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 sums > 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))

Submission status: Wrong Answer

Solution code:
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 ==0 :
        if sums > 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))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = a
#1 = plus
cp = 0
cm = 0
sumscp = 0
sumscm = 0

for i in range(len(a)):
    
    if i % 2 == 0:
        while sumscp + a[i] < 1:
            a[i] = a[i] + 1
            cp = cp + 1
        sumscp = sumscp + a[i]
    else:
        while sumscp + a[i] > -1:
            a[i] = a[i] - 1
            cp = cp + 1
        sumscp = sumscp + a[i]
        
for i in range(len(b)):
    
    if i % 2 == 0:
        while sumscm + b[i] > -1:
            b[i] = b[i] - 1
            cm = cm + 1
        sumscm = sumscm + b[i]
    else:
        while sumscm + a[i] < 1:
            b[i] = b[i] + 1
            cm = cm + 1
        sumscm = sumscm + b[i]
    
print(min(cp,cm))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

cum1 = cum2 = src[0]
ans1 = ans2 = 0
for i,a in enumerate(src[1:]):
    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))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
s=list(map(int,input().split()))
if s[0]<=0:
    t=1
elif s[0]>0:
    t=-1
ss=s[0]   
w=0
for i in range(N-1):
    if t==1:
        if ss+s[i+1]>=t:
            ss=ss+s[i+1]
            pass
        else:
            w+=t-ss-s[i+1]
            ss=1
        t=-1
    elif t==-1:
        if ss+s[i+1]<=t:
            ss=ss+s[i+1]
            pass
        else:
            w+=ss+s[i+1]-t
            ss=-1
        t=1
print(w)

Submission status: Wrong Answer

Solution code:
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))