Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    S = N[l]
    skip = 0
    for i in range(len(S)):
        if skip > 0:
            skip -= 1
        elif S[i] == "@":
            n = int(S[i+1])
            for j in range(n):
                print(S[i+2],end="")
            skip = 2
        else:
            print(S[i],end="")
    print("")



# Example run
# Input:
GQ\v
# Output:
GQ\v
while True:
	try:
		line=list(map(str,input()))
		string=""
		for i in range(len(line)):
			if (line[i]!='@' and line[i-1]!='@'):
				string+=line[i]
			elif line[i]=='@':
				string+=line[i+2]*int(line[i+1])
			else:
				pass
		print(string)
	except EOFError:
		break
		
				

# Example run
# Input:
}#S)VkY
# Output:
}#S)VkY
while 1:
    try:
        count = 0
        answer = ""
        N = list(input())
        for i in N:
            if i == "@":
                answer += int(N[count + 1]) * N[count + 2]
                del N[count], N[count + 1]
            else:
                answer += N[count]
            count += 1
        print(answer)
    except:
        break


# Example run
# Input:
dvoo'VhSn
# Output:
dvoo'VhSn
while 1:
    res = ""
    check = []
    try:
        s = input()
        for i in range(len(s)):
            if i in check:
                continue
            elif s[i] == "@":
                res = res + s[i+2] * int(s[i+1])
                check.append(i+1)
                check.append(i+2)
            else:
                res = res + s[i]
        print(res)
    except EOFError:
        break

# Example run
# Input:
Js>o<w]
# Output:
Js>o<w]
while True:
    try:
        s = list(input())
        while '@' in s:
            num = s.index('@')
            s[num+1] = s[num+2] * (int(s[num+1])-1)
            s.pop(num)

    except EOFError:
        break

    print(''.join(s))


# Example run
# Input:
Q5EY
# Output:
Q5EY
while True:
    try:
        string = input()
    except:
        break
    ans = ""
    for i in range(len(string)):
        if string[i] == "@":
            ans += int(string[i+1])*string[i+2]
        else:
            ans += string[i]
    print(ans)

# Example run
# Input:
::|e
# Output:
::|e
while 1:
    try:
        s = input()
        t = ''
        i = 0
        while i < len(s):
            if s[i] == '@':
                t += s[i + 2] * int(s[i + 1])
                i += 3
            else:
                t += s[i]
                i += 1
        print(t)
    except:
        break



# Example run
# Input:
Xg<'3O.+[
# Output:
Xg<'3O.+[
while True:
    try: n = input().split('@')
    except: break

    S, ans = n[1:], n[0]
    for s in S:
        ans += int(s[0]) * s[1]
        ans += s[2:]
    print(ans)



# Example run
# Input:
e3zvshd]
# Output:
e3zvshd]
while(1):
    try:
        s = list(input())
        skip = 0
        o = []
        for i in range(len(s)):
            if skip != 0:
                skip -= 1
                continue
            if s[i] != "@":
                o.append(s[i])
            else:
                skip = 2
                for j in range(int(s[i+1])):
                    o.append(s[i+2])
        print(*o,sep="")

    except EOFError:
        break


# Example run
# Input:
k9UI.C>
# Output:
k9UI.C>
try:
    while True:
        n = 0
        str3 = []
        str1 = input()
        str2 = [a for a in str1]
        num = len(str2)
        for num1 in range(0,num):
            if str2[num1] == "@":
                for num2 in range(int(str2[num1 + 1])):
                    print(str2[num1 + 2],end="")
                n = 2
                continue
            else:
                if n > 0:
                    n -= 1
                    continue
                else:
                    print(str2[num1],end="")
                    continue
        print()
except EOFError as e:
    n = 0


# Example run
# Input:
[Zsd
# Output:
[Zsd
# AOJ 0077 Run Length
# Python3 2018.6.15 bal4u

while True:
	try: s = list(input())
	except EOFError: break
		
	ans = []
	i = 0
	while i < len(s):
		if s[i] == '@':
			for j in range(int(s[i+1])): ans += s[i+2]
			i += 2
		else: ans += s[i]
		i += 1
	print(*ans, sep='')



# Example run
# Input:
cUc&W1}iQ
# Output:
cUc&W1}iQ
###
### atcorder test program
###

import sys

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Prime number search
    def Pnum(self, a):
        if a == 1: return False
        for i in range(2,int(a**0.5)+1):
            if a % i == 0:
                return False
        return True

    ### Circle area
    def caria(self, r):
        return r*r*self.pi

math = math()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

#A, B, C = [int(x) for x in input().split()]

