Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def dfs(l,d,k):
  for i in l[k]:
    if d[i[0]]==-1:
      d[i[0]]=d[k]+i[1]
      dfs(l,d,i[0])

n=int(input())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  l[a-1].append([b-1,c])
  l[b-1].append([a-1,c])
q,k=map(int,input().split())
d=[-1 for i in range(n)]
d[k-1]=0
dfs(l,d,k-1)
L=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print(d[L[i][0]-1]+d[L[i][1]-1])

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

def dfs(l,d,k):
  for i in l[k]:
    if d[i[0]]==-1:
      d[i[0]]=d[k]+i[1]
      dfs(l,d,i[0])

n=int(input())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  l[a-1].append([b-1,c])
  l[b-1].append([a-1,c])
q,k=map(int,input().split())
d=[-1 for i in range(n)]
d[k-1]=0
dfs(l,d,k-1)
L=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print(d[L[i][0]-1]+d[L[i][1]-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
c=0
for j in range(n):
  if [j,1] in l or [1,j] in l:
    if [j,n] in l or [n,j] in l:
      c+=1
      break
if c==1:print('POSSIBLE')
else:print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
L=[];l=[]
for k in range(n):
  L.append(0)
for i in range(m):
  x=list(map(int,input().split()))
  l.append(x)
  if x[0]==1:
    L[x[1]]+=1
  if x[1]==1:
    L[x[0]]+=1
  if x[0]==n:
    L[x[1]]+=1
  if x[1]==n:
    L[x[0]]+=1
if max(L)==2:print('POSSIBLE')
else:print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
L=[]
for j in range(m):
  if l[j][0]==1:L.append(l[j][1])
  if l[j][1]==1:L.append(l[j][0])
c=0
for k in range(len(L)):
  if c!=0:
    break
  for j in range(m):
    if L[k]==l[j][0] and l[j][1]==n:
      c+=1
      break
    if L[k]==l[j][1] and l[j][0]==n:
      c+=1
      break
if c==1:print('POSSIBLE')
else:print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
L=[];l=[]
for k in range(n):
  L.append(0)
for i in range(m):
  x=list(map(int,input().split()))
  l.append(x)
  if x[0]==1:
    L[x[1]]+=1
  if x[1]==1:
    L[x[0]]+=1
  if x[0]==n:
    L[x[1]]+=1
  if x[1]==n:
    L[x[0]]+=1
if max(L)==2:print('POSSIBLE')
else:print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
g=gcd(a[0],a[1])
for j in range(1,n):
  g=gcd(g,a[j])
m=max(a)
if k<=m and k%g==0:print('POSSIBLE')
else:print('IMPOSSIBLE')

Fixed submission:
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n>=2:
  g=gcd(a[0],a[1])
  for j in range(1,n):
    g=gcd(g,a[j])
  m=max(a)
  if k<=m and k%g==0:print('POSSIBLE')
  else:print('IMPOSSIBLE')
else:
  if a[0]==k:print('POSSIBLE')
  else:print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:
    c=1
    break
if c=1:print(2**(n-1))
else:
  if p=0:print(2**(n))
  else:print(0)

Fixed submission:
n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:c+=1
if c==0:
  if p==0:print(2**n)
  else:print(0)
elif c==n:
  if n!=1:print(2**(n-1))
  else:print(0)
else:print(2**(n-1))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
L=[]
for i in range(n):
  if i%2==n%2:L.append(l[i])
  else:L.insert(0,l[i])
for j in range(n):
  print(L[j],end=' ')

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l1=[];l2=[]
for i in range(n):
  if i%2==n%2:l1.append(l[i])
  else:l2.append(l[i])
l2.reverse()
for j in range(len(l1)):
  l2.append(l1[j])
for j in range(n):
  print(l2[j],end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1;d=[b]
while b!=2 and b!=1 and len(set(d))==len(d):
  b=a[b-1]
  c+=1
  d.append(b)
if b==2:print(c)
else:print(-1)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1;d=[b]
while b!=2 and len(set(d))==len(d):
  b=a[b-1]
  c+=1
  d.append(b)
if b==2:print(c)
else:print(-1)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1;d=[a[0]]
while (not b==2) and (len(set(d))==len(d)):
  b=a[b-1]
  c+=1
  d.append(b)
if b==2:print(c)
else:print(-1)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1;d=[a[0]]
while not (b==1 or b==2) and (len(set(d))==len(d)):
  b=a[b-1]
  c+=1
  d.append(b)
if b==2:print(c)
else:print(-1)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while not (b==1 or b==2):
  c+=1
  b=a[b-1]
if b==1:print(-1)
else:print(c)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[0];c=1
while b!=2 and c<=n:
  b=a[b-1]
  c+=1
if b==2:print(c)
else:print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(9)]
for j in range(n):
  l[a[j]//400]+=1
c=0
for k in range(len(l)-1):
  if l[k]>0:c+=1
print(c,c+l[8])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(9)]
for j in range(n):
  l[min(a[j],3200)//400]+=1
c=0
for k in range(len(l)-1):
  if l[k]>0:c+=1
if c==0:print(1,c+l[8])
else:print(c,c+l[8])
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if a>b:print(0)
elif n==1 and a!=b:print(0)
else:print((n-2)*(b-a)+1)​

Fixed submission:
n,a,b=map(int,input().split())
if a>b or (n==1 and a!=b):print(0)
else:print((n-2)*(b-a)+1)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  l[i].sort()

ans=[]
l.sort()
B1=[];R1=[]
for i in range(n):
  B1.append(max(l[i]))
  R1.append(min(l[i]))
ans.append((max(B1)-min(B1))*(max(R1)-min(R1)))

Bleft=[]
Bright=[]
Rleft=[]
Rright=[]

M=B1[0];m=B1[0]
Bleft.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bleft.append([m,M])

B1.reverse()
M=B1[0];m=B1[0]
Bright.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bright.append([m,M])

M=R1[0];m=R1[0]
Rleft.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rleft.append([m,M])

R1.reverse()
M=R1[0];m=R1[0]
Rright.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rright.append([m,M])

for i in range(n-1):
  M1=max(Bleft[i][1],Rright[n-2-i][1])
  m1=min(Bleft[i][0],Rright[n-2-i][0])
  M2=max(Rleft[i][1],Bright[n-2-i][1])
  m2=min(Rleft[i][0],Bright[n-2-i][0])
  ans.append((M1-m1)*(M2-m2))

print(min(ans))

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  l[i].sort()

ans=[]
l.sort()
B1=[];R1=[]
for i in range(n):
  B1.append(max(l[i]))
  R1.append(min(l[i]))
ans.append((max(B1)-min(B1))*(max(R1)-min(R1)))

Bleft=[]
Bright=[]
Rleft=[]
Rright=[]

M=B1[0];m=B1[0]
Bleft.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bleft.append([m,M])

B1.reverse()
M=B1[0];m=B1[0]
Bright.append([m,M])
for i in range(1,n):
  M=max(M,B1[i])
  m=min(m,B1[i])
  Bright.append([m,M])

M=R1[0];m=R1[0]
Rleft.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rleft.append([m,M])

R1.reverse()
M=R1[0];m=R1[0]
Rright.append([m,M])
for i in range(1,n):
  M=max(M,R1[i])
  m=min(m,R1[i])
  Rright.append([m,M])

for i in range(n-1):
  M1=max(Bleft[i][1],Rright[n-2-i][1])
  m1=min(Bleft[i][0],Rright[n-2-i][0])
  M2=max(Rleft[i][1],Bright[n-2-i][1])
  m2=min(Rleft[i][0],Bright[n-2-i][0])
  ans.append((M1-m1)*(M2-m2))

print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i])

ct1=0
if a[0]<=0:
  a[0]=1
  ct1+=1-a[0]
for i in range(1,n):
  if i%2==1:
    if sum(a[0:i+1])>=0:
      ct1+=sum(a[0:i+1])+1
      a[i]=-sum(a[0:i])-1
  else:
    if sum(a[0:i+1])<=0:
      ct1+=1-sum(a[0:i+1])
      a[i]=-sum(a[0:i])+1

ct2=0
if b[0]>=0:
  b[0]=-1
  ct2+=b[0]-1
for i in range(1,n):
  if i%2==0:
    if sum(b[0:i+1])>=0:
      ct2+=sum(b[0:i+1])+1
      b[i]=-sum(b[0:i])-1
  else:
    if sum(b[0:i+1])<=0:
      ct2+=1-sum(b[0:i+1])
      b[i]=-sum(b[0:i])+1

print(min(ct1,ct2))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i])

