Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def issubset(a,b):
    #a<<bならtrue
    x=bin(a)[2:]
    y=bin(b)[2:]
    if a>b:
        return False
    for i in range(1,len(x)+1):
        if (x[-i],y[-i])==("1","0"):
            return False
    return True
N,K=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
Kl=[K]
Ks=bin(K)[2:]
for i,c in enumerate(Ks):
    if c=="1":
        Kl.append(int(Ks[:i]+"0"+"1"*(len(Ks)-i-1),2))
ans=0
for k in Kl:
    tmp=0
    for i in range(N):
        if issubset(A[i],k):
            tmp+=B[i]
    ans=max(tmp,ans)
print(ans)


Fixed submission:
def issubset(x,y):
    #a<<bならtrue
    if len(x)>len(y):
        return False
    for i in range(1,len(x)+1):
        if (x[-i],y[-i])==("1","0"):
            return False
    return True
N,K=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
    A[i]=bin(A[i])[2:]
Ks=bin(K)[2:]
Kl=[Ks]
for i,c in enumerate(Ks):
    if c=="1":
        Kl.append(Ks[:i]+"0"+"1"*(len(Ks)-i-1))
ans=0
for k in Kl:
    tmp=0
    for i in range(N):
        if issubset(A[i],k):
            tmp+=B[i]
    ans=max(tmp,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def issubset(a,b):
    #a<<bならtrue
    x=bin(a)[2:]
    y=bin(b)[2:]
    if a>b:
        return False
    for i in range(1,len(x)+1):
        if (x[-i],y[-i])==("1","0"):
            return False
    return True
N,K=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
Kl=[K]
Ks=bin(K)[2:]
for i,c in enumerate(Ks):
    if c=="1":
        Kl.append(int(Ks[:i]+"0"+"1"*(len(Ks)-i-1),2))
ans=0
for k in Kl:
    tmp=0
    for i in range(N):
        if issubset(A[i],k):
            tmp+=B[i]
    ans=max(tmp,ans)
print(ans)


Fixed submission:
def issubset(x,y):
    #a<<bならtrue
    if len(x)>len(y):
        return False
    for i in range(1,len(x)+1):
        if (x[-i],y[-i])==("1","0"):
            return False
    return True
N,K=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
    A[i]=bin(A[i])[2:]
Ks=bin(K)[2:]
Kl=[Ks]
for i,c in enumerate(Ks):
    if c=="1":
        Kl.append(Ks[:i]+"0"+"1"*(len(Ks)-i-1))
ans=0
for k in Kl:
    tmp=0
    for i in range(N):
        if issubset(A[i],k):
            tmp+=B[i]
    ans=max(tmp,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
print(sum([int(list(input())[i]) for i in range(6)]))

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)
 
g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar
import time
time.sleep(A*0.08)
print("{0} {1}".format(Smax+Hmax, Smax))

Fixed submission:
N = int(input())
A = int(input())
print(N ** 2 - A)

Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)

g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar

print("{0} {1}".format(Smax+Hmax, Smax))


