Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
import numpy as np
l=np.array(list(map(int,input().split())))
for i in range(min(b,int(a**0.5)+4)):
  now=np.zeros(a,dtype=np.int)
  for j in range(a):
    x=l[j]
    y=np.zeros(a,dtype=np.int)
    y[max(0,j-x):min(a,j+x+1)]=1
    now+=y
  l=now
for i in range(a):
  now[i]=min(now[i],a)
print(*now)


Fixed submission:
a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
    y=[0]*a
    for j,x in enumerate(l):
      y[max(0,j-x)]+=1
      r=min(j+x,a-1)
      if r<a-1:
        y[r+1]-=1
    return itertools.accumulate(y)

  
for _ in range(b):
  l=ku(l)
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
l=list(map(int,input().split()))
for i in range(min(b,int(a**0.5)+4)):
  now=[0]*a
  for j in range(a):
    x=l[j]
    for k in range(max(0,j-x),min(a,j+x+1)):
      now[k]+=1
  l=now
for i in range(a):
  now[i]=min(now[i],a)
print(*now)


Fixed submission:
a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
    y=[0]*a
    for j,x in enumerate(l):
      y[max(0,j-x)]+=1
      r=min(j+x,a-1)
      if r<a-1:
        y[r+1]-=1
    return itertools.accumulate(y)

  
for _ in range(b):
  l=ku(l)
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
l=list(map(int,input().split()))
for i in range(min(b,1000)):
  now=[0]*a
  for j in range(a):
    x=l[j]
    for k in range(max(0,j-x),min(a,j+x+1)):
      now[k]+=1
  l=now
for i in range(a):
  now[i]=min(now[i],a)
print(*now)


Fixed submission:
a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
    y=[0]*a
    for j,x in enumerate(l):
      y[max(0,j-x)]+=1
      r=min(j+x,a-1)
      if r<a-1:
        y[r+1]-=1
    return itertools.accumulate(y)

  
for _ in range(b):
  l=ku(l)
print(*l)
Buggy python submission (verdict: Runtime Error):
a,b=map(input().split())
a=int(a)
b=int(float(b)*100)
a,b=int(a),int(b)
print(int((a*b)//100))

Fixed submission:
s=input()
a,b=s.split(' ')
a=int(a)
b=100*int(b[0])+int(b[2:])
s=a*b
print(int(s//100))
Buggy python submission (verdict: Runtime Error):
s=input()
if s[1]='R':
  print('ABC')
else:
  print('ARC')

Fixed submission:
s=input()
if s[1]=='R':
  print('ABC')
else:
  print('ARC')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(min(a%b,(b%(a%b))))


Fixed submission:
a,b=map(int,input().split())
print(min(a%b,b-a%b))
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))



Fixed submission:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
for i in range(len(q)):
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

Buggy python submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x-y:]
q=sorted(list(map(int,input().split())))[-x-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))



Fixed submission:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
for i in range(len(q)):
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

Buggy python submission (verdict: Runtime Error):
s,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x-y:]
q=sorted(list(map(int,input().split())))[-x-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))



Fixed submission:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
for i in range(len(q)):
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(1,6):
  if s=='hi'*i:
  print('Yes')
  quit()
print('No')

Fixed submission:
s=input()
for i in range(1,6):
  if s=='hi'*i:
    print('Yes')
    quit()
print('No')
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append([a,b])
for i in range(10**(n-1)-1,10**n):
  x=str(i)
  c=0
  for i in range(m):
    if x[l[i][0]-1]==str(l[i][1]):
      c+=1
  if c==m:
    print(x)
    quit()
print(-1)

Fixed submission:
n,m=map(int,input().split())
l=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append([a,b])
for i in range(10**n):
  x=str(i)
  if len(x)<n:pass
  else:
    c=0
    for i in range(m):
      if x[l[i][0]-1]==str(l[i][1]):
        c+=1
    if c==m:
      print(x)
      quit()
