Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03031 (python)

Fixed submission:
n,m = map(int,input().split())

li=[]
for i in range(1, m+1):
    s=list(map(int, input().split()))
    s.pop(0)
    li.append(s)

if m==1:
    p = [int(input())]
else:
    p = list(map(int, input().split()))
#print(li)
#print(p)

def check(g,en):
    stack = ["1", "0"]
    candi = []
    while stack:
        cur = stack.pop()
        if len(cur) == en:
            candi.append(cur)
            continue
        for i in g[len(cur)+1]:
            tmp = cur+i
            stack.append(tmp)
    return candi

g={}
for i in range(0,n+1):
    g[i]=["1", "0"]

ans = 0
#print(check(g,n))
for i in check(g,n):
    flag=0
    for j in range(m):
        tmp=0
        for k in range(0,len(li[j])):
            tmp += int(i[li[j][k]-1])
        if tmp % 2 != p[j]:
            flag=1
            break
    if flag==0:
        #print(i)
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

li=[]
for i in (1, m+1):
    s=list(map(int, input().split()))
    s.pop(0)
    li.append(s)

p = list(map(int, input().split()))
#print(li)
#print(p)

def check(g,en):
    stack = ["1", "0"]
    candi = []
    while stack:
        cur = stack.pop()
        if len(cur) == en:
            candi.append(cur)
            continue
        for i in g[len(cur)+1]:
            tmp = cur+i
            stack.append(tmp)
    return candi

g={}
for i in range(0,n+1):
    g[i]=["1", "0"]

ans = 0
print(check(g,n))
for i in check(g,n):
    flag=0
    for j in range(m):
        tmp=0
        for k in range(0,len(li[j])):
            tmp += int(i[li[j][k]-1])
        if tmp % 2  != p[j]:
            flag=1
            break
    if flag==0:
        print(i)
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())

li=[]
for i in (1, m+1):
    s=list(map(int, input().split()))
    s.pop(0)
    li.append(s)

p = list(map(int, input().split()))
#print(li)
#print(p)


def check(g,en):
    stack = ["1", "0"]
    checked = []
    candi = []
    while stack:
        cur = stack.pop()
        checked.append(cur)
        if len(cur) == en:
            candi.append(cur)
            continue
        for i in g[len(cur)]:
            tmp = cur+i
            if tmp in checked:
                continue
            if tmp in stack:
                continue
            stack.append(tmp)
    return candi

g={}
for i in range(0,n+1):
    g[i]=["1", "0"]

ans = 0
for i in check(g,n):
    flag=0
    for j in range(m):
        tmp=0
        for k in range(0,len(li[j])):
            tmp += int(i[li[j][k]-1])
        if tmp % 2  != p[j]:
            flag=1
            break
    if flag==0:
        #print(i)
        ans += 1

print(ans)
Problem p03044 (python)

Fixed submission:
n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

#print(tree)
stack=[1]
visitted={}
ans=[0]*n

while stack:
    cur = stack.pop()
    pre=ans[cur-1]
    visitted.setdefault(cur,1)
    #visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if w % 2 == 1:
            ans[v-1]=(pre+1)%2
        else:
            ans[v-1]=pre
        stack.append(v)

print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

stack=[1]
visitted=[]
ans=[0]*n

while stack:
    cur = stack.pop()
    visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        #if v in stack:
        #    continue
        if w % 2 == 1:
            ans[v-1]=(ans[cur]+1)%2
        else:
            ans[v-1]=ans[cur]
        stack.append(v)

for i in ans:
    print(i)
Problem p03062 (python)

Fixed submission:
n = int(input())
ai = list(map(int,input().split()))

dp =[[0, -10**9]]
#print(dp[0][0])

for i in range(1,n+1):
	dp.append([max(dp[i-1][0]+ai[i-1], dp[i-1][1]-ai[i-1]), \
			max(dp[i-1][0]-ai[i-1], dp[i-1][1]+ai[i-1])])
	#print(dp)
    
print(dp[n][0])