def get_input():
  N = []
  while True:
    try:
      N.append(input())
      #N.append(int(input()))
    except EOFError:
      break
  return N
 
N = get_input()

for S in N:
    i = 0
    while True:
        if i >= len(S):
            break
        if (S[i]=='@'):
            for j in range(int(S[i+1])):
                print(S[i+2], end='')
            i += 3
        else:
            print(S[i], end='')
            i += 1
        
    print()








# Example run
# Input:
Q<jukmQ3m
# Output:
Q<jukmQ3m
def aux(s):
  return(s[1]*int(s[0]) + s[2:])

while True:
  try:
    s = input().strip()
    v = s.split('@')
    t = v[0]
    for i in (map(lambda x:aux(x), v[1:])):
      t += i
    print(t)

  except EOFError:
      break

# Example run
# Input:
U9aF:i8g
# Output:
U9aF:i8g
while True:
    try:
        cha = input()
        cha = list(cha)
        ans = ""
        i = 0
        while i < len(cha):
            if cha[i] == "@":
                n = int(cha[i + 1])
                moji = cha[i + 2]
                for j in range(n):
                    ans += moji
                i += 3
            else:
                ans += cha[i]
                i += 1
        print(ans)
    except:
        break

# Example run
# Input:
e3zvshd]
# Output:
e3zvshd]
while True :
    try :
        s = list(input())
    except EOFError :
        break
    
    i = 0
    while i < len(s) :
        if s[i] == "@" :
            for j in range(int(s[i+1])) :
                print(s[i+2], end="")
            i += 3
        else :
            print(s[i], end="")
            i += 1
    print()


# Example run
# Input:
-M>Ld
# Output:
-M>Ld
while True:
    try:
        s = input()
    except EOFError:
        break

    r = ''
    n = 1
    for c in s:
        if n < 0:
            n = int(c)
        elif c == '@':
            n = -1
        else:
            r += c * n
            n = 1
    print(r)

# Example run
# Input:
`W9^t
# Output:
`W9^t
if __name__ == '__main__':

    ans = ""
    while True:
        try:
            tmp = ""
            ans = ""
            line = input()
            for x in line:
                if x == "@":
                    tmp += "@"
                else:
                    if len(tmp) == 0:
                        ans += x
                    else:
                        tmp += x
                        if len(tmp) == 3:
                            ans += tmp[2]*int(tmp[1])
                            tmp = ""
            print(ans)
        except EOFError:
            break



# Example run
# Input:
dSsm`%X6*
# Output:
dSsm`%X6*
while True:
    try:
        a = list(input())
    except:
        break
    ans = ""
    for i in range(len(a)-a.count("@")*2):
        if a[i] == "@":
            ans += a[i+2]*int(a[i+1])
            del a[i+1:i+3]
        else:
            ans += a[i]
    print(ans)
    


# Example run
# Input:
'y?HeBTk
# Output:
'y?HeBTk
def restore(s):
  ret = ""
  ind = 0
  end = len(s)
  while ind < end:
    if s[ind] == "@":
      ret += s[ind + 2] * int(s[ind + 1])
      ind += 3
    else:
      ret += s[ind]
      ind += 1
  return ret

while True:
  try:
    print(restore(input()))

  except EOFError:
    break


# Example run
# Input:
f+v-/5
# Output:
f+v-/5
while 1:
    try:s=input()
    except:break
    i,a,n=0,'',1
    for i in s:
        if n==0:n=int(i)
        elif i=='@': n=0
        else:
            a+=i*n
            n=1
    print(a)

# Example run
# Input:
+|Er
# Output:
+|Er
while True:
    try:
        Tlist = list(input())
    except:
        break
    while '@' in Tlist:
        at = Tlist.index('@')
        t = Tlist[at+2]
        x = int(Tlist[at+1])
        del(Tlist[at:at+3])
        Tlist.insert(at,t*x)
    print(''.join(Tlist))


# Example run
# Input:
^>x#
# Output:
^>x#
while 1:
    try:
        word = input()
    except EOFError:
        break

    newword = []
    word = list(word)
    while word != []:
        w = word.pop(0)
        if w == "@":
            count = int(word.pop(0))
            s = word.pop(0)
            for _ in range(count):
                newword.append(s)
        else:
            newword.append(w)

    print(''.join(w for w in newword))



# Example run
# Input:
0Gg
# Output:
0Gg
while True:
    try:
        string = input()
    except:
        break
    ans = ""
    i = 0
    while i < len(string):
        if string[i] == "@":
            ans += int(string[i+1])*string[i+2]
            i += 3
        else:
            ans += string[i]
            i += 1
    print(ans)