ct1=0
if a[0]<=0:
  ct1+=1-a[0]
  a[0]=1
x=a[0]
for i in range(1,n):
  y=x+a[i]
  if i%2==1:
    if y>=0:
      ct1+=y+1
      a[i]=-x-1
  else:
    if y<=0:
      ct1+=1-y
      a[i]=-x+1
  x+=a[i]

ct2=0
if b[0]>=0:
  ct2+=b[0]+1
  b[0]=-1
x=b[0]
for i in range(1,n):
  y=x+b[i]
  if i%2==0:
    if y>=0:
      ct2+=y+1
      b[i]=-x-1
  else:
    if y<=0:
      ct2+=1-y
      b[i]=-x+1
  x+=b[i]

print(min(ct1,ct2))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
a=list(map(int,input().split()))
b=copy.copy(a)

ct1=0
if a[0]<=0:
  a[0]=1
  ct1+=1-a[0]
for i in range(1,n):
  if i%2==1:
    if sum(a[0:i+1])>=0:
      ct1+=sum(a[0:i+1])+1
      a[i]=-sum(a[0:i])-1
  else:
    if sum(a[0:i+1])<=0:
      ct1+=1-sum(a[0:i+1])
      a[i]=-sum(a[0:i])+1

ct2=0
if b[0]>=0:
  b[0]=-1
  ct2+=b[0]-1