Buggy submission (verdict: Runtime Error):
n = int(input())
ai = list(map(int,input().split()))

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**9
	elif j==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))

Buggy submission (verdict: Runtime Error):
n = int(input())
ai = list(map(int,input().split()))

dp = [[]]

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**11
	elif j ==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))
Problem p03069 (python)

Fixed submission:
n=int(input())
sl=list(input())

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if (sl[i]=="#" and sl[i+1]==".") or (sl[i]=="." and sl[i+1]=="#") :
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
sl=list(s)

res=0
for i in range(n):
	if sl[i]=="#" and sl[i+1]==".":
		res= res + 1
        
print(res)
Problem p03105 (python)

Fixed submission:
A,B,C = map(int,input().split())

print(min(int(B/A), C))

Buggy submission (verdict: Runtime Error):
n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)
Problem p02994 (python)

Fixed submission:
n,l = (int(i) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)

Buggy submission (verdict: Runtime Error):
n,l = (int(I) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)
Problem p03067 (python)

Fixed submission:
a,b,c = (int(i) for i in input().split())
if (a-c)*(b-c)<0: print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = (int(i) for i in input().split())
if (a-c)(b-c)<0: print("Yes")
else: print("No")
Problem p03074 (python)

Fixed submission:
n,k = (int(i) for i in input().split())
s = input()
x,y,f,num,ans = [],[],1,0,0
for i in range(n):
    if f and s[i]=="1":
        f = 0
        x.append(i)
    elif 1-f and s[i]=="0":
        f,num = 1,num+1
        y.append(i-1)
if x and x[0]: num+=1
if int(s[-1]): y.append(n-1)
if num<=k: print(n)
else:
    if x[0]: ans = y[k-1]+1
    if s[-1]=="0": ans = max(ans,n-x[-k])
    for i in range(len(y)-k): ans = max(y[i+k]-x[i]+1,ans)
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k = (int(i) for i in input().split())
s = input()
x,y,f,num,ans = [],[],1,0,0
for i in range(n):
    if f and s[i]=="1":
        f = 0
        x.append(i)
    elif 1-f and s[i]=="0":
        f,num = 1,num+1
        y.append(i-1)
if x[0]: num+=1
if int(s[-1]): y.append(n-1)
if num<=k: print(n)
else:
    if x[0]: ans = y[k-1]+1
    for i in range(len(y)-k):
        if x[i]+1: ans = max(y[i+k]-x[i]+1,ans)
        else: ans = max(y[i+k]-x[i],ans)
    print(ans)
Problem p03081 (python)

Fixed submission:
n,q = (int(i) for i in input().split())
s = input()
x = [[i for i in input().split()] for i in range(q)]
l,r,s = 0,n+1,"#"+s+"#"
for i,j in x[::-1]:
    if l<=n and s[l+1]==i and  j=="L": l+=1
    elif s[l]==i and j=="R": l-=1
    if s[r-1]==i and j=="R": r-=1
    elif s[r]==i and j=="L": r+=1
print(max(0,r-l-1))

Buggy submission (verdict: Runtime Error):
n,q = (int(i) for i in input().split())
s = input()
x = [(i for i in input().split()) for i in range(q)]
l,r,s,f,R = 0,n+1,"#"+s+"#",1,0
while l+1<r:
    now = (l+r)//2
    for i,j in x:
        if s[now]==i:
            if j=="L": now-=1
            else: now+=1
        if now*(now-n-1)==0: break
    if now*(now-n-1) and f: f,R = 0,(l+r)//2
    if now: r = (l+r)//2
    else: l = (l+r)//2
L,r = l,n+1
if R: l = R
while l+1<r:
    now = (l+r)//2
    for i,j in x:
        if s[now]==i:
            if j=="L": now-=1
            else: now+=1
        if now*(now-n-1)==0: break
    if now-n-1: l = (l+r)//2
    else: r = (l+r)//2
print(r-L-1)
Problem p03096 (python)

Fixed submission:
n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(200001)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    if c[i]-c[i-1]: x[c[i]] = (x[c[i]]+num)%(10**9+7)
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(n+1)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    x[c[i]]+=num
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)
Problem p03128 (python)