# Example run
# Input:
oau}Q!*
# Output:
oau}Q!*
while True:
    try:
        s_inp = input()
        s_out = ""
        flag = 0
        for c in s_inp:
            if flag == 1:
                n = int(c)
                flag = 2
            elif flag == 2:
                for i in range(n):
                    s_out = s_out + c
                flag = 0
            elif c == "@":
                flag = 1
            else:
                s_out = s_out + c
        print(s_out)
    except:
        break



# Example run
# Input:
(b.S43br
# Output:
(b.S43br
while 1:
    try:
        s=list(input())
        ans=""
        while len(s)>0:
            i=s.pop(0)
            if i=="@":
                c=s.pop(0)
                l=s.pop(0)
                ans+=l*int(c)
            else:ans+=i
        print(ans)
    except:break


# Example run
# Input:
g\?CWE
# Output:
g\?CWE
import copy
n = int(input())
a = [int(i) for i in input().split()]
b=a.copy()
s0p = a[0]
s0n = b[0]
countp = 0
countn = 0

if a.count(0)==n:
  print(2*n-1)
  exit()

if s0p<=0:
  s0p+=(abs(a[0])+1)
  countp+=(abs(a[0])+1)
  
if s0n>=0:
  s0n-=(abs(b[0])+1)
  countn+=(abs(b[0])+1)

for i in range(1,n):
  s1 = s0p+a[i]
  if s0p*s1>=0:
    if s1>0:
      a[i]-=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1<0:
      a[i]+=(abs(s1)+1)
      countp+=(abs(s1)+1)
    elif s1==0:
      if s0p>0:
        a[i]-=1
        countp+=1
      elif s0p<0:
        a[i]+=1
        countp+=1
  s0p += a[i]

for i in range(1,n):
  s1 = s0n+b[i]
  if s0n*s1>=0:
    if s1>0:
      b[i]-=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1<0:
      b[i]+=(abs(s1)+1)
      countn+=(abs(s1)+1)
    elif s1==0:
      if s0n>0:
        b[i]-=1
        countn+=1
      elif s0n<0:
        b[i]+=1
        countn+=1
  s0n += b[i]
  
print(countp if countp<=countn else(countn))







# Example run
# Input:
-1378702
83957
# Output:
0
n = int(input())
a = list(map(int, input().split()))
L = [0 for _ in range(n)]
L[0] = a[0]
for i in range(1, n):
  L[i] = L[i-1] + a[i]
delay = 0
all_over = 0
if a[0] != 0:
  sign = (a[0] > 0) - (a[0] < 0)
  for i in range(1, n):
    L[i] += delay
    if L[i] <= 0 and sign == -1:
      delay += 1 - L[i]
      all_over += 1 - L[i]
      L[i] = 1
    elif L[i] >= 0 and sign == 1:
      delay -= L[i] + 1
      all_over += L[i] + 1
      L[i] = -1
    sign *= -1
  print(all_over)
else:
  posL = L[:]
  negL = L[:]
  pos_delay, neg_delay = 1, -1
  pos_all_over, neg_all_over = 1, 1
  sign = 1
  for i in range(1, n):
    posL[i] += pos_delay
    if posL[i] <= 0 and sign == -1:
      pos_delay += 1 - posL[i]
      pos_all_over += 1 - posL[i]
      posL[i] = 1
    elif posL[i] >= 0 and sign == 1:
      pos_delay -= posL[i] + 1
      pos_all_over += posL[i] + 1
      posL[i] = -1
    sign *= -1
  sign = -1
  for i in range(1, n):
    negL[i] += neg_delay
    if negL[i] <= 0 and sign == -1:
      neg_delay += 1 - negL[i]
      neg_all_over += 1 - negL[i]
      negL[i] = 1
    elif negL[i] >= 0 and sign == 1:
      neg_delay -= negL[i] + 1
      neg_all_over += negL[i] + 1
      negL[i] = -1
    sign *= -1
  print(pos_all_over, min(pos_all_over, neg_all_over))

# Example run
# Input:
1
-384972616
# 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
			count1 += abs(temp - a[i])
		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
	count1 = 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:
		count2 += abs(sum - a[i]) + 1
		if sum > 0:
			temp = -1 * abs(sum) - 1
			count2 += abs(temp - a[i])
		else:
			temp = abs(sum) + 1
			count2 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


# Example run
# Input:
-264371717
10366
# Output:
0
n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]


def check(a):
  sum = 0
  for i in range(len(a)):
    if(i == 0):
      if(a[i] == 0):
        return (i, +1)
      sum += a[0]
      continue
    if(sum > 0):
      sum += a[i]
      if(a[i] == 0 or sum >= 0):
        return (i, -1)

    elif(sum < 0):
      sum += a[i]
      if(a[i] == 0 or sum <= 0):
        return (i, +1)
    else:
      if(a[i-1] > 0):
        return (i, -1)
      else:
        return (i, +1)



  return True

ans = 0
while(True):
  c = check(a)
  if(c == True):
    break

  a[c[0]] += c[1]

  ans += 1



print(ans)

# Example run
# Input:
w]}[^h=
165350
# Output:
0
n = int(input().strip())
A = list(map(int, input().strip().split(" ")))

def solver(_sign):
    s = A[0]
    count = 0

    if _sign and s <= 0: # head is positive
        count += abs(s) + 1
        s = 1
    elif s >= 0: # head is negative
        count += abs(s) + 1
        s = -1

    for a in A[1:]:
        prev = s
        sign = prev > 0
        s += a
        if s == 0:
            count += 1
            if sign: # previous is positive
                s = -1
            else: # prev is negative
                s = 1
        elif sign == (s > 0): # previous and current have the same sign
            count += abs(s)+1
            if s > 0:
                s = -1
            else:
                s = 1
        else:
            pass

    return count

print(min(solver(True), solver(False)))


# Example run
# Input:
12272427
22140
# Output:
22141
N=int(input())
A=[int(i) for i in input().split()]
S1,S2=[],[]
if A[0]>0:
  S1.append(A[0])
  S2.append(-1)
  a1,a2=0,A[0]+1
elif A[0]==0:
  S1.append(1)
  S2.append(-1)
  a1,a2=1,1
else:
  S1.append(1)
  S2.append(A[0])
  a1,a2=-A[0]+1,0
for i in range(1,N):
  if S1[i-1]>0:
    if S1[i-1]+A[i]<0:
      S1.append(S1[i-1]+A[i])
    elif S1[i-1]+A[i]>=0:
      S1.append(-1)
      a1+=S1[i-1]+A[i]+1
  elif S1[i-1]<0:
    if S1[i-1]+A[i]>0:
      S1.append(S1[i-1]+A[i])
    elif S1[i-1]+A[i]<=0:
      S1.append(1)
      a1+=-S1[i-1]-A[i]+1
  if S2[i-1]>0:
    if S2[i-1]+A[i]<0:
      S2.append(S2[i-1]+A[i])
    elif S2[i-1]+A[i]>=0:
      S2.append(-1)
      a2+=S2[i-1]+A[i]+1
  elif S2[i-1]<0:
    if S2[i-1]+A[i]>0:
      S2.append(S2[i-1]+A[i])
    elif S2[i-1]+A[i]<=0:
      S2.append(1)
      a2+=-S2[i-1]-A[i]+1
print(min(a1,a2))

# Example run
# Input:
-1817683
-11385106
# Output:
0
def solve(asum, a, ans):
    for i in range(1, n):
        # print(asum)
        asumplus = asum + a[i]
        if asumplus == 0 and asum > 0:
            asumplus -= 1
            ans += 1
        elif asumplus == 0 and asum < 0:
            asumplus -= 1
            ans += 1
        elif asumplus > 0 and asum > 0:
            ans += asumplus + 1
            asumplus = -1
        elif asumplus < 0 and asum < 0:
            ans += -asumplus + 1
            asumplus = 1
        asum = asumplus
    return ans

n = int(input())
a = list(map(int,input().split()))
asum = a[0]
if asum > 0:
    ans = min(solve(asum,a,0),solve(-1,a,asum+1))
elif asum < 0:
    ans = min(solve(asum,a,0),solve(1,a,1-asum))
else:
    ans = min(solve(1,a,1),solve(-1,a,1))
print(ans)


# Example run
# Input:
-32152
1612446667
# Output:
0
n = int(input())
a = input().split()
a = [int(m) for m in a]
q = []
k = 0
kco = 0
#+-
for i in range(n):
    if i == 0:
        if a[i] > 0:
            q.append(a[i])
        else:
            q.append(1)
            kco += 1 - a[i]
        k += q[i]
    else:
        k += a[i]
        if i % 2 != 0:
            if k < 0:
                q.append(a[i])
            else:
                q.append(a[i]-k-1)
                kco += k + 1
            k += q[i] - a[i]
        if i % 2 == 0:
            if k > 0:
                q.append(a[i])
            else:
                q.append(a[i]-k+1)
                kco += -k + 1
            k += q[i] - a[i]
xco = kco
q = []
k = 0
kco = 0
#-+
for i in range(n):
    if i == 0:
        if a[i] < 0:
            q.append(a[i])
        else:
            q.append(1)
            kco += 1 - a[i]
        k += q[i]
    else:
        k += a[i]
        if i % 2 == 0:
            if k < 0:
                q.append(a[i])
            else:
                q.append(a[i]-k-1)
                kco += k + 1
            k += q[i] - a[i]
        if i % 2 != 0:
            if k > 0:
                q.append(a[i])
            else:
                q.append(a[i]-k+1)
                kco += -k + 1
            k += q[i] - a[i]
yco = kco
print(min(xco, yco))

# Example run
# Input:
-80
-7517
# Output:
0
def psolve(positive, As):
    i = 0
    ans = 0
    for a in As:
        if positive:
            if i + a <= 0:
                ans += abs(1 - (i + a))
                a += 1 - (i + a)
        else:
            if i + a >= 0:
                ans += abs(-1 - (i + a))
                a += -1 - (i + a)
        i += a
        positive = not positive
    return ans


def solve(N, As):
    return min(psolve(True, As), psolve(False, As))


if __name__ == "__main__":
    n = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(n, As))


