Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map (int,input().split()) 
dp = [[0 for i in range(W + 1)] for j in range(N+1)]
weight = []
value = []
for i in range(N):
    w,v = map( int, input().split() )
    weight.append(w)
    value.append(v)

for i in range(1,N+1):
    for j in range(0,W+1):
        if j - weight[i-1] >= 0:
            dp[i][j] = max( dp[i-1][ j - weight[i-1] ] + value[i-1], dp[i][j])
        dp[i][j] = max(dp[i][j],dp[i-1][j])
        
print(dp[N][W])

Fixed submission:
N,W = map (int,input().split()) 
dp = [[0 for i in range(W + 1)] for j in range(N+1)]
weight = []
value = []
for i in range(N):
    w,v = map( int, input().split() )
    weight.append(w)
    value.append(v)

for i in range(1,N+1):
    for j in range(0,W+1):
        if j - weight[i-1] >= 0:
            dp[i][j] = max( dp[i-1][ j - weight[i-1] ] + value[i-1], dp[i][j])
        dp[i][j] = max(dp[i][j],dp[i-1][j])
        
print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())
R = [[0, 0]]
L = [[0, 0]]
for i in range(N):
    x, v = map(int, input().split())
    R.append([x, v])
for i in R[::-1]:
    L.append([C - i[0], i[1]])
L.pop(-1)

R_sum = [0]
L_sum = [0]
R_sum2 = [0]
L_sum2 = [0]
total_1 = 0
total_2 = 0
total_3 = 0
total_4 = 0
for i in range(1, N + 1):
    total_1 += R[i][1] - (R[i][0] - R[i-1][0])
    total_2 += L[i][1] - (L[i][0] - L[i-1][0])
    total_3 += R[i][1] - 2*(R[i][0] - R[i-1][0])
    total_4 += L[i][1] - 2*(L[i][0] - L[i-1][0])
    R_sum.append(total_1)
    L_sum.append(total_2)
    R_sum2.append(total_3)
    L_sum2.append(total_4)
ans = 0
for i in range(N + 1):
    for j in range(N - i + 1):
        ans = max([ans, R_sum[i] + L_sum2[j], L_sum[i] + R_sum2[j]])
print(ans)

Fixed submission:
N, C = map(int, input().split())
R = [[0, 0]]
L = [[0, 0]]
R_half = -1
for i in range(N):
    x, v = map(int, input().split())
    R.append([x, v])
for i in R[::-1]:
    L.append([C - i[0], i[1]])
L.pop(-1)

R_sum = [0]
L_sum = [0]
R_sum2 = [0]
L_sum2 = [0]
total_1 = 0
total_2 = 0
total_3 = 0
total_4 = 0
for i in range(1, N + 1):
    total_1 += R[i][1] - (R[i][0] - R[i-1][0])
    total_2 += L[i][1] - (L[i][0] - L[i-1][0])
    total_3 += R[i][1] - 2*(R[i][0] - R[i-1][0])
    total_4 += L[i][1] - 2*(L[i][0] - L[i-1][0])
    R_sum.append(total_1)
    L_sum.append(total_2)
    R_sum2.append(total_3)
    L_sum2.append(total_4)
result_1 = max(R_sum)
result_2 = max(L_sum)
big_R = []
big_L = []
t = 0
p = 0
for i in range(N+1):
    t = max(t, R_sum[i])
    big_R.append(t)
    p = max(p, L_sum[i])
    big_L.append(p)
result_3 = 0
result_4 = 0
for i in range(N+1):
    result_3 = max(result_3, L_sum2[i] + big_R[N - i])
    result_4 = max(result_4, R_sum2[i] + big_L[N - i])
print(max([result_1, result_2, result_3, result_4]))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = []
T = []
A = []
for i in range(N):
    x, y = map(int, input().split())
    S.append(x)
    T.append(y)
    A.append([x, y])

ans = float("inf")
for i in S:
    for j in S:
        for k in T:
            for l in T:
                c = 0
                for x, y in A:
                    if i <= x <= j:
                        if k <= y <= l:
                            c += 1
                if c >= K:
                    ans = min(ans, (j - i)*(l - k))