print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
  l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
  for j in range(n):
    if l[j][i]=='1':
      memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
  ans+=(now*x*(n-x))%mod
  now*=2
print(ans%mod)


Fixed submission:
print('win' if sum(list(map(int,input().split())))<22 else 'bust')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
  l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
  for j in range(n):
    if l[j][i]=='1':
      memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
  ans+=(now*x*(n-x))%mod
  now*=2
print(ans%mod)


Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
  l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
  for j in range(n):
    if l[j][i]=='1':
      memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
  ans+=(now*x*(n-x))%mod
  now*=2
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=1
mod=1000000007
me=[0,0,0]
now=3
for x in l:
  if x==0:
    ans*now
    now-=1
    if now<0:
      print(0)
      quit()
    me[-now]=1
  else:
    a=len([i for i, y in enumerate(me) if y == x])
    if a>3:
      print(0)
      quit()
    ans=ans*a%mod    
    me[me.index(x)]+=1
if now==0:
  print(6*ans%mod)
else:
  print(3*ans%mod)

Fixed submission:
n=int(input())
mod=1000000007
l=list(map(int,input().split()))
me=[3]+[0]*2*n
ans=1
for x in l:
  ans=ans*me[x]%mod
  me[x]-=1
  me[x+1]+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=1
mod=1000000007
me=[0,0,0]
now=3
for x in l:
  if x==0:
    ans*now
    now-=1
    if now<0:
      print(0)
      quit()
    me[-now]=1
  else:
    a=len([i for i, y in enumerate(me) if y == x])
    if a>2:
      print(0)
      quit()
    ans=ans*a%mod    
    me[me.index(x)]+=1
if now==0:
  print(6*ans%mod)
else:
  print(3*ans%mod)

Fixed submission:
n=int(input())
mod=1000000007
l=list(map(int,input().split()))
me=[3]+[0]*2*n
ans=1
for x in l:
  ans=ans*me[x]%mod
  me[x]-=1
  me[x+1]+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=1
mod=10**9+7
me=[0,0,0]
now=3
for x in l:
  if x==0:
    ans*now
    now-=1
    if now<0:
      print(0)
      quit()
    me[-now]=1
  else:
    ans=ans*len([i for i, y in enumerate(me) if y == x])%mod
    me[me.index(x)]+=1
if now==0:
  print(6*ans%mod)
else:
  print(3*ans%mod)

Fixed submission:
n=int(input())
mod=1000000007
l=list(map(int,input().split()))
me=[3]+[0]*2*n
ans=1
for x in l:
  ans=ans*me[x]%mod
  me[x]-=1
  me[x+1]+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=1
mod=10**9+7
me=[0,0,0]
now=3
for x in l:
  if x==0:
    ans*now
    now-=1
    me[-now]=1
  else:
    ans=ans*len([i for i, y in enumerate(me) if y == x])%mod
    me[me.index(x)]+=1
if now==0:
  print(6*ans%mod)
else:
  print(3*ans%mod)

Fixed submission:
n=int(input())
mod=1000000007
l=list(map(int,input().split()))
me=[3]+[0]*2*n
ans=1
for x in l:
  ans=ans*me[x]%mod
  me[x]-=1
  me[x+1]+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))
ma=a[0]*b[-1]
mi=0
if sum(a)<k+1:
  ma=0
for i in range(n):
  a[i]=a[i]*b[i]
for i in range(50):
  now=0
  for i in range(n):
    now+=max(0,(a[i]-(mi+ma)//2+b[i]-1)//b[i])
  if now>k:
    mi=(ma+mi)//2
  else:
    ma=(ma+mi)//2
print(ma)

Fixed submission:
import bisect
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))
ma=a[0]*b[-1]
mi=0
if sum(a)<k+1:
  ma=0
for i in range(n):
  a[i]=a[i]*b[i]