Fixed submission:
N = int(input())
A = int(input())
print(N ** 2 - A)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[[int(i) for i in input().split()] for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        flag=True
        for k in range(N):
            if j==k or i==k:
                continue
            if A[i][j]>A[i][k]+A[k][j]:
                print(-1)
                exit()
            if A[i][j]==A[i][k]+A[k][j]:
                flag=False
        if flag:
            ans+=A[i][j]
print(ans)


Fixed submission:
N=int(input())
A=[[int(i) for i in input().split()] for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        flag=True
        for k in range(N):
            if j==k or i==k:
                continue
            if A[i][j]>A[i][k]+A[k][j]:
                print(-1)
                exit()
            if A[i][j]==A[i][k]+A[k][j]:
                flag=False
        if flag:
            ans+=A[i][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [0 for i in range(N)]
st = input().split()
for i in range(N):
  a[i] = int(st[i])
m = min(a); M = max(a)
b = [0 for i in range(M - m + 1)]
for i in range(N):
  b[a[i]-m] += 1
c = [0 for i in range(M - m + 1)]
c[0] = b[0] + b[1]
c[M - m] = b[M - m] + b[M - m - 1]
for i in range(1, M - m):
  c[i] = b[i-1] + b[i] + b[i+1]
print(max(c))


Fixed submission:
N = int(input())
a = [0 for i in range(N)]
st = input().split()
for i in range(N):
  a[i] = int(st[i])
m = min(a); M = max(a)
b = [0 for i in range(M - m + 1)]
for i in range(N):
  b[a[i]-m] += 1
c = [0 for i in range(M - m + 1)]
if len(b) >= 2:
	c[0] = b[0] + b[1]
	c[M - m] = b[M - m] + b[M - m - 1]
	for i in range(1, M - m):
	  c[i] = b[i-1] + b[i] + b[i+1]
	print(max(c))
else:
  print(max(b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
st = input().split()
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(st[i])

A.sort(reverse = True)
U = []
for i in range(N-1):
  if A[i] == A[i+1]:
    U.append(A[i])
    A[i] = -1
    A[i+1] = -1
  if len(U) >= 2:
    break
print(U[0] * U[1])


Fixed submission:
N = int(input())
st = input().split()
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(st[i])

A.sort(reverse = True)
U = []
for i in range(N-1):
  if A[i] == A[i+1]:
    U.append(A[i])
    A[i] = -1
    A[i+1] = -1
  if len(U) >= 2:
    break
if len(U) >= 2:
	print(U[0] * U[1])
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
R = [0 for i in range(2)]
st = input().split()
for i in range(N):
    k = int(st[i])
    m = 0
    if k % 4 == 1 or k % 4 == 3:
        m = 0
    elif k % 4 == 2:
        m = 1
    else:
        m = 2
    R[m] += 1
    

if R[1]+R[2]*2 < 2*(N-1):
    print("No")
else:
    print("Yes")


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
P=0
Q=0
R=0
for i in range(N):
    if a[i]%4==0:
        P+=1
    elif a[i]%4==2:
        Q+=1
    else:
        R+=1
if (Q==0 and R>P+1) or (Q!=0 and R>P):
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
print("ABC{0}".format(input())

Fixed submission:
print("ABC{0}".format(input()))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])

flag = 0
for k in c:
    if k == N:
        flag = 1
        break
    else:
        for i in range(M):
            if a[i] == k and b[i] == N:
                flag = 1
                break
    if flag == 1:
        break

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Fixed submission:
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
d = []
flag = 0
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])
        if b[i] == N:
            flag = 1
    if b[i] == N:
        d.append(a[i])
        if a[i] == 1:
            flag = 1
e = set(c) | set(d)
if len(c) + len(d) == len(e):
    flag = 0
else:
    flag = 1

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])

flag = 0
for k in c:
    if k == N:
        flag = 1
        break
    else:
        for i in range(M):
            if a[i] == k and b[i] == N:
                flag = 1
                break
    if flag == 1:
        break

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Fixed submission:
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = []
d = []
flag = 0
for i in range(M):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        c.append(b[i])
        if b[i] == N:
            flag = 1
    if b[i] == N:
        d.append(a[i])
        if a[i] == 1:
            flag = 1
e = set(c) | set(d)
if len(c) + len(d) == len(e):
    flag = 0
else:
    flag = 1