print(ans)

Fixed submission:
N, K = map(int, input().split())
S = []
T = []
A = []
for i in range(N):
    x, y = map(int, input().split())
    S.append(x)
    T.append(y)
    A.append([x, y])

S.sort()
T.sort()
ans = float("inf")
for i in range(N):
    for j in range(i+1, N):
        for k in range(N):
            for l in range(k+1, N):
                c = 0
                for x, y in A:
                    if S[i] <= x <= S[j]:
                        if T[k] <= y <= T[l]:
                            c += 1
                if c >= K:
                    ans = min(ans, (S[j] - S[i])*(T[l] - T[k]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
(n,),*e=[[*map(int,i.split())]for i in open(0)]
a=sorted(e)
b=sorted(e,key=lambda x: x[1])
ans=0
for i,j in a[:10]:
    for ii,jj in b[:10]:
        ans=max(ans,abs(i-ii)+abs(j-jj))
for i,j in a[:10]:
    for ii,jj in a[10:]:
        ans=max(ans,abs(i-ii)+abs(j-jj))
for i,j in a[10:]:
    for ii,jj in b[:10]:
        ans=max(ans,abs(i-ii)+abs(j-jj))
for i,j in b[10:]:
    for ii,jj in b[:10]:
        ans=max(ans,abs(i-ii)+abs(j-jj))
print(ans)

Fixed submission:
a,b=[],[]
for _ in range(int(input())):
    x,y=map(int,input().split())
    a+=[x-y]
    b+=[x+y]
print(max(max(a)-min(a),max(b)-min(b)))
Buggy python submission (verdict: Runtime Error):
(n,m),*e=[[*map(int,i.split())]for i in open(0)]
d=[[]for i in range(n+1)]
for i,j in e:
    d[i]+=[j]
    d[j]+=[i]
print(max(len(set(d[i]+d[j]))for i in range(n+1)for j in d[i]))

Fixed submission:
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x == y:
        return 0
    if x<y:x,y=y,x    
    par[x]=y
n,m=map(int,input().split())
par=[i for i in range(n+1)]
for _ in range(m):
    i,j=map(int,input().split())
    unite(i,j)
ans=[0]*(n+1)
for i in range(n+1):
    find(i)
for i in par:
    ans[i]+=1
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)];a,b=[0]*h,[0]*w
for y,x in e:a[y-1]+=1;b[x-1]+=1
print(max(a)+max(b)-(a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==max(a)+max(b)for y,x in e)<=0))

Fixed submission:
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a,b=[0]*h,[0]*w
for y,x in e:
    a[y-1]+=1
    b[x-1]+=1
ans=max(a)+max(b)
c=a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==ans for y,x in e)
print(ans-(c<=0))

Buggy python submission (verdict: Runtime Error):
import numpy as np
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a=np.zeros((h,w),int)
for y,x in e:a[y-1][x-1]=1
y=np.sum(a,axis=1)
x=np.sum(a,axis=0)
mx,my=max(x),max(y)
# b=sum(y[i-1]+x[j-1]==mx+my for i,j in e)
# b-=len(np.where(y==my)[0])*len(np.where(x==mx)[0])
print(mx+my)

Fixed submission:
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a,b=[0]*h,[0]*w
for y,x in e:
    a[y-1]+=1
    b[x-1]+=1
ans=max(a)+max(b)
c=a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==ans for y,x in e)
print(ans-(c<=0))

Buggy python submission (verdict: Runtime Error):
import numpy as np
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a=np.zeros((h,w),int)
for y,x in e:a[y-1][x-1]=1
y=np.sum(a,axis=1)
x=np.sum(a,axis=0)
mx,my=max(x),max(y)
b=sum(y[i-1]+x[j-1]==mx+my for i,j in e)
b-=len(np.where(y==my)[0])*len(np.where(x==mx)[0])
print(mx+my-(b>=0))

Fixed submission:
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a,b=[0]*h,[0]*w
for y,x in e:
    a[y-1]+=1
    b[x-1]+=1
ans=max(a)+max(b)
c=a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==ans for y,x in e)
print(ans-(c<=0))