for i in range(1,n):
  if i%2==0:
    if sum(b[0:i+1])>=0:
      ct2+=sum(b[0:i+1])+1
      b[i]=-sum(b[0:i])-1
  else:
    if sum(b[0:i+1])<=0:
      ct2+=1-sum(b[0:i+1])
      b[i]=-sum(b[0:i])+1

print(min(ct1,ct2))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  b.append(a[i])

ct1=0
if a[0]<=0:
  ct1+=1-a[0]
  a[0]=1
x=a[0]
for i in range(1,n):
  y=x+a[i]
  if i%2==1:
    if y>=0:
      ct1+=y+1
      a[i]=-x-1
  else:
    if y<=0:
      ct1+=1-y
      a[i]=-x+1
  x+=a[i]

ct2=0
if b[0]>=0:
  ct2+=b[0]+1
  b[0]=-1
x=b[0]
for i in range(1,n):
  y=x+b[i]
  if i%2==0:
    if y>=0:
      ct2+=y+1
      b[i]=-x-1
  else:
    if y<=0:
      ct2+=1-y
      b[i]=-x+1
  x+=b[i]

print(min(ct1,ct2))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[];c=1;d=[]
for i in range(1,n):
  b.append(a[i]-a[i-1])
for j in range(1,n-1):
  if b[j]*b[j-1]<0 and j-1 not in d:
    c+=1
    d.append(j)
print(c)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[];c=1;d=-1
for i in range(1,n):
  if a[i]-a[i-1]<0:b.append(-1)
  elif a[i]-a[i-1]>0:b.append(1)
for j in range(1,len(b)):
  if b[j]*b[j-1]<0 and d!=j-1:
    c+=1
    d=j
print(c)
Buggy python submission (verdict: Runtime Error):
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
if a==n:
  print(sum(v)/n)
  print(1)
elif v[a-1]!=v[a]:
  print(sum(v[0:a])/a)
  print(1)