if flag == 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
K = int(input())
N = 10
a = [i for i in range(N)]
for k in range(K//N):
    a[k]+=K//N
for i in range(K%N):
    for j in range(N):
        if i==j:
            a[j]+=N
        else:
            a[j]-=1
print(N)
print(str(a)[1:][:-1].replace(", ", " "))


Fixed submission:
K = int(input())
N = 50
a = [i+K//N for i in range(N)]
for i in range(K%N):
    for j in range(N):
        if i%N==j:
            a[j]+=N
        else:
            a[j]-=1
print(N)
print(str(a)[1:][:-1].replace(", ", " "))

Buggy python submission (verdict: Runtime Error):
K = int(input())
N = 10
a = [i for i in range(N)]
for k in range(K//N):
    a[i]+=K//N
for i in range(K%N):
    for j in range(N):
        if i==j:
            a[j]+=N
        else:
            a[j]-=1
print(N)
print(str(a)[1:][:-1].replace(", ", " "))


Fixed submission:
K = int(input())
N = 50
a = [i+K//N for i in range(N)]
for i in range(K%N):
    for j in range(N):
        if i%N==j:
            a[j]+=N
        else:
            a[j]-=1
print(N)
print(str(a)[1:][:-1].replace(", ", " "))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(N)]
R=[0 for i in range(M)]
for i in range(N):
    R[A[i][0]-1]+=1
P=0
Q=0
S=set()
for i in range(N):
    if R[A[i][0]-1]>=P:
        P=R[A[i][0]-1]
        Q=A[i][0]
S.add(Q)
while(len(S)<M):
    Pd=0
    Qd=0
    R=[0 for i in range(M)]
    for i in range(N):
        for j in range(M):
            if not(set([A[i][j]]) <= S):
                R[A[i][j]-1]+=1
                break
    for j in range(M):
        if R[j]>=Pd:
            Pd=R[j]
            Qd=j+1
    if Pd<P:
        P=Pd
    S.add(Qd)
print(P)


Fixed submission:
N,M=map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(N)]
R=[0 for i in range(M)]
for i in range(N):
    R[A[i][0]-1]+=1
P=0
Q=0
S=set()
for i in range(N):
    if R[A[i][0]-1]>=P:
        P=R[A[i][0]-1]
        Q=A[i][0]
S.add(Q)
while(len(S)<M):
    Pd=0
    Qd=0
    R=[0 for i in range(M)]
    for i in range(N):
        for j in range(M):
            if not(set([A[i][j]]) <= S):
                R[A[i][j]-1]+=1
                break
    for j in range(M):
        if R[j]>=Pd:
            Pd=R[j]
            Qd=j+1
    if Pd<P:
        P=Pd
    S.add(Qd)
print(P)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
b = []
st = input().split()
for i in range(n):
    k = st[i]
    if i % 2 == 0:
        b.insert(0, k)
    else:
        b.append(k)
if n % 2 == 0:
    b= list(reversed(b))
s = ""
for k in b:
    s += k + " "
print(s)


Fixed submission:
n = int(input())
b = []
a = input().split()
if n % 2 == 0:
    m = n // 2
    for i in range(m):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i])
else:
    m = n // 2
    for i in range(m+1):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i+1])
s = ""
for k in b:
    s += k + " "
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
b = []
st = input().split()
for i in range(n):
    k = st[i]
    if i % 2 == 0:
        b.insert(0, k)
    else:
        b.append(k)
if n % 2 == 0:
    b= list(reversed(b))
s = ""
for k in b:
    s += k + " "
print(s)


Fixed submission:
n = int(input())
b = []
a = input().split()
if n % 2 == 0:
    m = n // 2
    for i in range(m):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i])
else:
    m = n // 2
    for i in range(m+1):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i+1])
s = ""
for k in b:
    s += k + " "
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
b = []
st = input().split()
for i in range(n):
    k = int(st[i])
    if i % 2 == 0:
        b.insert(0, k)
    else:
        b.append(k)
if n % 2 == 0:
    b= list(reversed(b))
s = ""
for k in b:
    s += str(k) + " "
print(s)


Fixed submission:
n = int(input())
b = []
a = input().split()
if n % 2 == 0:
    m = n // 2
    for i in range(m):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i])
else:
    m = n // 2
    for i in range(m+1):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i+1])
s = ""
for k in b:
    s += k + " "
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
b = []
st = input().split()
for i in range(n):
    k = int(st[i])
    if i % 2 == 0:
        b.insert(0, k)
    else:
        b.append(k)
if n % 2 == 0:
    b= list(reversed(b))
s = ""
for k in b:
    s += str(k) + " "
print(s)


Fixed submission:
n = int(input())
b = []
a = input().split()
if n % 2 == 0:
    m = n // 2
    for i in range(m):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i])
else:
    m = n // 2
    for i in range(m+1):
        b.append(a[n-2*i-1])
    for i in range(m):
        b.append(a[2*i+1])
s = ""
for k in b:
    s += k + " "
print(s)
Buggy python submission (verdict: Runtime Error):
r,g,b = map(int, input().split())
if (g*2+b)%4 == 0:
    print(“YES”)
else:
    print(“NO”)