# Example run
# Input:
-7581
25265073
# Output:
0
N = int(input())
A = [int(i) for i in input().split()]

mi = 1e20
for sign in [-1, 1]:
    res, acc = 0, 0
    for a in A:
        acc += a
        if sign * acc <= 0:
            res += abs(acc - sign)
            acc = sign
        sign *= -1
    mi = min(mi, res)

print(mi)

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


def cost(t):
    res = 0
    sum = 0
    for y in s:
        sum += y
        if sum * t <= 0:
            res += abs(sum - t)
            sum = t
        t *= -1
    return res


print(min(cost(1), cost(-1)))


# Example run
# Input:
-246934
-2
# Output:
0
N = int(input())
nums = list(map(int, input().split()))
ans = 10**14
for start in [-1, 1]:
  before = start
  cnt = 0
  sum_n = 0
  for num in nums:
    sum_n += num
    if before*sum_n >= 0:
      if before < 0:
        cnt += abs(1-sum_n)
        sum_n = 1
      else:
        cnt += abs(-1-sum_n)
        sum_n = -1
    before = sum_n
  ans = min(ans, cnt)
print(ans)

# Example run
# Input:
-123410341
9062461
# Output:
0
n = int(input())
a = [int(_) for _ in input().split()]
even_p = 0
even_n = 0
odd_p = 0
odd_n = 0
for i in range(n):
    if i % 2 == 0:
        if a[i] > 0:
            odd_p += 1
        elif a[i] < 0:
            odd_n += 1
    else:
        if a[i] > 0:
            even_p += 1
        elif a[i] < 0:
            even_n += 1