elif v[0]!=v[a-1]:
  print(sum(v[0:a])/a)
  ct1=0;ct2=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
      if i<a:
        ct2+=1
  print(math.factorial(ct1)//(math.factorial(ct1-ct2)*math.factorial(ct2)))
else:
  print(sum(v[0:a])/a)
  ct1=0;ans=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
  for i in range(a,b+1):
    ans+=math.factorial(ct1)//(math.factorial(ct1-i)*math.factorial(i))
  print(ans)

Fixed submission:
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
if a==n:
  print(sum(v)/n)
  print(1)
elif v[a-1]!=v[a]:
  print(sum(v[0:a])/a)
  print(1)
elif v[0]!=v[a-1]:
  print(sum(v[0:a])/a)
  ct1=0;ct2=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
      if i<a:
        ct2+=1
  print(math.factorial(ct1)//(math.factorial(ct1-ct2)*math.factorial(ct2)))
else:
  print(sum(v[0:a])/a)
  ct1=0;ans=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
  for i in range(a,min(ct1+1,b+1)):
    ans+=math.factorial(ct1)//(math.factorial(ct1-i)*math.factorial(i))
  print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(1,m):
        if b[r]!=a[p+r][q:q+m]:break
       c=1
       break
if c==0:print('No')
else:print('Yes')

Fixed submission:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0;d=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(m):
        if b[r]!=a[p+r][q:q+m]:d+=1
      if d==0:c=1
      else:d=0
if c==0:print('No')
else:print('Yes')

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(n-m+1):
        if b[r]!=a[p+r][q-m+1:q]:pass
        else:break
        c=1
if c==1:print('Yes')
else:print('No')

Fixed submission:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0;d=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(m):
        if b[r]!=a[p+r][q:q+m]:d+=1
      if d==0:c=1
      else:d=0
if c==0:print('No')
else:print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[[99999999 for i in range(n)] for i in range(n)]
for i in range(n):
  distance[i][i]=0
for i in range(m):
  distance[l[i][0]-1][l[i][1]-1]=l[i][2]
  distance[l[i][1]-1][l[i][0]-1]=l[i][2]

for k in range(n):
  for i in range(n):
    for j in range(n):
      distance[i][j]=min(distance[i][k]+distance[k][j],distance[i][j])

ct=m
for k in range(m):
  for i in range(n):
    for j in range(n):
      if i!=j:
        if distance[i][j]==distance[i][l[k][0]-1]+l[k][2]+distance[l[k][1]-1][j]:
          ct-=1
          break
    else:
      continue
    break
print(ct)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[[99999999 for i in range(n)] for i in range(n)]
for i in range(n):
  distance[i][i]=0
for i in range(m):
  distance[l[i][0]-1][l[i][1]-1]=l[i][2]
  distance[l[i][1]-1][l[i][0]-1]=l[i][2]

for k in range(n):
  for i in range(n):
    for j in range(n):
      distance[i][j]=min(distance[i][k]+distance[k][j],distance[i][j])

ct=m
for k in range(m):
  for i in range(n):
    for j in range(n):
      if i!=j:
        if distance[i][j]==distance[i][l[k][0]-1]+l[k][2]+distance[l[k][1]-1][j]:
          ct-=1
          break
    else:
      continue
    break
print(ct)
Buggy python submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[];a2=[];a3=[];a4=[]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)

Fixed submission:
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a1=[0];a2=[w];a3=[0];a4=[h]
for i in a:
  if i[2]==1:a1.append(i[0])
  else:pass
for i in a:
  if i[2]==2:a2.append(i[0])
  else:pass
for i in a:
  if i[2]==3:a3.append(i[1])
  else:pass
for i in a:
  if i[2]==4:a4.append(i[1])
  else:pass
if max(a1)-min(a2)<0:x=max(a1)-min(a2)
else:x=0
if max(a3)-min(a4)<0:y=max(a3)-min(a4)
else:y=0
print(x*y)
Buggy python submission (verdict: Runtime Error):
s=input()
x=0;y=0
for i in range(len(s)):
  if s[i]=='C':
    x=i+1
    break
for j in range(len(s)):
  if s[j]=='F':
    y=j+1
if x*y!=0 and x<y:print('Yes')
else:print('No')​

Fixed submission:
s=input()
x=0;y=0
for i in range(len(s)):
  if s[i]=='C':
    x=i+1
    break
for j in range(len(s)):
  if s[j]=='F':
    y=j+1
if x*y!=0 and x<y:print('Yes')
else:print('No')
Buggy python submission (verdict: Runtime Error):
a,b,c=(list(input()) for x in range(3))
n=a.pop(0)
while not len(a)==0 or len(b)==0 or len(c)==0:
   if n=='a':
      n=a.pop(0)
   elif n=='b':
      n=b.pop(0)
   else:
      n=c.pop(0)
if a=='':print('A')
elif b=='':print('B')
else:print('C')

Fixed submission:
a,b,c=(list(input()) for x in range(3))
n=a.pop(0)
while not ((len(a)==0 and n=='a') or (len(b)==0 and n=='b') or (len(c)==0 and n=='c')):
   if n=='a':n=a.pop(0)
   elif n=='b':n=b.pop(0)
   else:n=c.pop(0)
if n=='a':print('A')
elif n=='b':print('B')
else:print('C')
Buggy python submission (verdict: Time Limit Exceeded):
n,a=map(int,input().split())
x=list(map(int,input().split()))
m=max(x)
L3=[]
for i3 in range(n+1):
  L2=[]
  for i2 in range(n+1):
    L1=[0 for i1 in range(n*m+1)]
    L2.append(L1)
  L3.append(L2)
for i3 in range(n+1):
  for i2 in range(n+1):
    for i1 in range(m*n+1):
      if i1==0 and i2==0 and i3==0:
        L3[i3][i2][i1]=1
      elif i3>0 and i1<x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]
      elif i3>0 and i2>0 and i1>=x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]+L3[i3-1][i2-1][i1-x[i3-1]]
      else:
        L3[i3][i2][i1]=0