Fixed submission:
r,g,b = map(int, input().split())
if (g*2+b)%4 == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[i for i in input().split()]
print(max(a)-min(a))

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[int(i)//400 for i in input().split()]
s=set()
r=0
for i in range(N):
    if a[i]==7:
        r+=1
    else:
        s.add(a[i])
print("{0} {1}".format(min([1,len(s)]),len(s)+r)

Fixed submission:
N=int(input())
a=[int(i)//400 for i in input().split()]
s=set()
r=0
for i in range(N):
    if a[i]>=8:
        r+=1
    else:
        s.add(a[i])
print("{0} {1}".format(max([1,len(s)]),len(s)+r))
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
h = [int(input()) for i in range(N)]
Tmax=2*max(h)//B
def Tenabled(Tin):
    x = [h[i] for i in range(N)]
    for i in range(N):
        x[i] -= B*Tin
    S = 0
    for i in range(N):
        if x[i]>0:
            S += -((-x[i])//(A-B))
    if S<=Tin:
        return True
    else:
        return False


high=Tmax
low=0
t=(high+low)//2
while(low<=high):
    if Tenabled(t):
        high=t
    else:
        low=t+1
    t=(high+low)//2
    if Tenabled(t)==True and Tenabled(t-1)==False:
        break
print(t)


Fixed submission:
N, A, B = map(int, input().split())
h = [int(input()) for i in range(N)]
Tmax=2*max(h)//B
def Tenabled(Tin):
    x = [h[i] for i in range(N)]
    for i in range(N):
        x[i] -= B*Tin
    S = 0
    for i in range(N):
        if x[i]>0:
            S += -((-x[i])//(A-B))
    if S<=Tin:
        return True
    else:
        return False


high=Tmax
low=0
t=(high+low)//2
while(low<=high):
    if Tenabled(t):
        high=t
    else:
        low=t+1
    t=(high+low)//2
    if Tenabled(t)==True and Tenabled(t-1)==False:
        break
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = [0 for i in range(M)]
for i in range(M):
    a[i], b[i], c[i] = map(int, input().split())
distance = [-10**20 for i in range(N)]
distance[0] = 0
for i in range(1,N):
    for j in range(M):
        u = a[j]-1; v = b[j]-1
        if distance[v] < distance[u] + c[j]:
            distance[v] = distance[u] + c[j]
negative = [False for i in range(N)]
for i in range(N):
    for j in range(M):
        u = a[j]-1; v = b[j]-1
        if distance[v] < distance[u] + c[j]:
            distance[v] = distance[u] + c[j]
            negative[v] = True
        if negative[u]:
            negative[v] = True
if negative[N-1]:
    print("inf")
else:
    print(distance[N-1])


Fixed submission:
N, M = map(int, input().split())
a = [0 for i in range(M)]
b = [0 for i in range(M)]
c = [0 for i in range(M)]
for i in range(M):
    a[i], b[i], c[i] = map(int, input().split())
distance = [-10**20 for i in range(N)]
distance[0] = 0
for i in range(1,N):
    for j in range(M):
        u = a[j]-1; v = b[j]-1
        if distance[v] < distance[u] + c[j]:
            distance[v] = distance[u] + c[j]
negative = [False for i in range(N)]
for i in range(N):
    for j in range(M):
        u = a[j]-1; v = b[j]-1
        if distance[v] < distance[u] + c[j]:
            distance[v] = distance[u] + c[j]
            negative[v] = True
        if negative[u]:
            negative[v] = True
if negative[N-1]:
    print("inf")
else:
    print(distance[N-1])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
X=[0 for i in range(N)]
for i in range(M):
    X[a[i]]+=1
    X[b[i]]+=1
for i in range(N):
    if X[i]%2==1:
        print("NO")
        exit()
print("YES")


Fixed submission:
N,M=map(int,input().split())
a=[0 for i in range(M)]
b=[0 for i in range(M)]
for i in range(M):
    a[i],b[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
X=[0 for i in range(N)]
for i in range(M):
    X[a[i]]+=1
    X[b[i]]+=1
for i in range(N):
    if X[i]%2==1:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
import math
A, B, C = map(int, input().split())
if C%math.gcd(A,B)==0:
    print("YES")
else:
    print("NO")


Fixed submission:
def gcd(x,y):
    p=max([x,y])
    q=min([x,y])
    if p%q==0:
        return q
    else:
        return gcd(q,p%q)

A, B, C = map(int, input().split())
if C%gcd(A,B)==0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
def sign(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    else:
        return 0


n = int(input())
a = [int(i) for i in input().split()]
s = [sum(a[:i+1]) for i in range(n)]
sp = [s[i] for i in range(n)]
sm = [s[i] for i in range(n)]
P0=0
M0=0
if s[0]==0:
    P0+=1
    M0+=1
    for j in range(n):
        sp[j]+=1
        sm[j]+=1
elif s[0]>0:
    M0+=abs(s[0]+1)
    for j in range(n):
        sm[j]-=(abs(s[0])+1)
else:
    P0+=abs(s[0]+1)
    for j in range(n):
        sp[j]+=(abs(s[0])+1)
for i in range(1,n):
    if sm[i-1]*sm[i]>=0:
        M0+=abs(sm[i])+1
        h=sign(sm[i-1])*(-1)*(abs(sm[i])+1)
        for j in range(i,n):
            sm[j]+=h
    if sp[i-1]*sp[i]>=0:
        P0+=abs(sp[i])+1
        h=sign(sp[i-1])*(-1)*(abs(sp[i])+1)
        for j in range(i,n):
            sp[j]+=h
print(min([M0,P0]))


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

Buggy python submission (verdict: Time Limit Exceeded):
def sign(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    else:
        return 0


n = int(input())
a = [int(i) for i in input().split()]
s = [sum(a[:i+1]) for i in range(n)]
sp = [s[i] for i in range(n)]
sm = [s[i] for i in range(n)]
P0=0
M0=0
if s[0]==0:
    P0+=1
    M0+=1
    for j in range(n):
        sp[j]+=1
        sm[j]+=1
elif s[0]>0:
    M0+=abs(s[0]+1)
    for j in range(n):
        sm[j]-=(abs(s[0])+1)
else:
    P0+=abs(s[0]+1)
    for j in range(n):
        sp[j]+=(abs(s[0])+1)
for i in range(1,n):
    if sm[i-1]*sm[i]>=0:
        M0+=abs(sm[i])+1
        h=sign(sm[i-1])*(-1)*(abs(sm[i])+1)
        for j in range(i,n):
            sm[j]+=h
    if sp[i-1]*sp[i]>=0:
        P0+=abs(sp[i])+1
        h=sign(sp[i-1])*(-1)*(abs(sp[i])+1)
        for j in range(i,n):
            sp[j]+=h
print(min([M0,P0]))


Fixed submission:
def sign(p):
    if p<0:
        return -1
    elif p>0:
        return 1
    else:
        return 0
N=int(input())
a=[int(i) for i in input().split()]
m=[0,0]
for sgn in [-1,1]:
    x=0
    S=0
    for i in range(N):
        S+=a[i]
        if sign(S)==sgn*(-1)**(i%2) or sign(S)==0:
            x+=abs(S)+1
            S=sgn*(-1)**((i+1)%2)
    m[(sgn+1)//2]=x
print(min(m))
Buggy python submission (verdict: Runtime Error):
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
Y=[0 for i in range(N)]
for i in range(N):
    if W[i]==1:
        Y[i]=(X[i]+T)%L
    else:
        Y[i]=(X[i]-T)%L
def dist(i,j):
    if (3-2*W[i])*(3-2*W[j])==1:
        return -1
    else:
        if 3-2*W[i]==1:
            D=(X[j]-X[i])%L
            return D//2
        else:
            D=(X[i]-X[j])%L
            return D//2
z=0
dt=3-2*W[0]
for i in range(1,N):
    ds=3-2*W[i]
    if dt*ds==1:
        continue
    z+=dt*((T//L)*2)
    K=T%L
    if K>=dist(0,i):
        z+=dt
    if K>=dist(0,i)+L//2:
        z+=st
z=-z%N
Z=Y[z:]+Y[:z]
for i in range(N):
    print(Z[i])

    

Fixed submission:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
D=0
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
    D+=(X[i]+T*W[i])//L
D%=N
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
for i in range(N):
    print(Y[(D+i)%N])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
P=10**9+7
X=0
Y=0
for i in range(1,M+1):
  X+=x[i-1]*(2*i-1-M)
  X=X%P
for j in range(1,N+1):
  Y+=y[j-1]*(2*j-1-N)
  Y=Y%P
print((X*Y)%P)


Fixed submission:
N,M=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
P=10**9+7
X=0
Y=0
for i in range(1,N+1):
  X+=x[i-1]*(2*i-1-N)
  X=X%P
for j in range(1,M+1):
  Y+=y[j-1]*(2*j-1-M)
  Y=Y%P
print((X*Y)%P)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
a = [[]]
a[0].append(0)
n=0
flag = False
while(True):
    n+=1
    a.append([])
    for p in a[n-1]:
        a[n].append(p)
        a[n].append(p-n)
        a[n].append(p+n)
        if p==X or p-n==X or p+n==X:
            print(n)
            flag = True
            break
    if flag:
        break


Fixed submission:
X = int(input())
j=0
for i in range(X*2):
    if (i*(i+1))//2<=X<=((i+1)*(i+2))//2:
        j=i
        break
print(j+1)