s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s130643570
p03739
u893132811
1556298938
Python
Python (3.4.3)
py
Runtime Error
151
14468
701
n = int(input()) A = list(map(int, input().split())) ans1 = 0 sum = A[0] for a in A[1:]: if (sum + a) * sum < 0: sum += a else: fugo = sum // abs(sum) nextsum = - fugo a_should_be = nextsum - sum dif = abs(a_should_be - a) sum += a_should_be ans1 += dif print(ans1) ans2 = A[0] + 1 sum = - (A[0] // abs(A[0])) for a in A[1:]: if (sum + a) * sum < 0: sum += a else: fugo = sum // abs(sum) nextsum = - fugo a_should_be = nextsum - sum dif = abs(a_should_be - a) sum += a_should_be ans2 += dif print(ans2) #A[0]を反転したほうがいいパターンの処理
s064217281
p03739
u893132811
1556298528
Python
Python (3.4.3)
py
Runtime Error
99
14332
328
n = int(input()) A = list(map(int, input().split())) ans = 0 sum = A[0] for a in A[1:]: if (sum + a) * sum < 0: sum += a else: fugo = sum // abs(sum) nextsum = - fugo a_should_be = nextsum - sum dif = abs(a_should_be - a) sum += a_should_be ans += dif print(ans)
s914327220
p03739
u501643136
1554945768
Python
Python (3.4.3)
py
Runtime Error
27
11516
415
n = int(input()) A = [map(int,input().split())] acm1 = 0 acm2 = 0 ans1 = 0 ans2 = 0 for i, a in enumerate(A): acm1 += a acm2 += a if(i%2==1): if(acm1>=0): ans1 += acm1 + 1 acm1 = -1 if(acm2<=0): ans2 += -acm2 + 1 acm2 = 1 else: if(acm1<=0): ans1 += -acm1 + 1 acm1 = 1 if(acm2>=0): ans2 += acm2 + 1 acm2 = -1 print(min(ans1, ans2))
s749542591
p03739
u227082700
1554840084
Python
Python (3.4.3)
py
Runtime Error
17
2940
213
n=int(input()) A=list(map(int,input().split())) ans=10**15 for i in[-1,1]: ansi,sum=0,0 for a in A: sum+=a if sum*i<=0:;ansi+=abs(sum-i);sum=i i*=-1 ans=min(ans,ansi) print(ans)
s295169193
p03739
u210827208
1554827909
Python
Python (3.4.3)
py
Runtime Error
76
14468
485
n=int(input()) X=list(map(int,input().split())) res=X[0] cnt=0 if X[0]==0: cnt=1 res=1 for i in range(1,n): if X[i]>0: tmp=i cnt+=2*(i-1) res=-1 elif X[i]<0: tmp=i cnt+=2*(i-1) res=1 for i in range(tmp,n): res+=X[i] if res>=0 and res-X[i]>0: cnt+=(1+res) res=-1 elif res<=0 and res-X[i]<0: cnt+=(1-res) res=1 print(cnt)
s537653860
p03739
u013408661
1554314722
Python
Python (3.4.3)
py
Runtime Error
45
14468
448
n=int(input()) p=list(map(int,input().split())) stack=[0]*(n+1) ans=0 if p[0]==0: p[0]=1 ans+=1 stack[1]=1 else: stack[1]=p[0] for i in range(1,n): if i%2==1: if p[i]+p[i-1]+stack[i-1]>=0: p[i]-=(p[i]+p[i-1]+stack[i-1])+1 ans+=(p[i]+p[i-1]+stack[i-1])+1 else: if p[i]+p[i-1]+stack[i-1]<=0: p[i]+=-(p[i]+p[i-1]+stack[i-1])+1 ans+=-(p[i]+p[i-1]+stack[i-1])+1 stack=p[i]+p[i-1]+stack[i-1] print(ans)
s386000990
p03739
u536377809
1554096740
Python
Python (3.4.3)
py
Runtime Error
2104
15160
528
import copy N=int(input()) l=list(map(int, input().split())) #リスト入力 cp = copy.copy(l) #c=0 for k in range(1,N): if sum(l[:k])==0: #c=c+1 if l[k]>0: l[k]=l[k]+1 else: l[k]=l[k]-1 if sum(l[:k])*sum(l[:k+1])>0: if sum(l[:k+1])>0: l[k]=l[k]-(sum(l[:k+1])-(-1)) #c=c+abs(sum(l[:k+1])-(-1)) else: l[k]=l[k]+(1-sum(l[:k+1])) #c=c+abs(1-sum(l[:k+1])) if sum(l)==0: c=c+1 l[-1]=l[-1]+1 #print(l) print(sum([abs(l[n]-cp[n]) for n in range(N)]))
s567314346
p03739
u536377809
1554096323
Python
Python (3.4.3)
py
Runtime Error
2104
15160
526
import copy N=int(input()) l=list(map(int, input().split())) #リスト入力 cp = copy.copy(l) #c=0 for k in range(N-1): if sum(l[:k+1])==0: #c=c+1 if l[k+1]>0: l[k+1]=l[k+1]+1 else: l[k+1]=l[k+1]-1 if sum(l[:k])*sum(l[:k+1])>0: if sum(l[:k+1])>0: l[k]=l[k]-(sum(l[:k+1])-(-1)) #c=c+abs(sum(l[:k+1])-(-1)) else: l[k]=l[k]+(1-sum(l[:k+1])) #c=c+abs(1-sum(l[:k+1])) if sum(l)==0: c=c+1 l[-1]=l[-1]+1 print(sum([abs(l[n]-cp[n]) for n in range(N)]))
s040910096
p03739
u536377809
1554096186
Python
Python (3.4.3)
py
Runtime Error
2104
15156
596
import copy N=int(input()) l=list(map(int, input().split())) #リスト入力 cp = copy.copy(l) #c=0 for k in range(N-1): if sum(l[:k+1])==0: #c=c+1 if l[k+1]>0: l[k+1]=l[k+1]+1 else: l[k+1]=l[k+1]-1 if sum(l[:k])*sum(l[:k+1])>0: print(k,sum(l[:k]),sum(l[:k+1]),l[k+1]) if sum(l[:k+1])>0: l[k]=l[k]-(sum(l[:k+1])-(-1)) #c=c+abs(sum(l[:k+1])-(-1)) else: l[k]=l[k]+(1-sum(l[:k+1])) #c=c+abs(1-sum(l[:k+1])) print(l[k]) if sum(l)==0: c=c+1 l[-1]=l[-1]+1 #print(l) #print(c) print(sum([abs(l[n]-cp[n]) for n in range(N)]))
s550987859
p03739
u151625340
1554050557
Python
Python (3.4.3)
py
Runtime Error
100
14332
297
n = int(input()) a = list(map(int,input().split())) s = 0 sign = a[0]//abs(a[0]) ans = 0 for i in range(n): s += a[i] if s == 0: s = sign ans += 1 elif s//abs(s) == sign: pass else: ans += abs(sign-s) s = sign sign *= -1 print(ans)
s561200151
p03739
u807772568
1552433079
Python
Python (3.4.3)
py
Runtime Error
107
14468
512
n = int(input()) a = list(map(int,input().split())) if a[0] != 0: b = [a[0]] else: su += 1 if b[1] > 0: b = [-1] else: b = [1] su = 0 for i in range(n-1): b.append(b[-1]+a[1+i]) if b[-1] * b[-2] > 0: su += abs(b[-1]) + 1 if b[-2] > 0: b[-1] = -1 else: b[-1] = 1 else: if b[-1] == 0: su += 1 if b[-2] > 0: b[-1] = -1 else: b[-1] = 1 print(su)
s745417899
p03739
u239981649
1549176471
Python
Python (3.4.3)
py
Runtime Error
294
14468
545
n = int(input()) *a, = map(int, input().split()) if a[0]: ans = 0 e0 = 1 if a[0] > 0 else -1 S = a[0] for i in range(1, n): e = e0 * int((i % 2-0.5)*2) n = max(e*(S+a[i])+1, 0) S += a[i]+(-e*n) ans += n print(ans) else: ans = [0, 0] for e0 in [1, -1]: a[0] = e0*1 S = a[0] for i in range(1, n): e = e0 * int((i % 2-0.5)*2) n = max(e*(S+a[i])+1, 0) S += a[i]+(-e*n) ans[int(e0/2+0.5)] += n print(min(ans))
s397029644
p03739
u189575640
1548111025
Python
Python (3.4.3)
py
Runtime Error
1333
142824
440
import sys n = int(input()) a = [int(n) for n in input().split()] sum = [0]*n sum[0] = a[0] ans = 0 for i in range(1,n): sum[i] = sum[i-1] while((sum[i]+a[i])*sum[i-1] >= 0): if(sum[i-1] > 0): ans+=sum[i-1] + a[i]+1 a[i]-=sum[i-1] + a[i]+1 else: ans+=1 - sum[i-1] - a[i] a[i]+=1 - sum[i-1] - a[i] print(a) sum[i] += a[i] print(ans) # print(a) # print(sum)
s635155765
p03739
u138486156
1544663531
Python
Python (3.4.3)
py
Runtime Error
2104
14332
834
n = int(input()) a = list(map(int, input().split())) not_0 = n for i in range(n): if a[i]: not_0 = i break if not_0 == n: print(1+2*(n-1)) exit() ans = 0 if not_0 == 0: b = [a[0]] else: if abs(a[not_0]) == 1: a[not_0] *= 2 ans = 2*not_0 else: ans = 1 + 2*(not_0-1) if a[not_0] > 0: b = [a[not_0] - 1] else: b = [a[not_0] + 1] tmp = b[0] for i in range(not_0+1, n): tmp += a[i] b.append(tmp) for i in range(not_0+1, n): if b[i-1]*b[i] < 0: continue else: if b[i-1] > 0: d = b[i] + 1 ans += d for j in range(i, n): b[j] -= d else: d = -b[i] + 1 ans += d for j in range(i, n): b[j] += d print(ans)
s755290655
p03739
u166696759
1541981905
Python
Python (3.4.3)
py
Runtime Error
2104
14468
486
n = int(input()) A = [item for item in list(map(int, input().split()))] S = [A[0]] for i in range(1, n): S.append(A[i]+S[i-1]) count = 0 if S[0] == 0: A[0] += 1 for item in S: item += 1 count += 1 #print(S) for i in range(1, n): #print(S[i-1], S[i]) if S[i] * S[i-1] >= 0: dif = -1 * (S[i-1]//abs(S[i-1])) - S[i] A[i] += dif for j in range(i,n): S[j] += dif count += abs(dif) #print(S) print(count)
s347168922
p03739
u404676457
1541371674
Python
Python (3.4.3)
py
Runtime Error
84
14376
591
def culc(a, sum, plus, ans): for i in range(1, n): plus = not(plus) sum += a[i] if plus: if sum <= 0: ans += abs(sum) + 1 sum = 1 else: if sum >= 0: ans += abs(sum) + 1 sum = -1 return ans n = int(input()) a = list(map(int, input().split())) plus = None if a[0] > 0: plus = True else: plus = False ans1 = culc(a, a[0], plus, 0) a[0] = a[0] // abs(a[0]) * -1 ans2 = abs(a[0]) + 1 ans2 = culc(a, a[0], not(plus), abs(a[0]) + 1) print(min(ans1, ans2))
s666598927
p03739
u404676457
1541371196
Python
Python (3.4.3)
py
Runtime Error
123
14468
738
n = int(input()) a = list(map(int, input().split())) sum = a[0] plus = None if a[0] > 0: plus = True else: plus = False ans1 = 0 for i in range(1, n): plus = not(plus) sum += a[i] if plus: if sum <= 0: ans1 += abs(sum) + 1 sum = 1 else: if sum >= 0: ans1 += abs(sum) + 1 sum = -1 sum = 0 a[0] = a[0] // abs(a[0]) * -1 if a[0] > 0: plus = True else: plus = False ans2 = abs(a[0]) + 1 for i in range(1, n): plus = not(plus) sum += a[i] if plus: if sum <= 0: ans2 += abs(sum) + 1 sum = 1 else: if sum >= 0: ans2 += abs(sum) + 1 sum = -1 print(min(ans1, ans2))
s194781410
p03739
u883048396
1540957506
Python
Python (3.4.3)
py
Runtime Error
17
3064
690
def 解() iN = int(input()) aA = [int(_) for _ in input().split()] iL = len(aA) iStart = 0 if sum(aA[0::2]) < sum(aA[2::2]): iStart = 1 iC = 0 aD = [0]*iL if 0 % 2 == iStart : if aA[0] < 0: aA[0] = 1 iC += -1 * aA[0] + 1 else: if 0 < aA[0] : aA[0] = -1 iC += aA[0] + 1 aD[0] = aA[0] for i in range(1,iL): aD[i] = aD[i-1]+aA[i] if i % 2 == iStart: if aD[i] <= 0: iC += -1*aD[i] +1 aD[i] = 1 else: if aD[i] >= 0: iC += aD[i] +1 aD[i] = -1 print(iC) 解()
s283612901
p03739
u853900545
1539389913
Python
Python (3.4.3)
py
Runtime Error
147
14468
400
n = int(input()) a = list(map(int,input().split())) cnt = 0 sum = [0]*n sum[0] = a[0] for i in range(1,n): sum[i] = sum[i-1]+a[i] if sum[i]*sum[i-1]<0: continue elif sum[i-1]*a[i]<0: cnt += abs(sum[i-1])-abs(a[i])+1 sum[i] = -1*(sum[i-1]//abs(sum[i-1])) else: cnt += abs(sum[i-1])+abs(a[i])+1 sum[i] = -1*(sum[i-1]//abs(sum[i-1])) print(cnt)
s147437373
p03739
u853900545
1539369017
Python
Python (3.4.3)
py
Runtime Error
139
14468
420
n = int(input()) a = list(map(int,input().split())) if n == 1: print(0) cnt = 0 sum = [0]*n sum[0] = a[0] for i in range(1,n): sum[i] = sum[i-1]+a[i] if sum[i]*sum[i-1]<0: continue elif sum[i-1]*a[i]<0: cnt += abs(sum[i-1])-abs(a[i])+1 sum[i] = -(sum[i-1]//abs(sum[i-1])) else: cnt += abs(sum[i-1])+abs(a[i])+1 sum[i] = -(sum[i-1]//abs(sum[i-1])) print(cnt)
s318462249
p03739
u853900545
1539363333
Python
Python (3.4.3)
py
Runtime Error
142
14468
395
n = int(input()) a = list(map(int,input().split())) cnt = 0 sum = [0]*n sum[0] = a[0] for i in range(1,n): sum[i] = sum[i-1]+a[i] if sum[i]*sum[i-1]<0: continue elif sum[i-1]*a[i]<0: cnt += abs(sum[i-1])-abs(a[i])+1 sum[i] = -(sum[i-1]//abs(sum[i-1])) else: cnt += abs(sum[i-1])+abs(a[i])+1 sum[i] = -(sum[i-1]//abs(sum[i-1])) print(cnt)
s110202102
p03739
u853900545
1539363251
Python
Python (3.4.3)
py
Runtime Error
147
14468
391
n = int(input()) a = list(map(int,input().split())) cnt = 0 sum = [0]*n sum[0] = a[0] for i in range(1,n): sum[i] = sum[i-1]+a[i] if sum[i]*sum[i-1]<0: continue elif sum[i-1]*a[i]<0: cnt += abs(sum[i-1])-abs(a[i])+1 sum[i] = -sum[i-1]//abs(sum[i-1]) else: cnt += abs(sum[i-1])+abs(a[i])+1 sum[i] = -sum[i-1]//abs(sum[i-1]) print(cnt)
s310033196
p03739
u853900545
1539362956
Python
Python (3.4.3)
py
Runtime Error
141
14468
389
n = int(input()) a = list(map(int,input().split())) cnt = 0 sum = [0]*n sum[0] = a[0] for i in range(1,n): sum[i] = sum[i-1]+a[i] if sum[i]*sum[i-1]<0: continue if sum[i-1]*a[i]<0: cnt += abs(sum[i-1])-abs(a[i])+1 sum[i] = -sum[i-1]//abs(sum[i-1]) else: cnt += abs(sum[i-1])+abs(a[i])+1 sum[i] = -sum[i-1]//abs(sum[i-1]) print(cnt)
s540204748
p03739
u099918199
1539142339
Python
Python (3.4.3)
py
Runtime Error
256
15108
843
n = int(input()) list_a = list(map(int,input().split())) i = 0 k = 0 count = 0 ans = list_a[0] if list_a[0] > 0: for i in range(1,n): ans += list_a[i] if ans / ((-1) ** i) <= 0: count += abs(ans - (-1) ** i) ans = (-1) ** i else: for i in range(1,n): ans += list_a[i] if ans / ((-1) ** (i+1)) <= 0: count += abs(ans - (-1) ** (i+1)) ans = (-1) ** (i+1) count1 = count count = 0 if list_a[0] <= 0: for i in range(1,n): ans += list_a[i] if ans / ((-1) ** i) <= 0: count += abs(ans - (-1) ** i) ans = (-1) ** i else: for i in range(1,n): ans += list_a[i] if ans / ((-1) ** (i+1)) <= 0: count += abs(ans - (-1) ** (i+1)) ans = (-1) ** (i+1) print(min(count1, count2))
s515461724
p03739
u201234972
1537920905
Python
Python (3.4.3)
py
Runtime Error
43
14332
272
N = int( input()) A = list( map( int, input().split())) ans = 10**15 for i in [1, -1]: ansi, sums = 0, 0 for a in A: sums += a if sums*i <= 0: ansi += abs(sums-s) sums = s s *= -1 ans = min( ans, ansi) print(ans)
s178550092
p03739
u201234972
1537920859
Python
Python (3.4.3)
py
Runtime Error
42
14332
272
N = int( input()) A = list( map( int, input().split())) ans = 10**15 for i in [1, -1]: ansi, sums = 0, 0 for a in A: sums += A if sums*i <= 0: ansi += abs(sums-s) sums = s s *= -1 ans = min( ans, ansi) print(ans)
s282015478
p03739
u201234972
1537920190
Python
Python (3.4.3)
py
Runtime Error
125
14332
1322
n = int( input()) A = list( map( int, input().split())) ansp = 0 sums = A[0] if sums == 0: ansp += 1 sums += 1 for i in range(1,n-1): sums += A[i] if i%2 == 1: if sums < 0: pass else: ansp += abs(-1-sums) sums = -1 else: if sums > 0: pass else: ansp += abs(1 - sums) sums = 1 if (n-1)%2 == 0: if A[n-1] > 0: sums += A[n-1] pass else: ansp += abs(1-A[n]) sums += 1 else: if A[n-1] < 0: sums += A[n-1] pass else: ansp += abs(-1-A[n-1]) sums -= 1 if sums == 0: ansp += 1 sums = A[0] ansm = 0 if sums == 0: ansm += 1 sums -= 1 for i in range(1,n-1): sums += A[i] if i%2 == 0: if sums < 0: pass else: ansm += abs(-1-sums) sums = -1 else: if sums > 0: pass else: ansm += abs(1 - sums) sums = 1 if (n-1)%2 == 1: if A[n-1] > 0: sums += A[n-1] pass else: ansm += abs(1-A[n-1]) sums += 1 else: if A[n-1] < 0: sums += A[n-1] pass else: ansm += abs(-1-A[n-1]) sums -= 1 if sums == 0: ansm += 1 print( min(ansp, ansm))
s130697564
p03739
u826263061
1536442364
Python
Python (3.4.3)
py
Runtime Error
239
14468
605
# -*- coding: utf-8 -*- """ Created on Sat Sep 8 15:51:53 2018 @author: maezawa """ def f(n, a0, cnt, sa, sign): a = a0[:] if sign == -1: cnt += abs(a[0])+1 a[0] = -a[0]/abs(a[0]) for i in range(n-1): sa += a[i] na = -sa//abs(sa)*(abs(sa)+1) if abs(a[i+1]) > abs(na) and a[i+1]*na > 0: continue else: cnt += abs(na-a[i+1]) a[i+1] = na return cnt n = int(input()) a = list(map(int, input().split())) sa = 0 cnt = 0 cnt0 = f(n, a, 0, 0, -1) cnt1 = f(n, a, 0, 0, 1) cnt = min([cnt0,cnt1]) print(cnt)
s971762533
p03739
u826263061
1536441253
Python
Python (3.4.3)
py
Runtime Error
183
14468
597
# -*- coding: utf-8 -*- """ Created on Sat Sep 8 15:51:53 2018 @author: maezawa """ def f(n, a0, cnt, sa, sign): a = a0[:] if sign == -1: a[0] = -a[0] cnt += 2*a[0] for i in range(n-1): sa += a[i] na = -sa//abs(sa)*(abs(sa)+1) if abs(a[i+1]) > abs(na) and a[i+1]*na > 0: continue else: cnt += abs(na-a[i+1]) a[i+1] = na return cnt n = int(input()) a = list(map(int, input().split())) sa = 0 cnt = 0 cnt0 = f(n, a, cnt, sa, -1) cnt1 = f(n, a, cnt, sa, 1) cnt = min([cnt0,cnt1]) print(cnt)
s545347517
p03739
u826263061
1536439190
Python
Python (3.4.3)
py
Runtime Error
149
14212
368
# -*- coding: utf-8 -*- """ Created on Sat Sep 8 15:51:53 2018 @author: maezawa """ n = int(input()) a = list(map(int, input().split())) sa = 0 cnt = 0 for i in range(0,n-1): sa += a[i] na = -sa//abs(sa)*(abs(sa)+1) if abs(a[i+1]) > abs(na) and a[i+1]*na > 0: continue else: cnt += abs(na-a[i+1]) a[i+1] = na print(cnt)
s044378831
p03739
u826263061
1536437727
Python
Python (3.4.3)
py
Runtime Error
144
14332
350
# -*- coding: utf-8 -*- """ Created on Sat Sep 8 15:51:53 2018 @author: maezawa """ n = int(input()) a = list(map(int, input().split())) sa = 0 cnt = 0 for i in range(0,n-1): sa += a[i] na = -sa//abs(sa)*(abs(sa)+1) if abs(a[i+1]) > abs(na) and a[i+1]*na > 0: continue cnt += abs(na-a[i+1]) a[i+1] = na print(cnt)
s983207983
p03739
u826263061
1536437536
Python
Python (3.4.3)
py
Runtime Error
148
14212
351
# -*- coding: utf-8 -*- """ Created on Sat Sep 8 15:51:53 2018 @author: maezawa """ n = int(input()) a = list(map(int, input().split())) sa = 0 cnt = 0 for i in range(0,n-1): sa += a[i] na = -sa//abs(sa)*(abs(sa)+1) if abs(a[i+1]) > abs(na) and a[i+1]*na >= 0: continue cnt += abs(na-a[i+1]) a[i+1] = na print(cnt)
s430608276
p03739
u820351940
1534056529
Python
Python (3.4.3)
py
Runtime Error
237
23248
618
import numpy as np input() a = list(map(int, input().split())) def calc(a): value = a[0] sign = value >= 0 result = 0 for i in a[1:]: value += i diff = 0 if sign and value >= 0: diff = value + 1 elif not sign and value < 0: diff = value - 1 result += abs(diff) sign = not sign value -= diff if value == 0: diff += sign value += diff result += diff return result r1 = calc(a[:]) diff = -a[0] - a[0] // abs(a[0]) a[0] += diff r2 = calc(a[:]) + abs(diff) print(min(r1, r2))
s314095558
p03739
u588341295
1532069003
Python
Python (3.4.3)
py
Runtime Error
81
14332
533
# -*- coding: utf-8 -*- N = int(input()) aN = list(map(int, input().split())) sum1 = aN[0] cnt = 0 if aN[0] > 0: sei = True elif aN[0] < 0: sei = False else: print("和が0なので、これはないはず") for i in range(1,N): sum1 += aN[i] if sei: if sum1 >= 0: tmp = abs(sum1) +1 cnt += tmp sum1 -= tmp sei = False else: if sum1 <= 0: tmp = abs(sum1) +1 cnt += tmp sum1 += tmp sei = True print(cnt)
s768115144
p03739
u004025573
1531682578
Python
Python (3.4.3)
py
Runtime Error
88
14332
275
n=int(input()) a=list(map(int,input().split())) now=a[0] flag=abs(a[0])//a[0] c=0 #print(c,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,flag) print(c)
s687680694
p03739
u140251125
1531274637
Python
Python (3.4.3)
py
Runtime Error
43
14468
547
# 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 + A_even[i]) * ((-1) ** (i - 1)) > 0: continue ans_even += S + A_even[i] + 1 A_even[i] = (-1) ** (i - 1) - S S = (-1) ** (i - 1) # 奇数番目が+ A_odd = A S_odd = 0 ans_odd = 0 for i in range(n): if (S + A_odd[i]) * ((-1) ** i) > 0: continue ans_odd += S + A_odd[i] + 1 A_odd[i] = (-1) ** i - S S = (-1) ** i ans = min(ans_even, ans_odd) print(ans)
s692878464
p03739
u006657459
1530847093
Python
Python (3.4.3)
py
Runtime Error
17
3064
567
import copy n = int(input()) a = [int(ai) for ai in input().split()] def search(a, flip=False): if flip: count = 0 a_sum = a[0] else: count = abs(a[0]) + 1 a_sum = - a[0] for ai in a[1:]: next_sum = a_sum + ai if next_sum * a_sum < 0: continue if a_sum < 0: a_sum = 1 elif a_sum > 0: a_sum = -1 else: c = 0 count += abs(next_sum) + 1 a_sum = next_sum + c return count print(min(search(a, False), search(a, True))
s577647580
p03739
u497625442
1530845828
Python
Python (3.4.3)
py
Runtime Error
17
3064
573
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 if a[0] = 0: a[0] = -1 cmin = find(a) a[0] = 1 cmax = find(a) c = min(cmin,cmax) else: c = find(a) print(c)
s296656060
p03739
u069838609
1524956867
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38256
1657
import numpy as np n = int(input()) a_array = np.array([int(elem) for elem in input().split(' ')]) def calculate_cumulative_sum(a_array, n): cumul_sum_array = np.zeros(n, dtype=np.int32) cumul_sum_array[0] = a_array[0] for i in range(1, n): cumul_sum_array[i] = cumul_sum_array[i - 1] + a_array[i] return cumul_sum_array def check_1(cumul_sum_array): result = (cumul_sum_array != 0).all() return result def check_2(cumul_sum_array): odd = np.sign(cumul_sum[::2]) even = np.sign(cumul_sum[1::2]) odd_sign = np.unique(odd) even_sign = np.unique(even) return (len(odd_sign) == 1) * (len(even_sign) == 1) * (odd_sign[0] != even_sign[0]) cumul_sum = calculate_cumulative_sum(a_array, n) count = {'plus': 0, 'minus': 0} def calc_num_manipulation(cumul_sum, start, n): cumul_sum = cumul_sum.copy() count = 0 if check_1(cumul_sum) and check_2(cumul_sum): return count for i in range(n): if i == 0: diff = cumul_sum[i] - start count += abs(diff) cumul_sum[i:] -= diff else: if cumul_sum[i - 1] < 0 and cumul_sum[i] <= 0: diff = cumul_sum[i] - 1 count += abs(diff) cumul_sum[i:] -= diff elif cumul_sum[i - 1] > 0 and cumul_sum[i] >= 0: diff = cumul_sum[i] - (-1) count += abs(diff) cumul_sum[i:] -= diff else: continue return count count['plus'] = calc_num_manipulation(cumul_sum, 1, n) count['minus'] = calc_num_manipulation(cumul_sum, -1, n) print(min(count.values()))
s542390511
p03739
u069838609
1524956772
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38640
1727
import numpy as np n = int(input()) a_array = np.array([int(elem) for elem in input().split(' ')]) def calculate_cumulative_sum(a_array, n): cumul_sum_array = np.zeros(n, dtype=np.int32) cumul_sum_array[0] = a_array[0] for i in range(1, n): cumul_sum_array[i] = cumul_sum_array[i - 1] + a_array[i] return cumul_sum_array def check_1(cumul_sum_array): result = (cumul_sum_array != 0).all() return result def check_2(cumul_sum_array): odd = np.sign(cumul_sum[::2]) even = np.sign(cumul_sum[1::2]) odd_sign = np.unique(odd) even_sign = np.unique(even) return (len(odd_sign) == 1) * (len(even_sign) == 1) * (odd_sign[0] != even_sign[0]) cumul_sum = calculate_cumulative_sum(a_array, n) count = {'plus': 0, 'minus': 0} def calc_num_manipulation(cumul_sum, start, n): cumul_sum = cumul_sum.copy() count = 0 for i in range(n): if check_1(cumul_sum) and check_2(cumul_sum): break else: if i == 0: diff = cumul_sum[i] - start count += abs(diff) cumul_sum[i:] -= diff else: if cumul_sum[i - 1] < 0 and cumul_sum[i] <= 0: diff = cumul_sum[i] - 1 count += abs(diff) cumul_sum[i:] -= diff elif cumul_sum[i - 1] > 0 and cumul_sum[i] >= 0: diff = cumul_sum[i] - (-1) count += abs(diff) cumul_sum[i:] -= diff else: continue return count count['plus'] = calc_num_manipulation(cumul_sum, 1, n) count['minus'] = calc_num_manipulation(cumul_sum, -1, n) print(min(count.values()))
s898635278
p03739
u503901534
1524792284
Python
Python (3.4.3)
py
Runtime Error
2104
14468
716
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 sums + 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))
s144630261
p03739
u503901534
1524792238
Python
Python (3.4.3)
py
Runtime Error
2104
14468
714
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 sums + 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 sumscp + b[i] > -1: b[i] = b[i] - 1 cm = cm + 1 sumscm = sumscm + b[i] else: while sums + a[i] < 1: b[i] = b[i] + 1 cm = cm + 1 sumscm = sumscm + b[i] print(min(cp,cm))
s249201666
p03739
u050428930
1524391990
Python
Python (3.4.3)
py
Runtime Error
97
14468
520
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)
s901568585
p03739
u417835834
1523240732
Python
Python (3.4.3)
py
Runtime Error
43
14468
887
n = int(input()) a_p = list(map(int,input().split())) a_n = a_p #positive if a[0] <= 0: counter_p = 0 for i in range(n): print(a_p,counter_p) sum_ai = sum(a_p[:i+1]) if i % 2 == 0: if sum_ai <= 0: a_p[i] += -sum_ai + 1 counter_p += -sum_ai + 1 else: if sum_ai >= 0: a_p[i] += -sum_ai - 1 counter_p += sum_ai + 1 print(counter_p) else: #negative counter_n = 0 for i in range(n): print(a_n,counter_n) sum_ai = sum(a_n[:i+1]) if i % 2 == 1: if sum_ai <= 0: a_n[i] += -sum_ai + 1 counter_n += -sum_ai + 1 else: if sum_ai >= 0: a_n[i] += -sum_ai - 1 counter_n += sum_ai + 1 print(counter_n) print(min(counter_n,counter_p))
s279101834
p03739
u813450984
1522656534
Python
Python (3.4.3)
py
Runtime Error
17
3060
196
n, x = map(int, input().split()) l = list(map(int, input().split())) ans = 0 for i in range(1, n): if l[i] + l[i-1] > x: ans += (l[i] + l[i-1]) - x l[i] -= (l[i] + l[i-1]) - x print(ans)
s179609052
p03739
u773981351
1522300025
Python
Python (3.4.3)
py
Runtime Error
111
14464
594
def ops_needed(x, target): if abs(target - x) < abs(x): return 0 else: return target - x def count_ops(a): total_ops = 0 accum = a[0] for i in range(1, len(a)): new_accum = accum + a[i] if new_accum == 0: ops = -1 * (accum / abs(accum)) else: ops = ops_needed(new_accum, -1 * (accum / abs(accum))) total_ops += abs(ops) accum = new_accum + ops return int(total_ops) if __name__ == '__main__': _ = int(input()) a = list(map(int, input().split())) print(count_ops(a))
s110603747
p03739
u773981351
1522299040
Python
Python (3.4.3)
py
Runtime Error
46
14468
798
def count_ops(a): if a[0] == 0: total_ops = 1 if a[1] < 0: accum = 1 else: accum = -1 else: total_ops = 0 accum = a[0] for i in range(1, len(a)): new_accum = accum + a[i] if (accum > 0 and new_accum > 0): ops = ops_needed(new_accum, -1) elif (accum > 0 and new_accum == 0): ops = -1 elif (accum < 0 and new_accum < 0): ops = ops_needed(new_accum, 1) elif (accum < 0 and new_accum == 0): ops = 1 else: ops = 0 total_ops += abs(ops) accum = new_accum + ops return total_ops if __name__ == '__main__': _ = int(input()) a = list(map(int, input().split())) print(count_ops(a))
s444596699
p03739
u729707098
1521697810
Python
Python (3.4.3)
py
Runtime Error
99
14332
218
n = int(input()) a = [int(i) for i in input().split()] num,answer = a[0],0 for i in range(1,n): if num*(num+a[i]) >= 0: x = (-num)//abs(num) answer += abs((x-num)-a[i]) num = x else: num += a[i] print(answer)
s468614554
p03739
u382765539
1508307369
Python
Python (3.4.3)
py
Runtime Error
18
2940
586
#include<bits/stdc++.h> using namespace std; int main(void){ int n; cin >> n; vector<int> a(n); for(auto& it : a) cin >> it; int total = a[0]; int ans = 0; for(int i=1;i<n;i++){ if(total > 0){ if(total + a[i] >= 0) { ans += abs(-total-1 - a[i]); a[i] = -total-1; } } else { if(total + a[i] <= 0) { ans += abs(-total+1 - a[i]); a[i] = -total+1; } } total += a[i]; } cout << ans << endl; return 0; }
s483311403
p03739
u343437894
1499489248
Python
Python (3.4.3)
py
Runtime Error
17
2940
381
n = int(input()) as = list(map(int, input().split(" "))) ope = 0 for i in range(0, n-1): sum_be=sum(as[:i]) sum_af=sum(as[:i+1]) if sum_be<0<sum_af or sum_af<0<sum_be: continue elif sum_be > 0: ope += as[i+1] + (sum_be+1) as[i+1] = sum_be + 1 elif sum_be < 0: ope += 1 - sum_be - sum_af as[i+1] = 1 - sum_be print(ope)
s583979684
p03739
u004797437
1495293792
Python
Python (3.4.3)
py
Runtime Error
2105
17812
581
n = int(input()) a_list = [int(i) for i in input().split(' ')] total = [a_list[0]] counter = 0 for a in a_list[1:]: total.append(total[-1] + a) if total[0]==0: total = map(lambda n: n-int(total[1]/abs(total[1])), total) for i in range(1,n): if total[i-1]<0 and total[i]<=0: counter += abs(total[i])+1 total[i:] = list(map(lambda n: n-(total[i])+1, total[i:])) elif total[i-1]>0 and total[i]>=0: counter += abs(total[i])+1 total[i:] = list(map(lambda n: n-(total[i])-1, total[i:])) else: continue print(counter)
s216682401
p03739
u667084803
1493275096
Python
Python (3.4.3)
py
Runtime Error
166
14084
833
import sys # -*- coding: utf-8 -*- # 整数の入力 n=int(input()) a=list(map(int, input().split())) b=a[:] c=a[:] # 無変更チェック if a[0]!=0: S=int(a[0]) for i in range(1,n): if S<0 and S+a[i]<=0: break elif S>0 and S+a[i]>=0: break S+=a[i] if i==n-1: print(0) sys.exit() # a[0]を1に変えた場合の計算 counter_2=abs(b[0]-1) b[0]=1 S=b[0] for i in range(1,n): if S<0 and S+b[i]<=0: counter_2+=-S-b[i]+1 b[i]=-S+1 elif S>0 and S+b[i]>=0: counter_2+=S+b[i]+1 b[i]=-S-1 S+=b[i] # a[0]を-1に変えた場合の計算 counter_3=abs(c[0]+1) c[0]=-1 S=c[0] for i in range(1,n): if S<0 and S+c[i]<=0: counter_3+=-S-c[i]+1 c[i]=-S+1 elif S>0 and S+c[i]>=0: counter_3+=S+c[i]+1 c[i]=-S-1 S+=c[i] print(min(counter_1,counter_2,counter_3))
s918834790
p03739
u021406692
1493239641
Python
Python (2.7.6)
py
Runtime Error
1794
142428
940
# -*- coding:utf-8 -*- def sign(x): if (x > 0): return 1 elif (x < 0): return -1 else: return 0 n = int(raw_input()) numlist = (raw_input()).split(' ') sumlist = [int(numlist[0])] count = 0 for i in range(1, n): sumlist.append(sumlist[i-1] + int(numlist[i])) while ((sign(sumlist[i-1]) == sign(sumlist[i])) or (sumlist[i] == 0)): if (sumlist[i] > 0): #i-1,i番目までのsumがともに正 numlist[i] = int(numlist[i]) - 1 sumlist[i] -= 1 count += 1 elif (sumlist[i] < 0): #i-1,i番目までのsumがともに負 numlist[i] = int(numlist[i]) + 1 sumlist[i] += 1 count += 1 else: if (sumlist[i-1] > 0): numlist[i] = int(numlist[i]) - 1 sumlist[i] -= 1 if (sumlist[i-1] < 0): numlist[i] = int(numlist[i]) + 1 sumlist[i] += 1 count += 1 print numlist print sumlist print count print numlist print sumlist
s781978778
p03739
u667084803
1493189253
Python
Python (3.4.3)
py
Runtime Error
27
11152
289
# -*- coding: utf-8 -*- # 整数の入力 n=int(input()) a=input().split() counter=0 S=a[0] # 出力 for i in range(1,n): S+=a[i] if S<0 and S+int(a[i])<=0: counter+=-S-int(a[i])+1 a[i]=-S+1 elif S>0 and S+int(a[i])>=0: counter+=S+int(a[i])+1 a[i]=-S-1 print(counter)
s105791154
p03739
u494209838
1492981638
Python
Python (3.4.3)
py
Runtime Error
47
14332
309
# -*- coding: utf-8 -*- n = input() a = [int(x) for x in input().split()] ans = 1e16 for s in (1, -1): res, cumsum = 0, 0 for j in range(n): cumsum += a[j] if cumsum * s <= 0: res += abs(cumsum-s) cumsum = s s *= -1 ans = min(ans, res) print(ans)
s842340794
p03739
u252228075
1492919191
Python
Python (3.4.3)
py
Runtime Error
17
3064
1300
n = int(input()) i = input() i = i.split() for item in range(len(i)): i[item] = int(i[item]) totn = 0 totp = 0 countp = 0 countn = 0 for x in range(len(i)): totp += i[x] totn += i[x] ''' if x == 0: if totp == 0: totn = -1 countn = 1 totp = 1 countp = 1 elif totp < 0: countp = abs(totp) + 1 totp = 1 elif totp > 0: countn = abs(totn) + 1 totn = -1 ''' if x %2 == 1: if totn == 0: countn += 1 totn = 1 elif totn < 0: countn += abs(totn) + 1 totn = 1 if totp == 0: countp += 1 totp = -1 elif totp > 0: countp += abs(totp) + 1 totp = -1 if x %2 == 0: if totn == 0: countn += 1 totn = -1 elif totn > 0: countn += abs(totn) + 1 totn = -1 if totp == 0: countp += 1 totp = 1 elif totp < 0: countp += abs(totp) + 1 totp = 1 '''print('totn', totn) print('countn', countn) print('totp', totp) print('countp', countp) ''' count = min(countn, countp) print(count)
s770763845
p03739
u252228075
1492919135
Python
Python (3.4.3)
py
Runtime Error
17
3064
1302
n = int(input()) i = input() i = i.split() for item in range(len(i)): i[item] = int(i[item]) totn = 0 totp = 0 countp = 0 countn = 0 for x in range(len(i)): totp += i[x] totn += i[x] ''' if x == 0: if totp == 0: totn = -1 countn = 1 totp = 1 countp = 1 elif totp < 0: countp = abs(totp) + 1 totp = 1 elif totp > 0: countn = abs(totn) + 1 totn = -1 ''' if x %2 == 1: if totn == 0: countn += 1 totn = 1 elif totn < 0: countn += abs(totn) + 1 totn = 1 if totp == 0: countp += 1 totp = -1 elif totp > 0: countp += abs(totp) + 1 totp = -1 elif x %2 == 0: if totn == 0: countn += 1 totn = -1 elif totn > 0: countn += abs(totn) + 1 totn = -1 if totp == 0: countp += 1 totp = 1 elif totp < 0: countp += abs(totp) + 1 totp = 1 '''print('totn', totn) print('countn', countn) print('totp', totp) print('countp', countp) ''' count = min(countn, countp) print(count)
s308353988
p03739
u024804656
1492916216
Python
Python (3.4.3)
py
Runtime Error
17
3064
659
n = int(input()) sa = input().split() a = [0 for i in range(n)] sumeven = 0 sumodd = 0 for i,sai in enumerate(sa): a[i] = int(sai) if i % 2 == 0: sumeven += a[i] else: sumodd += a[i] ret = 0 sm = 0 for i,ai in enumerate(a): if i % 2 == 1: ret += max(-sm+1-ai,0) sm += max(ai, -sm+1) else: ret += max(sm+1 + ai, 0) sm += min(ai, -(sm+1)) ret2 = 0 sm = 0 for i,ai in enumerate(a): if i % 2 == 0: ret2 += max(-sm+1-ai,0) sm += max(ai, -sm+1) else: ret2 += max(sm+1 + ai, 0) sm += min(ai, -(sm+1)) print(max(ret,ret2))
s356316247
p03739
u374514823
1492915692
Python
Python (3.4.3)
py
Runtime Error
45
14212
864
import itertools def sign(num): if num < 0: return -1 elif num > 0: return 1 else: return 0 N = input() a_i = list(map(int, input().split())) signs = [-1,1] a_sum = 0 changes_1 = 0 for i, a in enumerate(a_i): a_sum += a if sign(a_sum) != signs[i%2]: changes += abs(a_sum) + 1 a_sum = signs[i%2] signs = [1,-1] a_sum = 0 changes_2 = 0 for i, a in enumerate(a_i): a_sum += a if sign(a_sum) != signs[i%2]: changes += abs(a_sum) + 1 a_sum = signs[i%2] print(min(changes_1,changes_2)) # # for i, sum_i in enumerate(a_sum): # if i == 0: # signs = [sign(sum_i), -sign(sum_i)] # elif sign(sum_i) != signs[i%2]: # a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]] # changes += abs(sum_i) + 1 # # print(a_sum) # print(changes)
s833876932
p03739
u374514823
1492915466
Python
Python (3.4.3)
py
Runtime Error
17
3060
973
import itertools def sign(num): if num < 0: return -1 elif num > 0: return 1 else: return 0 N = input() a_i = list(map(int, input().split())) a_sum = [a_i[0]] for i, a in enumerate(a_i[1:]): i += 1 a_sum.append(a_sum[-1]+a) signs = [1, -1] for i, sum_i in enumerate(a_sum): if sum_i != 0 && i%2 == 0: signs = [sign(sum_i), -sign(sum_i)] break elif sum_i != 0 && i%2 == 1: signs = [-sign(sum_i), sign(sum_i)] break a_sum = 0 changes = 0 for i, a in enumerate(a_i): a_sum += a if sign(a_sum) != signs[i%2]: changes += abs(a_sum) + 1 a_sum = signs[i%2] print(changes) # # for i, sum_i in enumerate(a_sum): # if i == 0: # signs = [sign(sum_i), -sign(sum_i)] # elif sign(sum_i) != signs[i%2]: # a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]] # changes += abs(sum_i) + 1 # # print(a_sum) # print(changes)
s568567916
p03739
u374514823
1492915332
Python
Python (3.4.3)
py
Runtime Error
128
14212
895
import itertools def sign(num): if num < 0: return -1 elif num > 0: return 1 else: return 0 N = input() a_i = list(map(int, input().split())) a_sum = [a_i[0]] for i, a in enumerate(a_i[1:]): i += 1 a_sum.append(a_sum[-1]+a) signs = [1, -1] for i, sum_i in enumerate(a_sum): if sum_i != 0: signs[i%2] = sign(sum_i) signs[i%2+1] = -sign(sum_i) break a_sum = 0 changes = 0 for i, a in enumerate(a_i): a_sum += a if sign(a_sum) != signs[i%2]: changes += abs(a_sum) + 1 a_sum = signs[i%2] print(changes) # # for i, sum_i in enumerate(a_sum): # if i == 0: # signs = [sign(sum_i), -sign(sum_i)] # elif sign(sum_i) != signs[i%2]: # a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]] # changes += abs(sum_i) + 1 # # print(a_sum) # print(changes)
s874753815
p03739
u256260242
1492915304
Python
Python (3.4.3)
py
Runtime Error
28
11140
1427
n = int(input()) l = map(int, input().split()) ll = [] for q in range(len(l)): ll.append(l[q]) print(ll) sums1 = [0] * n count1 = 0 sums1[0] = ll[0] for i in range(1, len(ll)): sums1[i] = sums1[i-1] + ll[i] if l[0] == 0: for v in range(len(sums1)): sums1 += [1] * len(sums1) count1 += 1 for k in range(1, len(sums1)): while sums1[k] == 0 or sums1[k] * sums1[k-1] > 0: if sums1[k] == 0: for p in range(k, len(sums1)): sums1[p] += -(sums1[k-1]/abs(sums1[k-1])) count1 += 1 if sums1[k] * sums1[k-1] > 0: for p in range(k, len(sums1)): sums1[p] += (abs(sums1[k])+1) * (-(sums1[k])/abs(sums1[k])) count1 += abs(sums1[k])+1 sums2 = [0] * n count2 = 0 sums2[0] = ll[0] for i in range(1, len(ll)): sums2[i] = sums2[i-1] + ll[i] if l[0] == 0: for v in range(len(sums2)): sums2 -= [1] * len(sums2) count2 += 1 for k in range(1, len(sums2)): while sums2[k] == 0 or sums2[k] * sums2[k-1] > 0: if sums2[k] == 0: for p in range(k, len(sums2)): sums2[p] += -sums2[k-1]/abs(sums2[k-1]) count2 += 1 if sums2[k] * sums2[k-1] > 0: for p in range(k, len(sums1)): sums2[p] += -(abs(sums2[k])+1) * ((sums2[k])/abs(sums2[k])) count2 += abs(sums1[k])+1 print(min(count2, count2) * 2)
s218105616
p03739
u256260242
1492915205
Python
Python (3.4.3)
py
Runtime Error
27
11140
1431
n = int(input()) l = map(int, input().split()) ll = [] for q in range(len(l)): ll.append(l[q]) print(ll) sums1 = [0] * n count1 = 0 sums1[0] = ll[0] for i in range(1, len(ll)): sums1[i] = sums1[i-1] + ll[i] if l[0] == 0: for v in range(len(sums1)): sums1 += [1] * len(sums1) count1 += 1 for k in range(1, len(sums1)): while sums1[k] == 0 or sums1[k] * sums1[k-1] > 0: if sums1[k] == 0: for p in range(k, len(sums1)): sums1[p] += -(sums1[k-1]/abs(sums1[k-1])) count1 += 1 if sums1[k] * sums1[k-1] > 0: for p in range(k, len(sums1)): sums1[p] += (abs(sums1[k])+1) * (-(sums1[k])/abs(sums1[k])) count1 += abs(sums1[k])+1 sums2 = [0] * n count2 = 0 sums2[0] = ll[0] for i in range(1, len(ll)): sums2[i] = sums2[i-1] + ll[i] if l[0] == 0: for v in range(len(sums2)): sums2 -= [1] * len(sums2) count2 += 1 for k in range(1, len(sums2)): while sums2[k] == 0 or sums2[k] * sums2[k-1] > 0: if sums2[k] == 0: for p in range(k, len(sums2)): sums2[p] += -sums2[k-1]/abs(sums2[k-1]) count2 += 1 if sums2[k] * sums2[k-1] > 0: for p in range(k, len(sums1)): sums2[p] += -(abs(sums2[k])+1) * ((sums2[k])/abs(sums2[k])) count2 += abs(sums1[k])+1 print(min(count2, count2) * 2)
s074884225
p03739
u306773664
1492915188
Python
Python (3.4.3)
py
Runtime Error
2105
19244
982
N = int(input()) prog = list(map(int,input().split())) def seq(N,prog): result = [0]*N result[0] = prog[0] for i in range(N-1): result[i+1] = result[i] + prog[i+1] if result[0] == 0: if sum(result[0]+result[1]) >= 0: result[0] -= 1 x = [-1]*(N-1) result[1:] = [a+b for (a,b) in zip(x,result[1:])] else: result[0] += 1 x = [1]*(N-1) result[1:] = [a+b for (a,b) in zip(x,result[1:])] answer = 0 for i in range(N-1): y=0 if result[i] >= 0: if result[i+1] >0: y = (-1)*(result[i+1]+1) result[i+1] = -1 answer += abs(y) else: if result[i+1] <= 0: y = abs(result[i+1])+1 result[i+1] = 1 answer += abs(y) z = [y]*(N-i-1) result[(i+1):] = [a+b for (a,b) in zip(z,result[(i+1):])] print(answer) seq(N,prog)
s653256995
p03739
u256260242
1492915146
Python
Python (3.4.3)
py
Runtime Error
31
11140
1427
n = int(input()) l = map(int, input().split()) ll = [] for q in range(len(l)): ll.append(l[q]) print(ll) sums1 = [0] * n count1 = 0 sums1[0] = ll[0] for i in range(1, len(ll)): sums1[i] = sums1[i-1] + ll[i] if l[0] == 0: for v in range(len(sums1)): sums1 += [1] * len(sums1) count1 += 1 for k in range(1, len(sums1)): while sums1[k] == 0 or sums1[k] * sums1[k-1] > 0: if sums1[k] == 0: for p in range(k, len(sums1)): sums1[p] += -(sums1[k-1]/abs(sums1[k-1])) count1 += 1 if sums1[k] * sums1[k-1] > 0: for p in range(k, len(sums1)): sums1[p] += (abs(sums1[k])+1) * (-(sums1[k])/abs(sums1[k])) count1 += abs(sums1[k])+1 sums2 = [0] * n count2 = 0 sums2[0] = ll[0] for i in range(1, len(ll)): sums2[i] = sums2[i-1] + ll[i] if l[0] == 0: for v in range(len(sums2)): sums2 -= [1] * len(sums2) count2 += 1 for k in range(1, len(sums2)): while sums2[k] == 0 or sums2[k] * sums2[k-1] > 0: if sums2[k] == 0: for p in range(k, len(sums2)): sums2[p] += -sums2[k-1]/abs(sums2[k-1]) count2 += 1 if sums2[k] * sums2[k-1] > 0: for p in range(k, len(sums1)): sums2[p] += -(abs(sums2[k])+1) * ((sums2[k])/abs(sums2[k])) count2 += abs(sums1[k])+1 print(min(count2, count2))
s549782171
p03739
u768951609
1492914590
Python
Python (2.7.6)
py
Runtime Error
10
2568
657
n=int(raw_input()) a=map(int,raw_input().split(' ')) p_s=a[0] c=0 for i in range(1,n): s=p_s+a[i] if s==0: if i==n-1: a[i]+=1 c+=1 else: if a[i]>=0: a[i]+=1 c+=1 else: a[i]-=1 c+=1 s=p_s+a[i] if p_s*s>=0: if p_s>0: c+=abs(p_s*-1 - 1 - a[i]) a[i]=p_s*-1 - 1 else: c+=abs(p_s*-1 + 1 - a[i]) a[i]=p_s*-1 + 1 p_s=p_s+a[i] print c
s671577958
p03739
u706884679
1492914138
Python
Python (3.4.3)
py
Runtime Error
21
2940
818
n = int(input()) a = list(map(int, input().split())) c = 0 i = 1 k = 1 sum = a[0] while a[i] == 0: i += 1 if a[i] > 0: if i % 2 == 1: a[0] = 1 c = 1 else: a[0] = -1 c = 1 else: if i % 2 == 1: a[0] = -1 c = 1 else: a[0] = 1 c = 1 i = 1 if a[0] > 0: while i < n: if i == 2*k-1: sum = sum + a[2*k-1] if sum >= 0: c = c + sum + 1 sum = -1 else: pass i += 1 else: sum = sum + a[2*k] if sum <= 0: c = c - sum + 1 sum = 1 else: pass i += 1 k += 1 print(c) elif a[0] < 0: while i < n: if i == 2*k-1: sum = sum + a[2*k-1] if sum <= 0: c = c - sum + 1 sum = 1 else: pass i += 1 else: sum = sum + a[2*k] while sum >= 0: c = c + sum + 1 sum = -1 else: pass i += 1 k += 1 print(c)
s168665796
p03739
u374514823
1492913980
Python
Python (3.4.3)
py
Runtime Error
2105
19564
754
import itertools def sign(num): if num < 0: return -1 elif num > 0: return 1 else: return 0 N = input() a_i = list(map(int, input().split())) a_sum = [a_i[0]] for i, a in enumerate(a_i[1:]): i += 1 a_sum.append(a_sum[-1]+a) signs = [0, 0] changes = 0 for i, sum_i in enumerate(a_sum): if sum_i != 0: signs[i%2] = sign(sum_i) signs[i%2+1] = -sign(sum_i) break if signs == [0, 0]: signs = [1, -1] for i, sum_i in enumerate(a_sum): if i == 0: signs = [sign(sum_i), -sign(sum_i)] elif sign(sum_i) != signs[i%2]: a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]] changes += abs(sum_i) + 1 # print(a_sum) print(changes)
s046653556
p03740
u814419162
1601293305
Python
PyPy3 (7.3.0)
py
Runtime Error
86
74764
96
a,b=[int(x) for x in input().split()] if abs(a-b)<=1: print("Brown"): else: print("Alice")
s561169296
p03740
u814419162
1601293255
Python
PyPy3 (7.3.0)
py
Runtime Error
92
68656
96
a,b=[int(x) for x in input().split()] if abs(a-b)<=1: print("Brown): else: print("Alice")
s025791247
p03740
u612975321
1599090674
Python
Python (3.8.2)
py
Runtime Error
26
9004
95
x, y = = map(int,input().split()) if abs(x-y) < 1: print('Brown') else: print('Alice')
s831378099
p03740
u075595666
1595723770
Python
Python (3.8.2)
py
Runtime Error
25
9100
88
n,m = map(int(input().split())) if abs(n-m) < 2: print('Brown') else: print('Alice')
s466021731
p03740
u353797797
1579801466
Python
Python (3.4.3)
py
Runtime Error
1253
581860
1004
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): memo={} def win(a,b): if a>b:a,b=b,a if (a,b)==(0,0) or (a,b)==(0,1) or (a,b)==(1,1):return False if (a,b) in memo:return memo[a,b] for i in range(1,a): r=a-i*2 if r<0:break if not win(r,b+i): memo[a,b]=True return True for i in range(1,b): r=b-i*2 if r<0:break if not win(r,a+i): memo[a,b]=True return True memo[a, b] = False return False x,y=MI() if win(x,y):print("Alice") else:print("Brown") main()
s756889287
p03740
u863044225
1578362880
Python
Python (3.4.3)
py
Runtime Error
18
2940
82
x,y=map(int,input.split()) if abs(x-y)<=1: print('Blown') else: print('Alice')
s325741153
p03740
u329706129
1575940222
Python
Python (3.4.3)
py
Runtime Error
17
2940
73
x, y = input().split() print('Alice') if (x + y) > 1 else print('Brown')
s669088843
p03740
u038815010
1575136385
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38284
116
x, y = map(int, input().split()) if abs(x - y) <= 1: print('Brown') else: print('Alice')
s720192774
p03740
u143278390
1575070551
Python
Python (3.4.3)
py
Runtime Error
18
2940
90
x=int(input()) y=int(input()) if(abs(x-y)<=1): print('Brown') else: print('Alice')
s501485440
p03740
u886747123
1570347906
Python
PyPy3 (2.4.0)
py
Runtime Error
314
46576
1175
X, Y = map(int, input().split()) # 最終状態は(0,1), (1,1)のいずれか # 最終状態の1手前は勝ち確状態、その1手前は負け確状態 # 1手前に戻すには片方の山からi個石を取り、もう片方の山に2i個加える # 1手前に戻しつつ山の状態を列挙して、与えられた状態を探索する # ただし、石の個数の合計が与えられた石の個数の合計を超えたら探索を打ち切る # 山の状態を再帰的に探索する def recur_search(x,y,Alice_win_flg): if x+y > X+Y or x < 0 or y < 0: return elif [x, y] in done_memo and Alice_win_flg == 0: return elif [x,y] == [X,Y] or [x,y] == [Y,X]: # 1つでも勝ちパターンがあるなら先手Aliceの勝利 if Alice_win_flg == 1: print("Alice") exit() else: done_memo.append([x, y]) done_memo.append([y, x]) return else: for i in range(1, x+1): recur_search(x-i, y+2*i, 1^Alice_win_flg) recur_search(y+2*i, x-i, 1^Alice_win_flg) done_memo = [] recur_search(1,0,0) recur_search(1,1,0) print("Brown")
s866015331
p03740
u886747123
1570347688
Python
Python (3.4.3)
py
Runtime Error
86
3928
1175
X, Y = map(int, input().split()) # 最終状態は(0,1), (1,1)のいずれか # 最終状態の1手前は勝ち確状態、その1手前は負け確状態 # 1手前に戻すには片方の山からi個石を取り、もう片方の山に2i個加える # 1手前に戻しつつ山の状態を列挙して、与えられた状態を探索する # ただし、石の個数の合計が与えられた石の個数の合計を超えたら探索を打ち切る # 山の状態を再帰的に探索する def recur_search(x,y,Alice_win_flg): if x+y > X+Y or x < 0 or y < 0: return elif [x, y] in done_memo and Alice_win_flg == 0: return elif [x,y] == [X,Y] or [x,y] == [Y,X]: # 1つでも勝ちパターンがあるなら先手Aliceの勝利 if Alice_win_flg == 1: print("Alice") exit() else: done_memo.append([x, y]) done_memo.append([y, x]) return else: for i in range(1, x+1): recur_search(x-i, y+2*i, 1^Alice_win_flg) recur_search(y+2*i, x-i, 1^Alice_win_flg) done_memo = [] recur_search(1,0,0) recur_search(1,1,0) print("Brown")
s750773798
p03740
u886747123
1570346974
Python
Python (3.4.3)
py
Runtime Error
188
3928
1092
X, Y = map(int, input().split()) # 最終状態は(0,1), (1,1)のいずれか # 最終状態の1手前は勝ち確状態、その1手前は負け確状態 # 1手前に戻すには片方の山からi個石を取り、もう片方の山に2i個加える # 1手前に戻しつつ山の状態を列挙して、与えられた状態を探索する # ただし、石の個数の合計が与えられた石の個数の合計を超えたら探索を打ち切る # 山の状態を探索し、与えられた状態と一致したらフラグを保存する def recur_search(x,y,Alice_win_flg): if [x,y] == [X,Y] or [x,y] == [Y,X]: Alice_win_flg_list.append(Alice_win_flg) return elif x+y > X+Y or x < 0 or y < 0: return else: for i in range(1, x+1): recur_search(x-i, y+2*i, 1^Alice_win_flg) recur_search(y+2*i, x-i, 1^Alice_win_flg) Alice_win_flg_list = [] recur_search(1,0,0) recur_search(1,1,0) # 1つでもAlice勝ちパターンがあるなら先手のAliceの勝ち print("Alice" if sum(Alice_win_flg_list) > 0 else "Brown")
s118408638
p03740
u511965386
1565384398
Python
PyPy3 (2.4.0)
py
Runtime Error
312
47472
306
X, Y = map(int, input().split()) def rec(x, y) : flg = False for i in range(2, x + 1, 2) : flg = flg or not rec(x-i, y+i//2) for i in range(2, y + 1, 2) : flg = flg or not rec(x+i//2, y-i) return flg if rec(X, Y) : print('Alice') else : print('Brown')
s551366679
p03740
u595893956
1563835872
Python
Python (3.4.3)
py
Runtime Error
17
2940
63
a,b = map(int,input()) print("ABlriocwen"[not abs(a-b)>1 :: 2])
s825618179
p03740
u189575640
1551805951
Python
Python (3.4.3)
py
Runtime Error
77
4040
682
import sys AB = [int(n) for n in input().split()] # N = int(input()) # a = [int(input()) for _ in range(N)] # S = str(input()) # L = len(S) # T = str(input()) fin = [[0,0],[1,0],[0,1]] Alice = True memo = {} def Alicewin(state,Alice): if(state in fin and Alice): return False elif(state in fin and not Alice): return True Ap = 2 while(Ap<=state[0]): if Alicewin([state[0]-Ap,state[1]+Ap/2],not Alice): return True Ap+=2 Bp = 2 while(Bp<=state[1]): if Alicewin([state[0]+Bp/2,state[1]-Bp],not Alice): return True Bp+=2 return False print("Alice" if Alicewin(AB, True) else "Brown")
s569444222
p03740
u490305870
1551562775
Python
Python (3.4.3)
py
Runtime Error
17
2940
232
¥X,Y = map(int,input().split()) def judege(Z): ans = int(Z/2) re = Z%2 # print(ans,re) if ans == 0: if re == 0: return "Brown" else: return "Alice" else: return judege(ans+re) print(judege(X+Y))
s328480688
p03740
u794173881
1551049218
Python
Python (3.4.3)
py
Runtime Error
17
2940
64
x,y =map(int,input()) print("Brown" if abs(x-y)<=1 else "Alice")
s184583134
p03740
u794173881
1550335392
Python
Python (3.4.3)
py
Runtime Error
21
3316
854
from collections import deque n,m = map(int,input().split()) info = [list(map(int,input().split())) for i in range(m)] tree = [[] for i in range(n)] for i in range(m): tree[info[i][0]-1].append([info[i][0]-1,info[i][1]-1,info[i][2],False]) flag= [False] visited =[-float("inf")]*n visited[0]=0 count = [0] def bfs(here): q =deque() for i in tree[here]: q.append(i) while q and count[0] <=m*n: tmp = q.popleft() here =tmp[0] go = tmp[1] cost = tmp[2] if visited[here] + cost> visited[go]: visited[go] = cost +visited[here] for i in range(len(tree[go])): if not tree[go][i][3]: q.appendleft(tree[go][i]) tree[go][i][3]=True else: q.append(tree[go][i]) if go == n-1: print("inf") exit() count[0] +=1 bfs(0) print(visited[n-1])
s586087127
p03740
u522398430
1529553000
Python
Python (3.4.3)
py
Runtime Error
151
12508
387
import numpy x,y = map(int, input().split()) z = np.array([x,y]) i = 1 if z[z.argmax()] == 0 or z[z.argmax()] == 1: i = 1 else: while True: amax, amin = z.argmax(), z.argmin() z[amin] += z[amax]//2 z[amax] = 1 if z[amax]%2 else 0 i+=1 if (z[z.argmax()] == 0 or z[z.argmax()] == 1): break print("Brown" if i%2 else "Alice")
s163622771
p03740
u522398430
1529552921
Python
Python (3.4.3)
py
Runtime Error
305
21136
386
import numpy x,y = map(int, input().split()) z = np.array([x,y]) i = 1 if z[z.argmax()] == 0 or z[z.argmax()] == 1: i = 1 else: while True: amax, amin = z.argmax(), z.argmin() z[amin] += z[amax]//2 z[amax] = 1 if z[amax]%2 else 0 i+=1 if (z[z.argmax()] == 0 or z[z.argmax()] == 1): break print("Brown" if i%2 else "Alice")
s244268585
p03740
u391475811
1525480455
Python
Python (3.4.3)
py
Runtime Error
18
3188
86
X,Y=map(int,input()) if max(X,Y)-min(X,Y) > 1: print("Alice") else: print("Brown")
s346886014
p03740
u888275483
1493732486
Python
Python (2.7.6)
py
Runtime Error
10
2568
141
#!/usr/bin/env python # -*- coding: utf-8 -*- A, B = map(int, raw_input().split()) if abs(A - B) < 2 print("Brown") else: print("Alice")
s140504696
p03740
u579170193
1493242261
Python
Python (3.4.3)
py
Runtime Error
17
2940
69
a,b=map(int,raw_input().split());print(abs(a-b)<2and'Brown'or'Alice')
s924013038
p03740
u009102496
1493082188
Python
Python (3.4.3)
py
Runtime Error
17
2940
88
a,b=map(int,input().split()) if abs(a-b)<2: print("Brown") elif: print("Alice")
s881053290
p03741
u780475861
1590250068
Python
Python (3.4.3)
py
Runtime Error
43
14084
403
import sys def func(lst, sign): cur, res = 0, 0 for i in alst: cur += i if sign and cur <= 0: res += abs(cur) + 1 cur = 1 elif not sign and cur >= 0: res += abs(cur) + 1 cur = -1 sign = not sign return res def main(): n, *alst = map(int, sys.stdin.read().split()) print(min(func(alst, True), func(alst, False))) if __name__ == '__main__': main()
s227457514
p03741
u921773161
1565792757
Python
Python (3.4.3)
py
Runtime Error
107
14332
2955
n = int(input()) a = list(map(int, input().split())) tmp = 0 ans = 0 if a[0] != 0: for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass elif a[0] == 0: ans_list = [] a[0] = 1 ans += 1 for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass ans_list.append(ans) a[0] = -1 ans += 1 for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass ans_list.append(ans) ans = min(ans) print(ans)
s717533540
p03741
u921773161
1565792673
Python
Python (3.4.3)
py
Runtime Error
107
14332
2929
n = int(input()) a = list(map(int, input().split())) tmp = 0 ans = 0 if a[0] != 0: for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass elif a[0] == 0: ans_list = [] a[0] = 1 for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass ans_list.append(ans) a[0] = -1 for i in range(n): if i == 0 : tmp += a[i] elif i % 2 == 1: tmp += a[i] if a[0] > 0: if tmp < 0 : pass elif tmp >= 0 : ans += (abs(tmp) + 1) tmp = -1 elif a[0] < 0: if tmp <= 0 : ans += (abs(tmp)+1) tmp = 1 elif tmp > 0 : pass elif i % 2 == 0: tmp += a[i] if a[0] > 0: if tmp > 0 : pass elif tmp <= 0 : ans += (abs(tmp) + 1) tmp = 1 elif a[0] < 0: if tmp >= 0 : ans += (abs(tmp)+1) tmp = -1 elif tmp < 0 : pass ans_list.append(ans) ans = min(ans) print(ans)
s754338597
p03741
u879870653
1549144859
Python
Python (3.4.3)
py
Runtime Error
44
14332
546
N = int(input()) A = list(map(int,input().split())) ans = 0 sum_A = A[0] for i in range(1,N) : if ((sum_A + A[i]) == 0) or (sum_A *(sum_A + A[i]) >= 0) : if sum_A > 0 : ans += 1 + sum_A + A[i] #print("ans += {}".format(1 + sum_A + A[i])) sum_A = -1 elif sum_A < 0 : ans += 1 - (sum_A + A[i]) #print("ans += {}".format(1 - (sum_A + A[i]))) sum_A = 1 else : sum_A += A[i] #print("else") record.append(sum_A) print(ans)
s738232500
p03741
u663710122
1544736542
Python
Python (3.4.3)
py
Runtime Error
104
14332
331
_ = int(input()) A = list(map(int, input().split())) def solve(i, s, k, sign): if i >= len(A): return k if sign * (s + A[i]) > 0: return solve(i + 1, s + A[i], k, sign * -1) else: return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1) print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
s554414093
p03741
u663710122
1544736429
Python
Python (3.4.3)
py
Runtime Error
103
14332
326
N = int(input()) A = list(map(int, input().split())) def solve(i, s, k, sign): if i >= N: return k if sign * (s + A[i]) > 0: return solve(i + 1, s + A[i], k, sign * -1) else: return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1) print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))
s989573375
p03741
u663710122
1544736304
Python
Python (3.4.3)
py
Runtime Error
103
14332
331
N = int(input()) A = list(map(int, input().split())) def solve(i, s, k, sign): if i == N: return k if sign * (s + A[i]) > 0: return solve(i + 1, s + A[i], k, sign * -1) else: return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1) a = solve(0, 0, 0, 1) b = solve(0, 0, 0, -1) print(a)
s639080159
p03741
u663710122
1544736270
Python
Python (3.4.3)
py
Runtime Error
107
14468
364
N = int(input()) A = list(map(int, input().split())) def solve(i, s, k, sign): if i == N: return k if sign * (s + A[i]) > 0: return solve(i + 1, s + A[i], k, sign * -1) else: return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1) a = solve(0, 0, 0, 1) b = solve(0, 0, 0, -1) if a < b: print(a) else: print(b)