Fixed submission:
n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x,y,inf = [2,5,5,4,5,6,3,7,6],set(),float("inf")
dp,ans = [0,-inf],[]
def f(i,y):
    num = -inf
    for j in y:
        if i>=j: num = max(num,dp[i-j]+1)
    return num 
for i in a: y.add(x[i-1])
for i in range(2,n+1): dp.append(f(i,y))
a,N = sorted(a)[::-1],n
for i in range(dp[n]):
    for j in a:
        if N>=x[j-1] and dp[N-x[j-1]]==dp[N]-1:
            ans.append(str(j))
            N-=x[j-1]
            break
print("".join(ans))

Buggy submission (verdict: Runtime Error):
n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x,y,inf = [2,5,5,4,5,6,3,7,6],set(),float("inf")
dp,ans = [0,-inf],[]
def f(i,y):
    num = -inf
    for j in y:
        if i>=j: num = max(num,dp[i-j]+1)
    return num 
for i in a: y.add(x[i-1])
for i in range(2,n+1): dp.append(f(i,y))
a,N = sorted(a)[::-1],n
for i in range(dp[n]):
    for j in a:
        if dp[N-x[j-1]]==dp[N]-1:
            ans.append(str(j))
            N-=x[j-1]
            break
print("".join(ans))
Problem p03147 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]
c,h = 0,h+[0]
while sum(h):
	f = 0
	for i in range(n+1):
		if f and h[i]==0:
			m,f = min(h[l:i]),0
			for j in range(l,i): h[j]-=m
			c+=m
		elif 1-f and h[i]: f,l = 1,i
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]
c,h = 0,h+[0]
while sum(h):
	for i in range(n):
		if h[i]!=0:
			l = i
			break
	for i in range(l,n+1):
		if h[i]==0:
			m = min(h[l:i])
			for j in range(l,i): h[j]-=m
			c+=m
			for j in range(l,n+1):
				if h[j]!=0:
					l = j
					break
print(c)
Problem p03288 (python)

Fixed submission:
n = int(input())
if n<1200: print("ABC")
elif n<2800: print("ARC")
else: print("AGC")

Buggy submission (verdict: Runtime Error):
n = int(input())
if n<1200: print("ABC")
elif: n<2800: print("ARC")
else: print("AGC")
Problem p03323 (python)

Fixed submission:
a,b = (int(i) for i in input().split())
if a<9 and b<9: print("Yay!")
else: print(":(")

Buggy submission (verdict: Runtime Error):
a,b = (int(input()))
if a<9 and b<9: print("Yay!")
else: print(":(")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a<9 and b<9: print("Yey!")
else: print(":(")
Problem p03333 (python)

Fixed submission:
n = int(input())
L,R = [0],[0]
for _ in range(n):
	l,r = (int(i) for i in input().split())
	L.append(l)
	R.append(r)
L,R,ans = sorted(L)[::-1],sorted(R),0
for i in range(n+1):
	if L[i]>R[i]: ans+=L[i]-R[i]
	else: break
print(ans*2)

Buggy submission (verdict: Runtime Error):
n = int(input())
L,R = [],[]
for num in range(n):
	l,r = (int(i) for i in input().split())
	if l<=0<=r: continue
	L.append(l)
	R.append(r)
L,R,a,b = sorted(L),sorted(R),-1,0
if R and L and R[0]<=0 and L[-1]>=0:
	if abs(R[0])<L[-1]: flag,now,ans,a = True,L[-1],L[-1],-2
	else: flag,now,ans,b = False,R[0],abs(R[0]),1
elif R and L and R[0]<=0 and L[-1]<0: flag,now,ans,b = False,R[0],abs(R[0]),1
elif R and L and R[0]>0 and L[-1]>=0: flag,now,ans,a = True,L[-1],L[-1],-2
else: ans,now = 0,0
while ans!=0 and b-a!=len(L)+1:
	if flag: flag,now,ans,b = False,R[b],ans+abs(now-R[b]),b+1
	else: flag,now,ans,a = True,L[a],ans+abs(now-L[a]),a-1