Buggy python submission (verdict: Runtime Error):
import numpy as np
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a=np.zeros((h,w),int)
for y,x in e:
    a[y-1][x-1]=1
y=np.sum(a,axis=1)
x=np.sum(a,axis=0)
ans=max(y)+max(x)
b=sum(y[i-1]+x[j-1]==ans for i,j in e)
b-=len(np.where(y==max(y))[0])*len(np.where(x==max(x))[0])
print(ans-(b>=0))

Fixed submission:
(h,w,m),*e=[[*map(int,i.split())]for i in open(0)]
a,b=[0]*h,[0]*w
for y,x in e:
    a[y-1]+=1
    b[x-1]+=1
ans=max(a)+max(b)
c=a.count(max(a))*b.count(max(b))-sum(a[y-1]+b[x-1]==ans for y,x in e)
print(ans-(c<=0))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=[int(i)-1for i in input().split()]
c=list(map(int,input().split()))
ans=-10**9
for i in range(n):
    start=i
    cycle=[0]
    for _ in range(n):
        i=p[i]
        cycle+=[cycle[-1]+c[i]]
        if i==start:break
    S,L=cycle[-1],len(cycle)-1
    if S<0:ans=max(ans,max(cycle[1:k]))
    else:ans=max(ans,k//L*S+max(cycle[:k%L+1]))
print(ans)

Fixed submission:
a=[0]
for i in input():
    if i=="R":a+=[a[-1]+1]
    else:a+=[0]
print(max(a))
Buggy python submission (verdict: Runtime Error):
import numpy as np

h,w,k=map(int,input().split())
a=[input() for _ in range(h)]
b=[]
for i in a:
    b+=[[1 if j=="#" else 0 for j in i]]
c=np.array(b)
print(c)
ans=0
for i in range(2**(h*w)):
    for j in range(h*w):
        d=c.copy()
        if ((i>>j)&1):
            if j<=h:
                d[j]=0
            else:
                d[:,j-h]=0
        if np.sum(d)==k:
            ans+=1
print(ans)

Fixed submission:
h,w,k=map(int,input().split())
a=[input() for _ in range(h)]
ans=0
for H in range(2**h):
    for W in range(2**w):
        c=0
        for i in range(h):
            for j in range(w):
                if H>>i&1 and W>>j&1 and a[i][j]=="#":
                    c+=1
        if c==k:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n+1):
    a=i
    for j in range(2,1+int(i**.5)):
        b=0
        while i%j==0:
            i//=j
            b+=1
        a*=b+1
        if i==1:
            break
    if i!=1:
        a*=2
    ans+=a
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    a=n//i
    ans+=i*a*(a+1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n+1):
    a=i
    for j in range(2,1+int(i**.5)):
        b=0
        while i%j==0:
            i//=j
            b+=1
        a*=b+1
    if i!=1:
        a*=2
    ans+=a