cnt = 0
if odd_p > even_p:
    if a[0] > 0:
        sum_i = a[0]
    else:
        cnt += abs(a[0]-1)
        sum_i = 1
else:
    if a[0] < 0:
        sum_i = a[0]
    else:
        cnt += abs(a[0] + 1)
        sum_i = -1
for i in range(1, n):
    if sum_i > 0:
        if sum_i + a[i] < 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i+1)
            sum_i = -1
    elif sum_i < 0:
        if sum_i + a[i] > 0:
            sum_i += a[i]
        else:
            cnt += abs(a[i]+sum_i-1)
            sum_i = 1
print(cnt)

# Example run
# Input:
-398
986892
# Output:
986893
N = int(input())
a = [int(i) for i in input().split()]

def pura(A):
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += abs(1-A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 + check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 + check))
                A[i] = 1 - check
        check += A[i]
        print(ans)
    return ans

print(pura(a))

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

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

# Example run
# Input:
4EPy8r+|E
51856
# Output:
0
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                index = -1
                for j in range(n):
                    if A[j] != 0:
                        index = A.index(A[j])
                        break
                
                if index == -1:
                    sums[i] = 1
                    res += 1
                elif (index % 2 and A[index] > 0) or (index % 2 == 0 and A[index] < 0):
                    sums[i] = -1
                    res += 1
                else:
                    sums[i] = 1
                    res += 1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    A[i] -= 1
                    sums[i] = -1
                    res += 1
                else:
                    A[i] += 1
                    sums[i] = 1
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += 1 - (sums[i])
                sums[i] = 1
    
    print(res)


if __name__ == '__main__':
    main()

# Example run
# Input:
-816653
-7191
# Output:
0