if print(ans+abs(now))
Problem p03428 (python)

Fixed submission:
from math import sqrt,pi,acos
n = int(input())
p1 = [[int(i) for i in input().split()] for i in range(n)]
p,q,ans = sorted(p1),[],[]
x1,x2,y1,y2,z1,z2 = p[0][0],p[0][1]+1,p[0][0],p[0][1],10**6+1,0
def cos(a,b,c,d,e,f):
	a,b,e,f = a-c,b-d,e-c,f-d
	return (a*e+b*f)/(sqrt(a**2+b**2)*sqrt(e**2+f**2))
while p[0]!=[z1,z2]:
	q.append([y1,y2])
	num = 2
	for i,j in p:
		if y1!=i or y2!=j:
			m = cos(x1,x2,y1,y2,i,j)
			if num>m: num,z1,z2 = m,i,j
	ans.append((pi-acos(max(-1,num)))/(2*pi))
	x1,x2,y1,y2 = y1,y2,z1,z2
ans = [(pi-acos(cos(x1,x2,y1,y2,q[1][0],q[1][1])))/(2*pi)]+ans[1:]
for i in p1:
	if i in q: print(ans[q.index(i)])
	else: print(0)

Buggy submission (verdict: Runtime Error):
from math import sqrt,pi,acos
n = int(input())
p1 = [[int(i) for i in input().split()] for i in range(n)]
p,q,ans = sorted(p1),[],[]
x1,x2,y1,y2,z1,z2 = p[0][0],p[0][1]+1,p[0][0],p[0][1],10**6+1,0
def cos(a,b,c,d,e,f):
	a,b,e,f = a-c,b-d,e-c,f-d
	return (a*e+b*f)/(sqrt(a**2+b**2)*sqrt(e**2+f**2))
while p[0]!=[z1,z2]:
	q.append([y1,y2])
	num = 2
	for i,j in p:
		if y1!=i or y2!=j:
			m = cos(x1,x2,y1,y2,i,j)
			if num>m: num,z1,z2 = m,i,j
	ans.append((pi-acos(num))/(2*pi))
	x1,x2,y1,y2 = y1,y2,z1,z2
ans = [(pi-acos(cos(x1,x2,y1,y2,q[1][0],q[1][1])))/(2*pi)]+ans[1:]
for i in p1:
	if i in q: print(ans[q.index(i)])
	else: print(0)
Problem p03469 (python)

Fixed submission:
s = input()
print(s[:3] + "8" + s[4:])

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
num = 0
for j2 in b:
	if j2 >= a:
		h -= j2
		num +=1
if h%a==0: answer = (h-h%a)//a + num
else: answer = (h-h%a)//a + num + 1
print(answer)
Problem p03472 (python)

Fixed submission:
def main():
    N, H = map(int, input().split())
    AB = (tuple(map(int, input().split())) for _ in [0] * N)
    a, b = [], []
    appenda, appendb = a.append, b.append
    for i, j in AB:
        appenda(i)
        appendb(j)

    amax = max(a)
    b = [i for i in b if i > amax]
    b.sort(reverse=1)
    energy = H
    if energy <= sum(b):
        attack = 0
        i = 0
        while energy > 0:
            energy -= b[i]
            attack += 1
            i += 1
    else:
        energy -= sum(b)
        attack = (energy + amax - 1) // amax + len(b)

    print(attack)

main()

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
b = [i for i in b if i>a]
b.sort().reverse()
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
num = 0
b.sort().reverse()
for j2 in b:
	if j2 >=a and h>0: 
	    h -= j2
		num +=1
	else: break