ct=0
for i2 in range(n+1):
  for i1 in range(1,m*n+1):
    if i1==i2*a:
      ct+=L3[n][i2][i1]
print(ct)

Fixed submission:
n,a=map(int,input().split())
x=list(map(int,input().split()))
m=max(x)
L3=[]
for i3 in range(n+1):
  L2=[]
  for i2 in range(n+1):
    L1=[0 for i1 in range(n*m+1)]
    L2.append(L1)
  L3.append(L2)
for i3 in range(n+1):
  for i2 in range(n+1):
    for i1 in range(m*n+1):
      if i1==0 and i2==0 and i3==0:
        L3[i3][i2][i1]=1
      elif i3>0 and i1<x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]
      elif i3>0 and i2>0 and i1>=x[i3-1]:
        L3[i3][i2][i1]=L3[i3-1][i2][i1]+L3[i3-1][i2-1][i1-x[i3-1]]
      else:
        L3[i3][i2][i1]=0
ct=0
for i2 in range(n+1):
  for i1 in range(1,m*n+1):
    if i1==i2*a:
      ct+=L3[n][i2][i1]
print(ct)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
d=list(map(int,input().split()))
l=[0,1,2,3,4,5,6,7,8,9]
for i in range(k):
  l.remove(d[i])
L=[]
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        L.append(l[j1]*1000+l[j2]*100+l[j3]*10+l[j4])
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Fixed submission:
n,k=map(int,input().split())
d=list(map(int,input().split()))
l=[0,1,2,3,4,5,6,7,8,9]
for i in range(k):
  l.remove(d[i])
L=[]
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        for j5 in range(len(l)):
          L.append(l[j1]*10000+l[j2]*1000+l[j3]*100+l[j4]*10+l[j5])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        L.append(l[j1]*1000+l[j2]*100+l[j3]*10+l[j4])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      L.append(l[j1]*100+l[j2]*10+l[j3])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    L.append(l[j1]*10+l[j2])
for j1 in range(len(l)):
  L.append(l[j1])
L.sort()
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
readline = sys.stdin.buffer.readline


n = int(readline())
a = list(map(int,readline().split()))

cnt = np.zeros(1000005)
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)

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

cnt = [0] * 1000005
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)

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

cnt = [0] * 40
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,40,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1
        
print(ans)

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

cnt = [0] * 1000005
for x in a:
    if cnt[x] != 0: 
        cnt[x] = 2
    else: 
        for i in range(x,1000005,x):
            cnt[i] += 1

ans = 0
for x in a:
    if cnt[x] == 1:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
class SEGTree:
    def __init__(self,n,op,e):
        self.Unit=e
        self.Op=op
        i=1<<(n.bit_length()-1)
        if i!=n:
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.Op(self.SEG[i*2+1],self.SEG[i*2+2])
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return self.Op(c1,c2)
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)

INF=10**30
N,K=map(int,input().split())
A=[int(input()) for i in range(N)]
M=max(A)
SEG=SEGTree(M+1,max,0)

ans=0
for i in range(N):
    l=max(0,A[i]-K)
    r=min(M,A[i]+K)
    res=SEG.get(l,r+1)
    ans=max(ans,res+1)
    if SEG.get(A[i],A[i]+1)<res+1:
        SEG.update(A[i],res+1)
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline

class SEGTree:
    def __init__(self,N,op,e):
        self.size=2**(N-1).bit_length()
        self.e=e
        self.op=op
        self.SEG=[self.e]*(self.size*2)
    
    def update(self,i,x):
        i+=self.size
        self.SEG[i]=x
        while i>0:
            i>>=1
            self.SEG[i]=self.op(self.SEG[i*2],self.SEG[i*2+1])
            
    def query(self,l,r):
        l+=self.size
        r+=self.size
        lres,rres=self.e,self.e
        
        while l<r:
            if l&1:
                lres=self.op(lres,self.SEG[l])
                l+=1
            if r&1:
                r-=1
                rres=self.op(self.SEG[r],rres)
            l>>=1
            r>>=1
        res=self.op(lres,rres)
        return res
    
    def get(self,i):
        return self.SEG[i+self.size]

N,K=map(int,input().split())
A=[int(input()) for i in range(N)]
M=max(A)
seg=SEGTree(M+1,max,0)
 
ans=0
for i in range(N):
    l=max(0,A[i]-K)
    r=min(M,A[i]+K)
    res=seg.query(l,r+1)+1
    ans=max(ans,res)
    if seg.get(A[i])<res:
        seg.update(A[i],res)
print(ans)