while abs(ma-mi)>1:
  now=0
  for i in range(n):
    now+=max(0,(a[i]-(mi+ma)//2+b[i]-1)//b[i])
  if now>k:
    mi=(ma+mi)//2
  else:
    ma=(ma+mi)//2
print(ma)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))
ma=10**13
mi=0
if sum(a)<k+1:
  print(0)
  quit()
while abs(ma-mi)>1:
  now=0
  for i in range(n):
    now+=max(0,(a[i]*b[i]-(mi+ma)//2+b[i]-1)//b[i])
  if now>k:
    mi=(ma+mi)//2
  else:
    ma=(ma+mi)//2
print(ma)

Fixed submission:
import bisect
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))
ma=a[0]*b[-1]
mi=0
if sum(a)<k+1:
  ma=0
for i in range(n):
  a[i]=a[i]*b[i]
while abs(ma-mi)>1:
  now=0
  for i in range(n):
    now+=max(0,(a[i]-(mi+ma)//2+b[i]-1)//b[i])
  if now>k:
    mi=(ma+mi)//2
  else:
    ma=(ma+mi)//2
print(ma)
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
def c(n):
  s=set([1])
  if n%2==0:
    s.add(2)
    while n%2==0:
      n//=2
  i=1
  while n>1:
    i+=2
    if n%i==0:
      s.add(i)
      while n%i==0:
        n//=i
  return s
s=c(a)
l=list(s)
for x in l:
  if b%x!=0:
    s.remove(x)
print(len(s))

Fixed submission:
a,b=map(int,input().split())
def p(n):
    a = set([1])
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a
s=p(a)
l=list(s)
for x in l:
  if b%x!=0:
    s.remove(x)
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
def c(n):
  s=set()
  if n%2==0:
    s.add(2)
    while n%2==0:
      n//=2
  i=1
  while n>1:
    i+=2
    if n%i==0:
      s.add(i)
      while n%i==0:
        n//=i
  return s
s=(c(a)&c(b))
print(len(s)+1)

Fixed submission:
a,b=map(int,input().split())
def p(n):
    a = set([1])
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a
s=p(a)
l=list(s)
for x in l:
  if b%x!=0:
    s.remove(x)
print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
def c(n):
  s=set()
  if n%2==0:
    s.add(2)
    while n%2==0:
      n//=2
  i=1
  while n>1:
    i+=2
    if n%i==0:
      s.add(i)
      while n%i==0:
        n//=i
  return s
s=(c(a)&c(b))
print(len(s)+1)

Fixed submission:
a,b=map(int,input().split())
def p(n):
    a = set([1])
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a
s=p(a)
l=list(s)
for x in l:
  if b%x!=0:
    s.remove(x)
print(len(s))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()[::-1]
mod=10**9+7
if s[0]=='?':
  dp=[[1]*10]
  for _ in range(3):
    dp[0].append(0)
else:
  dp=[[0]*13]
  dp[0][int(s[0])]=1
dp.append([0]*13)
now=1
for i in range(1,len(s)):
  now=now*10
  x=s[i]
  if x!='?':
    x=(now*int(x))%13
    for j in range(13):
      dp[i%2][(j+x)%13]=dp[i%2-1][j]
  else:
    for j in range(10):
      x=(now*j)%13
      for k in range(13):
        if j==0:
          dp[i%2][k]=dp[i%2-1][k]
        else:
          dp[i%2][(k+x)%13]+=dp[i%2-1][k]
          dp[i%2][(k+x)%13]=dp[i%2][(k+x)%13]%mod
print(dp[len(s)%2-1][5]%mod)

Fixed submission:
s=input()[::-1]
mod=10**9+7
dp=[[0]*13 for i in range(len(s))]
if s[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1
now=1
for i in range(1,len(s)):
  now=(now*10)%13
  x=s[i]
  if x!='?':
    x=now*int(x)
    for j in range(13):
      dp[i][(j+x)%13]=dp[i-1][j]
  else:
    for j in range(10):
      x=now*j
      for k in range(13):
          dp[i][(k+x)%13]+=dp[i-1][k]
          dp[i][(k+x)%13]=dp[i][(k+x)%13]%mod
print(dp[-1][5]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()[::-1]
mod=10**9+7
if s[0]=='?':
  dp=[[1]*10]
  for _ in range(3):
    dp[0].append(0)
else:
  dp=[[0]*13]
  dp[0][int(s[0])]=1
dp.append([0]*13)
now=1
for i in range(1,len(s)):
  now=now*10
  x=s[i]
  if x!='?':
    x=(now*int(x))%13
    for j in range(13):
      dp[i%2][(j+x)%13]=dp[i%2-1][j]
  else:
    for j in range(10):
      x=(now*j)%13
      for k in range(13):
        if j==0:
          dp[i%2][k]=dp[i%2-1][k]
        else:
          dp[i%2][(k+x)%13]+=dp[i%2-1][k]
          dp[i%2][(k+x)%13]=dp[i%2][(k+x)%13]%mod
print(dp[len(s)%2-1][5]%mod)

Fixed submission:
s=input()[::-1]
mod=10**9+7
dp=[[0]*13 for i in range(len(s))]
if s[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1
now=1
for i in range(1,len(s)):
  now=(now*10)%13
  x=s[i]
  if x!='?':
    x=now*int(x)
    for j in range(13):
      dp[i][(j+x)%13]=dp[i-1][j]
  else:
    for j in range(10):
      x=now*j
      for k in range(13):
          dp[i][(k+x)%13]+=dp[i-1][k]
          dp[i][(k+x)%13]=dp[i][(k+x)%13]%mod
print(dp[-1][5]%mod)
Buggy python submission (verdict: Runtime Error):
class uf():
    def __init__(self,n):
        self.n=n
        self.pa=[-2]*n
    def find(self,x):
        if self.pa[x]<-1:
            return x
        else:
            self.pa[x]=self.find(self.pa[x])
            return self.pa[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
        	return True
        else:
            if self.pa[x]>self.pa[y]:
                x,y=y,x
            self.pa[x]+=y
            self.pa[y]=x
            return True
    def same(self,x,y):
        return self.find[x]==find.pa[y]
    def size(self,x):
        return -self.pa[self.find(x)] 
n,m=map(int,input().split())
import sys
input=sys.stdin.readline
uf=uf(n)
for _ in range(m):
    a,b,c=map(int,input().split())
    uf.unite(a-1,b-1)
memo=set([])
for i in range(n):
    memo.add(uf.find(i))
print(len(memo))

Fixed submission:
class uf():
    def __init__(self,n):
        self.n=n
        self.pa=[-1]*n
    def find(self,x):
        if self.pa[x]<0:
            return x
        else:
            self.pa[x]=self.find(self.pa[x])
            return self.pa[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
        	return True
        else:
            if self.pa[x]>self.pa[y]:
                x,y=y,x
            self.pa[x]+=self.pa[y]
            self.pa[y]=x
            return True
    def same(self,x,y):
        return self.find[x]==find.pa[y]
    def size(self,x):
        return -self.pa[self.find(x)] 
n,m=map(int,input().split())
import sys
input=sys.stdin.readline
uf=uf(n)
for _ in range(m):
    a,b,c=map(int,input().split())
    uf.unite(a-1,b-1)
memo=set([])
for i in range(n):
    memo.add(uf.find(i))
print(len(memo))
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline()
n=int(input())
for i in range(n):
  if int(input())%2==1:
    print('first')
    quit()
print('second')

Fixed submission:
n=int(input())
for i in range(n):
  if int(input())%2==1:
    print('first')
    quit()
print('second')
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans1=[]
ans2=[]
for x in c.keys():
  if c[x]>1:
    ans1.append(x)
  if c[x]>3:
    ans2.append(x)
ans1.sort()
if len(ans1)<2:
  print(0)
else:
  print(max(ans1[-1]*ans1[-2],max(ans2)**2))

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
import collections
c = collections.Counter(l)
ans1=[]
ans2=[0]
for x in c.keys():
  if c[x]>1:
    ans1.append(x)
  if c[x]>3:
    ans2.append(x)
ans1.sort()
if len(ans1)<2:
  print(0)
else:
  print(max(ans1[-1]*ans1[-2],max(ans2)**2))
Buggy python submission (verdict: Runtime Error):
import math
x, y = map(int, input().split())
c_up = (2*y-x)/3
c_do = (2*x-y)/3
if c_up.is_integer() and c_do.is_integer():
  c_up = int(c_up)
  c_do = int(c_do)
  pattern = math.factorial(c_up+c_do) / (math.factorial(c_up)*math.factorial(c_do))
  result = int(pattern % (7 + 10**9))
else:
  result = 0
print(result)


Fixed submission:
def mod_comb(n, r, m):
  nn = n+1
  r = min(r, n-r)
  numer = 1
  denom = 1
  for i in range(1, r+1):
    numer = (numer * (nn - i)) % m
    denom = (denom * i) % m
  output = numer * pow(denom, m-2, m) % m
  return output

x, y = map(int, input().split())
if not (x <= 2*y and y <= 2*x):
  result = 0
else:
  c_up = (2*y-x)/3
  c_do = (2*x-y)/3
  if c_up.is_integer() and c_do.is_integer():
    c_up = int(c_up)
    c_do = int(c_do)
    result = mod_comb((c_up+c_do), c_up, 7+10**9)
  else:
    result = 0
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
min_num = 3 * 10**5
for i in range(0, n):
  if i == 0:
    temp = s[1:].count("E")
  elif i == n-1:
    temp = s[:-1].count("W")
  else:
    s_1 = s[:i-1].count("W")
    s_2 = s[i+1:].count("E")
    temp = s_1 + s_2
  if min_num > temp:
    min_num = temp
print(min_num) 

Fixed submission:
n = int(input())
s = input()
list_num = []
for i in range(0, n):
  if i == 0:
    temp = s[1:].count("E")
    list_num.append(temp)
  else:
    temp = list_num[-1]
    if s[i] == "E":
      temp -= 1
    if s[i-1] == "W":
      temp += 1
    list_num.append(temp)
print(min(list_num))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def main():
  s = input()
  k = int(input())
  alphabet = sorted(list(set(list(s))))

  list_sub = []
  num = 1
  while num <= k:
    temp = list(itertools.product(alphabet, repeat=num))
    temp = ["".join(com) for com in temp if "".join(com) in s]
    list_sub.extend(temp)
    num += 1
  list_sub.sort()
  print(list_sub[k-1])

if __name__ == "__main__":
  main()

Fixed submission:
s = input()
k = int(input())

list_sub = []
for i in range(len(s)):
  temp = [s[i:i+j] for j in range(1, min(len(s)-i+1, k+1))]
  list_sub += temp

list_sub = list(set(list_sub))
list_sub.sort()

print(list_sub[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
s = input()
k = int(input())
alphabet = sorted(list(set(list(s))))

list_sub = []
num = 1
while num <= k:
  temp = list(itertools.product(alphabet, repeat=num))
  temp = ["".join(com) for com in temp if "".join(com) in s]
  list_sub.extend(temp)
  num += 1
list_sub.sort()
print(list_sub[k-1])

Fixed submission:
s = input()
k = int(input())

list_sub = []
for i in range(len(s)):
  temp = [s[i:i+j] for j in range(1, min(len(s)-i+1, k+1))]
  list_sub += temp

list_sub = list(set(list_sub))
list_sub.sort()

print(list_sub[k-1])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

check = [(-1, 0), (0, -1), (1, 0), (0, 1)]
for j in range(h):
  for i in range(w):
    if grid[i][j] == "#":
      temp = [(i+cx, j+cy) for cx, cy in check if (0<= i+cx <w and 0<= j+cy <h)]
      count = 0
      for t_cx, t_cy in temp:
        if grid[t_cx][t_cy] == "#":
          count += 1
      if count == 0:
        print("No")
        exit()
print("Yes")

Fixed submission:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

check = [(-1, 0), (0, -1), (1, 0), (0, 1)]
for j in range(h):
  for i in range(w):
    if grid[j][i] == "#":
      temp = [(i+cx, j+cy) for cx, cy in check if (0<= i+cx <w and 0<= j+cy <h)]
      count = 0
      for t_cx, t_cy in temp:
        if grid[t_cy][t_cx] == "#":
          count += 1
      if count == 0:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_x = list(map(int, input().split()))
med = int(n / 2) - 1
for i in range(n):
  temp = list_x[:i] + list_x[i+1:]
  temp.sort()
  print(temp[med])

Fixed submission:
n = int(input())
list_x = list(map(int, input().split()))
sub_list = sorted(list_x)

a = sub_list[n // 2]
b = sub_list[n // 2 - 1]

for one_x in list_x:
  if one_x <= b:
    print(a)
  else:
    print(b)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
cell = {}
for i in range(h):
  row = list(map(int, input().split()))
  for j, a in enumerate(row):
    cell[a] = (i, j)
max_point = h * w
req_mp = [-1 for _ in range(max_point)]

q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  result = 0
  p = l
  while p < r:
    if req_mp[p] == -1:
      magic = abs(cell[p+d][0] - cell[p][0]) + abs(cell[p+d][1] - cell[p][1])
      req_mp[p] = magic
    result += req_mp[p]
    p += d
  print(result)

Fixed submission:
h, w, d = map(int, input().split())
cell = {}
for i in range(h):
  row = list(map(int, input().split()))
  for j, a in enumerate(row):
    cell[a] = (i, j)

max_point = h * w
req_mp = [0 for i in range(max_point)]
for i in range(max_point):
  if i < d:
    req_mp[i] = 0
  else:
    temp = req_mp[i-d]
    temp += abs(cell[i-d+1][0] - cell[i+1][0])
    temp += abs(cell[i-d+1][1] - cell[i+1][1])
    req_mp[i] = temp

q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  print(req_mp[r-1] - req_mp[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, h = map(int, input().split())
list_w = []
max_a = [-1, -1, 10**9]
for i in range(n):
  a, b = list(map(int, input().split()))
  list_w.append([a, b])
  if max_a[1] < a:
    max_a = [i, a, b]
  elif max_a[1] == a and max_a[2] > b:
    max_a = [i, a, b]  
list_w.pop(max_a[0])
list_w.sort(key=lambda x:x[1], reverse=True)

count = 0
while h > 0:
  if h > max_a[2]:
    if len(list_w) > 0 and list_w[0][1] > max_a[1]:
      h -= list_w[0][1]
      list_w.pop(0)
      count += 1
    else:
      if max_a[2] > max_a[1]:
        num = (h - max_a[2]) // max_a[1]
        h -= max_a[1] * num
        count += num
      else:
        num = h // max_a[1]
        h -= max_a[1] * num
        count += num
  else:
    h -= max_a[2]
    count += 1
print(count)

Fixed submission:
import math
n, h = map(int, input().split())
list_a = []
list_b = []
for i in range(n):
  a, b = list(map(int, input().split()))
  list_a.append(a)
  list_b.append(b)
max_a = max(list_a)
use_b = [b for b in list_b if b > max_a]
use_b.sort(reverse=True)

count = 0
while h > 0:
  if len(use_b) > 0:
    h -= use_b.pop(0)
    count += 1
  else:
    count += math.ceil(h / max_a)
    break
print(count)