if h<=0: print(num)
else:
	if h%a==0: print((h-h%a)//a + num)
	else: print((h-h%a)//a + num + 1)

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
num = 0
for j2 in b:
	if j2 >= a and h>0:
		h -= j2
		num +=1
if h<=0: print(num)
else:
	if h%a==0: answer = (h-h%a)//a + num
	else: answer = (h-h%a)//a + num + 1
    print(answer)

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if j[0] > a: a = j[0]
	b.append(j[1])
b.sort()
while b[0]<=a: b = b[1:]
h -= sum(b)
if h%a==0: answer = (h-h%a)//a + len(b)
else: answer = (h-h%a)//a + len(b) + 1
print(answer)
Problem p03475 (python)

Fixed submission:
n = int(input())
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1): c[i],s[i],f[i] = (int(i2) for i2 in input().split())
for j in range(n):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())
c,s,f = [0]*(n-1)
for i in range(n-1): c[i],s[i],f[i] = map(int,input().split())
for j in range(n-1):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)
Problem p03485 (python)

Fixed submission:
a,b = (int(i) for i in input().split())
if (a+b)%2==0: print((a+b)//2)
else: print((a+b+1)//2)

Buggy submission (verdict: Runtime Error):
a,b = int(input())
if (a+b)%2==0: print((a+b)//2)
else: print((a+b+1)//2)
Problem p03486 (python)

Fixed submission:
s = input()
t = input()
slist,tlist = [],[]
for i in s:
	slist.append(i)
for i in t:
	tlist.append(i)
slist.sort()
tlist.sort()
tlist = tlist[::-1]
for j in range(min(len(slist),len(tlist))):
	if ord(slist[j]) < ord(tlist[j]):
		print("Yes")
		break
	elif ord(slist[j]) > ord(tlist[j]):
		print("No")
		break
	else:
		if j == min(len(slist),len(tlist))-1:
			if len(slist) < len(tlist): print("Yes")
			else: print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
slist,tlist = [],[]
for i in s:
	slist.append(i)
for i in t:
	tlist.append(i)
slist.sort()
tlist.sort()
tlist = tlist[::-1]
for j in range(min(len(slist),len(tlist))):
	if ord(slist[j]) < ord(tlist[j]):
		print("Yes")
		break
	elif ord(slist[j]) > ord(tlist(j)):
		print("No")
		break
	else:
		if j == min(len(slist),len(tlist))-1:
			if len(slist) < len(tlist): print("Yes")
			else: print("No")
Problem p03487 (python)

Fixed submission:
import collections
n = int(input())
a = [int(i) for i in input().split()]
c = collections.Counter(a)
answer = 0
for i in c.most_common():
	if i[0]>i[1]:
		answer += i[1]
	elif i[0]<i[1]:
		answer += i[1]-i[0]
print(answer)

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
x = [int(i) for i in input().split()]
y = copy.deepcopy(x)
z = []
for j in x:
	if j not in z and x.count(j)<j:
		while y.count(j) != 0: y.remove(j)
	elif j not in z and x.count(j)>j:
		while y.count != j: y.remove(j)
	z.append(j)
print(len(x)-len(y))
Problem p03488 (python)

Fixed submission:
s = [len(i) for i in input().split("T")]
x,y  = (int(i) for i in input().split())
xl,yl,flag = [],[],False
for i in range(len(s)):
	if i%2==0: xl.append(s[i])
	else: yl.append(s[i])
x,y,xl = abs(x-xl[0]),abs(y),xl[1:]
xs,ys,lenx,leny,xl2,yl2 = sum(xl),sum(yl),len(xl),len(yl),[0],[0]
a,b = [[0 for i in range(xs+1)] for i in range(lenx+1)],[[0 for i in range(ys+1)] for i in range(leny+1)]
a[0][0],b[0][0] = 1,1
if xs>=x and (xs-x)%2==0 and ys>=y and (ys-y)%2==0: x2,y2,flag = (xs-x)//2,(ys-y)//2,True
else: print("No")
if flag:
	for i in range(lenx):
		for j in range(x2+1):
			if xl[i]<=j: a[i+1][j] = a[i][j-xl[i]] | a[i][j]
			else: a[i+1][j] = a[i][j]
	for i in range(leny):
		for j in range(y2+1):
			if yl[i]<=j: b[i+1][j] = b[i][j-yl[i]] | b[i][j]
			else: b[i+1][j] = b[i][j]
	if a[-1][x2] and b[-1][y2]: print("Yes")
	else: print("No")

Buggy submission (verdict: Runtime Error):
s = input()
x,y = (int(i) for i in input().split())
f,l,dx,now,num = s.count("T"),len(s),True,0,0
ax = [[0 for i in range((l-f)*2+1)] for i in range((f+2)//2+1)]
ay = [[0 for i in range((l-f)*2+1)] for i in range(f//2+1)]
ax[0][l-f],ay[0][l-f],s = 1,1,s+"T"
for i in range(l+1):
	if s[i]=="F": num+=1
	elif dx:
		for j in range((l-f)*2+1):
			if ax[now][j]==1:
				if j-num>=0: ax[now+1][j-num]=1
				if j+num<(l-f)*2+1: ax[now+1][j+num]=1
		dx,num = False,0
	else:
		for j in range((l-f)*2+1):
			if ay[now][j]==1:
				if j-num>=0: ay[now+1][j-num]=1
				if j+num<(l-f)*2+1: ay[now+1][j+num]=1
		now,dx,num = now+1,True,0
if ax[-1][l-f+x]==1 and ay[-1][l-f+y]==1: print("Yes")
else: print("No")
Problem p03505 (python)

Fixed submission:
k,a,b = (int(i) for i in input().split())
num = k-a
if num<=0: print(1)
elif a<=b: print(-1)
else: print(((num-num%(a-b))//(a-b))*2+2*(min(1,num%(a-b)))+1)

Buggy submission (verdict: Runtime Error):
k,a,b = (int(i) for i in input().split())
num = k-a
if num<0: print(1)
elif a<b: print(-1)
else: print(((num-num%(a-b))//(a-b))*2+3)
Problem p03534 (python)

Fixed submission:
from collections import Counter
s = input()
c,x = Counter(s).most_common(),len(s)
if any(c[i][1]-x//3-1 for i in range(x%3)) or any(c[i][1]-x//3 for i in range(x%3,len(c))): print("NO")
else: print("YES")

Buggy submission (verdict: Runtime Error):
from collections import Counter
s = input()
c,x = Counter(s).most_common(),len(s)
if any(c[i][1]-x//3-1 for i in range(x%3)) or any(c[i][1]-x//3 for i in range(x%3,3)): print("NO")
else: print("YES")
Problem p03543 (python)

Fixed submission:
n = input()
if n[1]==n[2]:
	if n[0]==n[1] or n[2]==n[3]:
		print("Yes")
	else:
		print("No")
else: print("No")

Buggy submission (verdict: Runtime Error):
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1:
		y[k] = "+"
	else:
		y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")

Buggy submission (verdict: Runtime Error):
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1: y[k] = "+"
	else: y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")
Problem p03545 (python)

Fixed submission:
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = list(j)
		break
for k in range(3):
	if y[k]==1:
		y[k] = "+"
	else:
		y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")

Buggy submission (verdict: Runtime Error):
import itertools
n = input()
x, pm, a = [], [1,-1], 7-int(n[0])
for i in range(1,4):
	x.append(int(n[i]))
for j in itertools.product(pm,repeat=3):
	if x[0]*j[0]+x[1]*j[1]+x[2]*j[2]==a:
		y = j
		break
for k in range(3):
	if y[k]==1: y[k] = "+"
	else: y[k] = "-"
print(n[0]+y[0]+n[1]+y[1]+n[2]+y[2]+n[3]+"=7")
Problem p03555 (python)

Fixed submission:
a = input()
b = input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]: print("YES")
else: print("NO")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
c = c[::-1]
answer,x,y = 0,0,n-1
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(y+1):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)
Problem p03557 (python)

Fixed submission:
import bisect
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
c.sort()
answer = 0
for i in b:
	x = bisect.bisect_right(c,i)
	y = bisect.bisect_left(a,i)
	answer += (n-x)*y
print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
c = c[::-1]
answer,x,y = 0,0,n-1
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(y+1):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)