print(ans)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    a=n//i
    ans+=i*a*(a+1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
x,n,*a=map(int,open(0).read().split())
b=[1]*101
for i in a:
    b[i]=0
c=1000 
ans=n
for i in range(102):
    if b[i] and c>abs(x-i):
        c=abs(x-i)
        ans=i
print(ans)

Fixed submission:
x,n,*a=map(int,open(0).read().split())
b=[1]*103
for i in a:
    b[i]=0
c=1000 
ans=n
for i in range(102):
    if b[i] and c>abs(x-i):
        c=abs(x-i)
        ans=i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
a.sort()
b=[0]*(10**6+1)
for i in a:
    b[i]+=1
    for j in range(2*i,10**6+1,i):
        b[j]+=2
print(b.count(1))

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
b=[0]*(10**6+1)
for i in a:
    b[i]+=1
    if b[i]==1:
        for j in range(2*i,10**6+1,i):
            b[j]+=100
print(b.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
n,*a=map(int,open(0).read().split())
ans=1
for i in a:
    ans*=i
if ans>10**18:
    ans=-1
print(ans) 

Fixed submission:
n,*a=map(int,open(0).read().split())
if 0 in a:
    print(0)
    exit()
ans=1
for i in a:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
if n%2==0:
    print(r-q+1+e-w)
else:
    print(r-q+1)

Fixed submission:
n=int(input())
a,b=[],[]
for _ in range(n):
    i,j=map(int,input().split())
    a+=[i]
    b+=[j]
a.sort()
b.sort()
c=n//2
if n%2==1:
    print(b[c]-a[c]+1)
else:
    print(b[c]-a[c]+b[c-1]-a[c-1]+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
if n%2==0:
    print(max(w-q,r-e)+1)
else:
    print(r-q+1)

Fixed submission:
n=int(input())
a,b=[],[]
for _ in range(n):
    i,j=map(int,input().split())
    a+=[i]
    b+=[j]
a.sort()
b.sort()
c=n//2
if n%2==1:
    print(b[c]-a[c]+1)
else:
    print(b[c]-a[c]+b[c-1]-a[c-1]+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
# if w<=e:
#     print(max(w-q,r-e)+1)
# else:
print(r-q+1)

Fixed submission:
n=int(input())
a,b=[],[]
for _ in range(n):
    i,j=map(int,input().split())
    a+=[i]
    b+=[j]
a.sort()
b.sort()
c=n//2
if n%2==1:
    print(b[c]-a[c]+1)
else:
    print(b[c]-a[c]+b[c-1]-a[c-1]+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]
c.sort()
q,w=c[n//2][0],min(c[n//2][1],c[n//2+1][1])
c.sort(key=lambda x: x[1])
e,r=max(c[n//2][0],c[n//2-1][1]),c[n//2][1]
if w<=e:
    print(max(w-q,r-e)+1)
else:
    print(r-q+1)

Fixed submission:
n=int(input())
a,b=[],[]
for _ in range(n):
    i,j=map(int,input().split())
    a+=[i]
    b+=[j]
a.sort()
b.sort()
c=n//2
if n%2==1:
    print(b[c]-a[c]+1)
else:
    print(b[c]-a[c]+b[c-1]-a[c-1]+1)
Buggy python submission (verdict: Runtime Error):
print("Yes" if input()==input()[:-1])

Fixed submission:
a=input()
b=input()
print("Yes" if a==b[:-1] and len(a)+1==len(b) else "No")
Buggy python submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
t=[list(map(int,input().split())) for _ in range(q)]
ans=0
import itertools
for p in itertools.permutations(range(1,m+1),m-n):
    a=[]
    for i in range(1,m+1):
        if i not in p:
            a+=[i]
    d=0
    for i in t:
        if a[i[1]-1]-a[i[0]-1]==i[2]:
            d+=i[3]
    ans=max(d,ans)        
print(ans) 

Fixed submission:
n,m,q=map(int,input().split())
t=[list(map(int,input().split())) for _ in range(q)]
ans=0
import itertools
for p in itertools.combinations_with_replacement(range(1,m+1),n):
    d=0
    for i in t:
        if p[i[1]-1]-p[i[0]-1]==i[2]:
            d+=i[3]
    ans=max(d,ans)        
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
m=0
for i in range(1,n+1,n-1):
    c=a*i//b-a*(i//b)
    if c>=m:
        m=c
    # print((a*i)//b,a*(i//b),a*i//b-a*(i//b))
print(m) 

Fixed submission:
a,b,n=map(int,input().split())
if b-1<=n:
    i=b-1
else:
    i=n
print(a*i//b-a*(i//b))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int,input().split())
m=0
d=1
if n>=10**5:
    d=2
for i in range(1,n+1,d):
    c=a*i//b-a*(i//b)
    if c>=m:
        m=c
    # print((a*i)//b,a*(i//b),a*i//b-a*(i//b))
print(m) 

Fixed submission:
a,b,n=map(int,input().split())
if b-1<=n:
    i=b-1
else:
    i=n
print(a*i//b-a*(i//b))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,n=map(int,input().split())
m=0
d=1
if n>=10**6:
    d=2
for i in range(1,n+1,d):
    c=a*i//b-a*(i//b)
    if c>=m:
        m=c
    # print((a*i)//b,a*(i//b),a*i//b-a*(i//b))
print(m)

Fixed submission:
a,b,n=map(int,input().split())
if b-1<=n:
    i=b-1
else:
    i=n
print(a*i//b-a*(i//b))
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print("Yes" if -c//b>=-a//d else "No")a,b,c,d=map(int,input().split())
print("Yes" if -c//b>=-a//d else "No")

Fixed submission:
a,b,c,d=map(int,input().split())
for _ in range(100):
    a-=d
    c-=b
    if c<1:
        print("Yes")
        exit()
    if a<1:
        print("No")
        exit()

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
for _ in range(100):
    a,c-=d,b
    if b<1:
        print("Yes")
        exit()
    if a<1:
        print("No")
        exit()

Fixed submission:
a,b,c,d=map(int,input().split())
for _ in range(100):
    a-=d
    c-=b
    if c<1:
        print("Yes")
        exit()
    if a<1:
        print("No")
        exit()
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            a+=g[g[i][j]][k]
print(a)

Fixed submission:
from math import *
g=[[0]*202 for _ in range(202)]
for i in range(1,201):
    for j in range(1,201):
        g[i][j]=gcd(i,j)
n=int(input())
a=0
for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            a+=g[g[i][j]][k]
print(a)
Buggy python submission (verdict: Runtime Error):
x,y,A,B,C,*a=map(int,open(0).read().split())
a,b,c=a[:A],a[A:A+B],a[A+B:]
a.sort()
b.sort()
c.sort()
a,b=a[A-x:],b[B-y:]
d,e,f=a[0],b[0],c[-1]
D=E=0
F=-1
for _ in range(min(C,x+y)):
    if f>e>=d:
        a[D]=f
        D+=1
        d=a[D]
    elif f>d>=e:
        b[E]=f
        E+=1
        e=b[F]
    elif e>f>=d:
        a[D]=f
        D+=1
        d=a[D]
    elif d>f>=e:
        b[E]=f
        E+=1
        e=b[F]
    else:break   
    F-=1
    if F!=-C-1:
        f=c[F]    
print(sum(a+b))

Fixed submission:
x,y,a,b,c=map(int,input().split())
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]
p.sort()
q.sort()
p=p[-x:]
q=q[-y:]
s=p+q+r
s.sort()
print(sum(s[-x-y:]))
Buggy python submission (verdict: Runtime Error):
s=input()
q=int(input())
i=0
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        i+=1
    else:
        if a[1]=="1" and i%2==1:
            z=z+a[3]
        elif a[1]=="1" and i%2==0:     
            x=a[2]+x
        elif a[1]=="2" and i%2==1:  
            x=x+a[3]
        else:
            z=z+a[3]
print(z[::-1]+s[::-1]+x[::-1] if i%2 else x+s+z)

Fixed submission:
s=input()
q=int(input())
i=0
x=z=""
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        i+=1
    else:
        if a[1]=="1" and i%2==1:
            z=z+a[2]
        elif a[1]=="1" and i%2==0:     
            x=a[2]+x
        elif a[1]=="2" and i%2==1:  
            x=a[2]+x
        else:
            z=z+a[2]
print(z[::-1]+s[::-1]+x[::-1] if i%2 else x+s+z)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
x=y=z=""
i=0
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        i+=1
        x,z=z[::-1],x[::-1]
    else:
        if a[1]=="1":x="".join([a[2],x])
        else:z="".join([z,a[2]])
print(x+s[::-1]+z if i%2 else x+s+z)

Fixed submission:
s=input()
q=int(input())
i=0
x=z=""
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        i+=1
    else:
        if a[1]=="1" and i%2==1:
            z=z+a[2]
        elif a[1]=="1" and i%2==0:     
            x=a[2]+x
        elif a[1]=="2" and i%2==1:  
            x=a[2]+x
        else:
            z=z+a[2]
print(z[::-1]+s[::-1]+x[::-1] if i%2 else x+s+z)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        s=s[::-1]
    else:
        if a[1]=="1":s=a[2]+s
        else:s=s+a[2]
print(s)

Fixed submission:
s=input()
q=int(input())
i=0
x=z=""
for _ in range(q):
    a=list(input().split())
    if a[0]=="1":
        i+=1
    else:
        if a[1]=="1" and i%2==1:
            z=z+a[2]
        elif a[1]=="1" and i%2==0:     
            x=a[2]+x
        elif a[1]=="2" and i%2==1:  
            x=a[2]+x
        else:
            z=z+a[2]
print(z[::-1]+s[::-1]+x[::-1] if i%2 else x+s+z)
Buggy python submission (verdict: Time Limit Exceeded):
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*(2*10**4+1)
c.sort()
dp[0]=0
for i in range(h):
    for a,b in c:
        if i+a<=2*10**4:
            dp[i+a]=min(dp[i+a],dp[i]+b)
        else:break    
print(min(dp[h:]))

Fixed submission:
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*(2*10**4+1)
c.sort()
dp[0]=0
for i in range(h):
    for a,b in c:
        if i+a<=2*10**4:
            dp[i+a]=min(dp[i+a],dp[i]+b)
        else:break    
print(min(dp[h:]))

Buggy python submission (verdict: Runtime Error):
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*h**3
dp[0]=0
for i in range(h):
    for a,b in c:
        dp[i+a]=min(dp[i+a],dp[i]+b)
print(min(dp[h:]))

Fixed submission:
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*(2*10**4+1)
c.sort()
dp[0]=0
for i in range(h):
    for a,b in c:
        if i+a<=2*10**4:
            dp[i+a]=min(dp[i+a],dp[i]+b)
        else:break    
print(min(dp[h:]))

Buggy python submission (verdict: Runtime Error):
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*h*2
dp[0]=0
for i in range(h):
    for a,b in c:
        dp[i+a]=min(dp[i+a],dp[i]+b)
print(min(dp[h:]))

Fixed submission:
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
dp=[10**9]*(2*10**4+1)
c.sort()
dp[0]=0
for i in range(h):
    for a,b in c:
        if i+a<=2*10**4:
            dp[i+a]=min(dp[i+a],dp[i]+b)
        else:break    
print(min(dp[h:]))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=[0]*(n+1)
for _ in range(m):
    i,j=input().split()
    i=int(i)
    if j=="AC":
        ac[i]=1
    elif ac[i]==0 and j=="WA":
        wa[i]+=1
print(sum(ac),sum(wa[i] for i in range(m) if ac[i]==1))    

Fixed submission:
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=[0]*(n+1)
for _ in range(m):
    i,j=input().split()
    i=int(i)
    if j=="AC":
        ac[i]=1
    elif ac[i]==0 and j=="WA":
        wa[i]+=1
print(sum(ac),sum(wa[i] for i in range(n+1) if ac[i]==1))
Buggy python submission (verdict: Time Limit Exceeded):
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
b*=(2**c[0])    
print(0 if b//2>m else (m-b//2)//b+1)  

Fixed submission:
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
    if b*(2**c[0])>2*m:
        print(0)
        exit()
b*=2**c[0]    
print(0 if b//2>m else (m-b//2)//b+1)

Buggy python submission (verdict: Runtime Error):
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
b=a[0]*a[1]// fractions.gcd(a[0], a[1])
for i in a:
    b=lcm(i,b)
print(0 if b//2>m else (m-b//2)//b+1)  

Fixed submission:
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
    if b*(2**c[0])>2*m:
        print(0)
        exit()
b*=2**c[0]    
print(0 if b//2>m else (m-b//2)//b+1)

Buggy python submission (verdict: Runtime Error):
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n,m,*a=map(int,open(0).read().split())
a=list(set(a))
b=a[0]*a[1]// fractions.gcd(a[0], a[1])
for i in a:
    b=lcm(i,b)
print(0 if b//2>m else (m-b//2)//b+1)  

Fixed submission:
def f(n):
    a=0
    while n%2==0:
        n//=2
        a+=1
    return a    
n,m,*a=map(int,open(0).read().split())
c=[f(i) for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
a=[i//(2**c[0]) for i in a]
b=a[0]
for i in a:
    b=lcm(i,b)
    if b*(2**c[0])>2*m:
        print(0)
        exit()
b*=2**c[0]    
print(0 if b//2>m else (m-b//2)//b+1)