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

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
#n,m=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if a[-1]<=0:
    x=a.pop()
    print(x-sum(a))
    for y in a:
        print(x,y)
        x=x-y
elif a[0]>=0:
    a=a[::-1]
    x=a.pop()
    print(-x+sum(a))
    while a:
        y=a.pop()
        if len(a)>0:
            print(x,y)
            x=x-y
        else:
            print(y,x)
            
else:
    for i in range(n):
        if a[i]>0:
            ap=a[i:]
            an=a[:i]
            break
    print(sum(ap)-sum(an))
    z=ap.pop()
    x=an.pop()
    for y in ap:
        print(x,y)
        x=x-y
    for y in an:
        print(z,y)
        z=z-y
    print(z,x)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
#n,m=map(int,input().split())
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if a[-1]<=0:
    x=a.pop()
    print(x-sum(a))
    for y in a:
        print(x,y)
        x=x-y
elif a[0]>=0:
    a=a[::-1]
    x=a.pop()
    print(-x+sum(a))
    while a:
        if len(a)>1:
            print(x,y)
            x=x-y
        else:
            print(y,x)
else:
    for i in range(n):
        if a[i]>0:
            ap=a[i:]
            an=a[:i]
            break
    print(sum(ap)-sum(an))
    z=ap.pop()
    x=an.pop()
    for y in ap:
        print(x,y)
        x=x-y
    for y in an:
        print(x,y)
        x=x-y
    print(z,x)
Problem p03030 (python)

Fixed submission:
import sys
import bisect
from collections import defaultdict

ans=0
n=int(input())
a=[]
for i in range(n):
    #s,p=map(int,input().split())
    s,p=input().split()
    a.append((s,-int(p),i+1))
#a=[(1,int(i)) for i in input().split()]
a=sorted(a)

for i in range(n):
    print(a[i][2])

Buggy submission (verdict: Runtime Error):
for j in sorted([[(s,-int(p),i+1) for s,p,i in enumerate(input().split())] for _ in range(int(input()))]):print(j[2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    s,p=input().split()
    a+=[(s,-int(p),i+1)]
a.sort()
for i in a:
    print(a[2])
Problem p03046 (python)

Fixed submission:
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

m,k=MI()

if k>=2**m or (m,k)==(1,1):
    print(-1)
elif (m,k)==(1,0):
    print('0 0 1 1')
else:
    a=[]
    for i in range(2**m):
        if i!=k: a.append(i)
    ans=[k]+a+[k]+a[::-1]
    print(*ans)

Buggy submission (verdict: Runtime Error):
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

m,k=MI()

if k>=2**m:
    print(-1)
    exit()

a=[]
for i in range(2**m):
    if i!=k: a.append(i)

print(k,*a,k,*a[::-1])
Problem p03050 (python)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans=0
n=int(input())

for d in make_divisors(n):
    if d==1:
        continue
    m=d-1
    if n//m==n%m:
        ans+=m
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
from operator import itemgetter
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10*5)

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def factorize(x):
    d=defaultdict(int)
    if x==1:
        return d[1]
    while x>1:
        for p in prime:
            if x%p==0:
                x//=p
                d[p]+=1
    return d[p]

ans=0
n=int(input())

#prime=seachPrimeNum(10**6+2)
#fctr=factorize(n)

for d in make_divisors(n):
    if d==1:
        continue
    m=d-1
    if n//m==n%m:
        ans+=m
print(ans)
Problem p03068 (python)

Fixed submission:
# coding: utf-8
# Your code here!

n=int(input())
s=input()
k=int(input())
'''
#a,b=map(int,input().split())
a=[int(i) in range(n)]
a=[0]*n
for i in range(n):
    a.append(int(i))
'''

t=s[k-1]
ans=''
for i in range(n):
    if s[i]==t:
        ans+=t
    else:
        ans+='*'
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input());s=input();k=int(input())
print(''.join([i if i==s[k-1]else*for i in s]))

Buggy submission (verdict: Runtime Error):
n=int(input());s=input();k=int(input())
print(''.join([i if i==s[k-1]else*for i in s]))
Problem p03069 (python)

Fixed submission:
n=int(input())
s=input()
'''
k=int(input())
a,b,c=map(int,input().split())
a=[int(i) in range(n)]
a=[0]*n
for i in range(n):
    a.append(int(i))
'''
pre=0
b=[0]*n
w=[0]*n

for i in range(n):
    if s[i]=='#':
        cc=1
    else:
        cc=0
    b[i]=pre+cc
    pre+=cc
tb=b[n-1]
for i in range(n):
    w[i]=n-(i+1)-(tb-b[i])

#print(s,b,w)
ans=min(n,w[0])
for i in range(n):
    ans=min(ans,b[i]+w[i])
    
print(ans)

Buggy submission (verdict: Runtime Error):
n=input()
s=input()
i=0
for c in s:
  if c=='#':
    ans=s[i:].count('.')
    break
  i+=1
print(ans)
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
if a==b:
  ans=a*2
else:
  ans=max(a,b)*2-1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a==b:
  ans=a*2
else:
  a*2-1
print(ans)
Problem p03109 (python)

Fixed submission:
s=str(input())
if int(s[0:4])*10000+int(s[5:7])*100+int(s[8:10])>20190430:
  print('TBD')
else:
  print('Heisei')

Buggy submission (verdict: Runtime Error):
s=str(input())
if int(s[0:4])*10000+int(str[5:7])*100+int(str[8:10])>20190430:
  print('TBD')
else:
  print('Heisei')
Problem p03110 (python)

Fixed submission:
n=int(input())
a=0
for i in range(n):
  m, curr=input().split()
  m=float(m)
  curr=str(curr)
  if curr=='BTC':
    a=a+m*380000
  else:
    a=a+m
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in range(n):
  m, curr=map(float, input().split())
  a=0
  if curr='BTC'
    a=a+m/380000
  else:
    a=a+m
print(a)
Problem p03126 (python)

Fixed submission:
n,m=map(int,input().split())
ans=set()
b=set(range(1,m+1))
#print(b)
ans=ans.union(b)
for n in range(n):
  #print(ans)
  s=list(map(int,input().split()))
  ex=b - set(s[1:])
  ans=ans-ex
print(len(ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=set()
b=set(range(1,m+1))
ans.union(b)
for n in range(n):
  s=list(map(int,input().split()))
  s=s[1:]
  ans=ans-s
print(len(ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=set()
ans.add(range(1,m+1))
for n in range(n):
  s=list(map(int,input().split()))
  s=s[1:]
  ans=ans-s
print(len(ans))
Problem p03130 (python)

Fixed submission:
c=[]
for i in range(3):
  a,b=map(int,input().split())
  c.append(a)
  c.append(b)
c=sorted(c)
ans='YES'
for j in range(1,5):
  cnt=0
  for i in range(6):
    if c[i]==j:
      cnt+=1
  if cnt>2:
    ans='NO'
    break

print(ans)

Buggy submission (verdict: Runtime Error):
c=[]
for i in range(3):
  a,b=map(int,input().split())
  c.append(a)
  c.append(b)
c=sorted(c)
if c[5]=c[3]:
  print('No')
else:
  print('Yes')
Problem p03147 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
hm=max(h)
s=['']*hm
for k in range(1,hm+1):
  for i in range(n):
    if h[i]>=k:
      s[k-1]+='#'
    else:
      s[k-1]+=' '

#print(s)
ans=0
for k in range(hm):
  ans+=len(list(s[k].split()))
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input()))
hm=max(h)
s=['']*hm
for k in range(hm+1):
  for i in range(n):
    if h[i]>=k:
      s[k]+='#'
    else:
      s[k]+=' '

ans=0
for k in range(hm+1):
  ans+=len(list(s[k].split()))
print(ans)
Problem p03155 (python)

Fixed submission:
n=int(input())
h=int(input())
w=int(input())
print((n-h+1)*(n-w+1))

Buggy submission (verdict: Runtime Error):
a
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
dist=[-1]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    
def dfs(cur):
    if dist[cur]!=-1:
        return dist[cur]
        
    if not g[cur]:
        dist[cur]=0
    else:
        dist[cur]=1+max([dfs(nb) for nb in g[cur]])
    return dist[cur]

ans=0
for i in range(1,n+1):
    ans=max(ans,dfs(i))

print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
dist=[-1]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    
def dfs(cur):
    if dist[cur]!=-1:
        return dist[cur]
        
    if not g[cur]:
        dist[cur]=0
    else:
        dist[cur]=1+max([dfs(nb) for nb in g[cur]])
    return dist[cur]

ans=0
for i in range(1,n+1):
    ans=max(ans,dfs(i))

print(ans)
Problem p03192 (python)

Fixed submission:
s=int(input())
c=0
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))

print(c)

Buggy submission (verdict: Runtime Error):
n,h,w=map(int, input().split())
c=0
for i in range(n):
  a,b = map(int, input().split())
  if a>=h and b>=w:
    c=c+1
print(c)

Buggy submission (verdict: Runtime Error):
s=input()
c=0
if s % 10 ==2:
    c=c+1
s=int((s-(s%10))/10)
if s % 10 ==2:
    c=c+1
s=int((s-(s%10))/10)
if s % 10 ==2:
    c=c+1
s=int((s-(s%10))/10)
if s % 10 ==2:
    c=c+1
s=int((s-(s%10))/10)
print(c)
Problem p03194 (python)

Fixed submission:
n,p=map(int, input().split())
ans=1
m=int(pow(p,1/n))+1
if n==1:
    print(p)
else:
    m=int(pow(p,1/n))+1
    i=2
    c=0
    while(i<=p and i<=m):
        #print('i,p=',i,p)
        if p % i == 0:
            p=p/i
            c=c+1
            if p % i != 0:
                #print('i**(c//n)=',i**(c//n))
                ans = ans * ( i**(c//n) )
                i=i+1
                c=0
        else:
            i=i+1
    print(ans)

Buggy submission (verdict: Runtime Error):
n,p=map(int,input().split())
a=1
for i in range(2,int(p**0.5)+2):
  if p%i==0:
    c=0
    while p%i!=0:
      p//=i
      c+=1
	a*=(c//n)*i
  if p==1:
    break
print(a)
Problem p03215 (python)

Fixed submission:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)#[-k:]
ans=0
i=0
i2=2**40
while i2>0:
#    print(i2,sum([(j&(ans+i2))==(ans+i2) for j in c]))
    ans+=i2 if sum([(j&(ans+i2))==(ans+i2) for j in c])>=k else 0
    i2//=2
    i+=1
    
print(ans)#,A,c)
#print()

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)[-k:]
ans=0
i=0
i2=1
while i2<c[-1]*2:
    ans+=i2 if sum([j>>i&1 for j in c])==k else 0
    #print(i2,sum([j>>i&1 for j in c]))
    i2*=2
    i+=1
    
print(ans)
Problem p03231 (python)

Fixed submission:
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if max(x,y) % min(x,y)==0:
    return min(x,y)
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if x % y==0:
    return x
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  print(n*m)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if x % y==0:
    return x
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=int(n*m/d)
if d==1:
  print(n*m)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if x % y==0:
    return x
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*m/d
if d==1:
  print(n*m)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)
Problem p03239 (python)

Fixed submission:
N, T = list(map(int, input().split()))
ans=10000

for i in range(N):
  c, tt=list(map(int, input().split()))
  if tt <= T:
    ans=min(c,ans)

if ans==10000:
  print('TLE')
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N, T = list(map(int, input().split()))
ans=10000

for i in range(N):
  c, tt==list(map(int, input().split()))
  if tt <= T:
    ans=min(c,ans)

if ans==10000:
  print('TLE')
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int,input())
tmp=10000
ans=0

for i in range(N):
  c, tt==map(int,input())
  if tt <= T:
    tmp=min(c,tmp)
    if c==ans:
      ans=i

if ans==0:
  print('TLE')
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int,input())
ans=10000

for i in range(N):
  c, tt==map(int,input())
  if tt <= T:
    ans=min(c,ans)

if ans==10000:
  print('TLE')
else:
  print(ans)
Problem p03241 (python)

Fixed submission:
N, M = list(map(int, input().split()))
tmp=0

if N==1:
  print(M)
  tmp=1
else:
  for i in range(int(M**0.8)+1):
    k = i + N
    if M % k == 0:
      print(int(M/k))
      tmp=1
      break

if tmp==0:
  print(1)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
tmp=0

if N==1:
  print(M)
  else:
    for i in range(M-N):
      k = i + N
      if M % k == 0:
        print(int(M/k))
        tmp=1
        break

if tmp==0:
  print(1)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
tmp=0

for i in range(M-N):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    tmp=1
    break

if tmp==1:
else:
  print(1)

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

for i in range(M-N):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    tmp=1
    break

if tmp==1:
  else:
    print(1)

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

for i in range(M-N):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    tmp=1
    break

if tmp==1:
else:
  print(1)

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

for i in range(M/N+1):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    break

print(1)
Problem p03254 (python)

Fixed submission:
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n,x=MI()
a=LI()
a.sort()
y=x
ans,s=0,0
for i in range(n):
    s+=a[i]
    if s>x:
        break
    else:
        if i<n-1:
            ans+=1
        elif x-s==0:
            ans+=1
            
print(ans)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  if x>=a[i]:
    ans+=1
    x-=a[i]
if x=sum(a): ans=n-1
print(ans)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().spit()))
a.sort()
ans=0
for i in range(n):
  if x>=a[i]:
    ans+=1
    x-=a[i]
print(ans)
Problem p03261 (python)

Fixed submission:
n=int(input())
a=input()
st=set()
st.add(a)
ans='Yes'
for i in range(n-1):
    s=input()
    st.add(s)
    if a[-1]!=s[0]:
        ans='No'
    a=s
if len(st)<n:
    ans='No'
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(iput())
a=input()
st=set(a)
ans='Yes'
for i in range(n-1):
    s=input()
    if a[-1]!=s[0]:
        ans='No'
    st.add(s)
    a=s
if len(st)<n:
    ans='No'
print(ans)
Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
k-=1
ans=1<<99
for i in range(n-k):
    ans=min(ans,abs(a[i])+a[k+i]-a[i],abs(a[k+i])+a[k+i]-a[i])
print(ans)

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

R=[0]
L=[0]
for i in range(n):
    if x[i]>=0:
        R.append(x[i])
    else:
        L.append(-x[i])

R=sorted(R)
L=sorted(L)


lenR=len(R)
lenL=len(L)

if lenR>k:
    ans=R[k]
    for i in range(k):
        ans=min(ans,R[k-i]+2*L[i], 2*R[k-i]+L[i])
        #print('i,ans,R[k-i]+2*L[i], 2*R[k-i]+L[i]=',i,ans,R[k-i]+2*L[i], 2*R[k-i]+L[i])
else:
    ans=R[lenR-1]+L[k-lenR-1]
    for i in range(lenR):
        if k-i<lenL:
            ans=min(ans,R[i]+2*L[k-i], 2*R[i]+L[k-i])

print(ans)
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())
fl=0
t=0
ans='1'
for i in range(len(s)):
  if s[i]=='1' and fl==0:
    t+=1
  else:
    if fl==0:
      ans=s[i]
      fl=1
if t>=k:
  ans='1'
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
fl=0
t=0
for i in range(len(s)):
  if s[i]=='1' and fl=0:
    t+=1
  else:
    if fl==0:
      ans=s[i]
      fl=1
if t<=k:
  ans='1'
print(ans)
Problem p03311 (python)

Fixed submission:
# coding: utf-8
# Your code here!
n=int(input())
b=input().split()
a=[0]*n
for i in range(n):
    a[i]=int(b[i])-i
a.sort()
c=a[n//2]
ans=0
for i in range(n):
  ans+=abs(a[i]-c)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) + i for i in range(n)]
a.sort()
b=a[n//2]
ans=0
for i in range(n):
  ans+=abs(a[i]-b)
print(ans)
Problem p03353 (python)

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

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    
chars=chars|subset(s[max(l-10,0):],0)
for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

print(sorted(chars)[k-1])

Buggy submission (verdict: Runtime Error):
s=str(input())
k=int(input())

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    

for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

print(sorted(chars)[k-1])

Buggy submission (verdict: Runtime Error):
s=str(input())
k=int(input())

l=len(s)
chars=set()
sub1=['']*l


for i in range(l-1):
  n=i+1 #length = n
  for j in range(l-i):
    chars.add(s[j:j+n])

print(sorted(chars)[k-1])
Problem p03354 (python)

Fixed submission:
n, m=map(int, input().split())
p=[0]+list(map(int, input().split()))

par=[i for i in range(n+1)]
cnt=0
def root(i):
    if par[i]==i:
        return i
    else:
        par[i]=root(par[i])
        return par[i]


for i in range(m):
    x, y=map(int, input().split())
    if root(x)==root(y):
        0
        #print(par[1:])
    else:
        par[root(y)]=root(x)
        #print(par[1:])

ans=0
for i in range(n):
    n=1+i
    if root(n)==root(p[n]):
        ans=ans+1
print(ans)
'''
print(par[1:])

root_ls=[0]+[root(i+1) for i in range(n)]
print(par[1:])
print(root_ls[1:])
'''

Buggy submission (verdict: Runtime Error):
n, m=map(int, input().split())
p=[0]+list(map(int, input().split()))

par=[i for i in range(n+1)]
cnt=0
def root(i):
    if par[i]==i:
        return i
    else:
        par[i]=root(par[i])
        return par[i]

for i in range(m):
    x, y=map(int, input().split())
    if root(x)==root(y):
        
    else:
        par[y]=root(x)

ans=0
for i in range(n):
    n=1+i
    if root(n)==root(p[n]):
        ans=ans+1
print(ans)
'''
print(par[1:])

root_ls=[0]+[root(i+1) for i in range(n)]
print(par[1:])
print(root_ls[1:])
'''

Buggy submission (verdict: Runtime Error):
n, m=map(int, input().split())
p=[]+list(map(int, input().split()))

cat=[0]*(n+1)
cnt=0

for i in range(m):
    x, y=map(int, input().split())
    if cat[x]==0 and cat[y]==0:
        # new set
        cnt=cnt+1
        cat[x]=cnt
        cat[y]=cnt
    else:
        cat[x], cat[y]=cat[x]+cat[y], cat[x]+cat[y]

        
        dp.append(set())
        dp[cat[x]].add(x)
        dp[cat[x]].add(y)
        print('i,cat[x],cat[y],cat,dp=',i,cat[x],cat[y],cat,dp)
        

dp=[set()]*cnt
p_set=[set()]*cnt

for i in range(n+1):
    if cat[i]==0:
    else:
        dp[cat[i]].add[i]
        p_set[cat[i]].add[p[i]]

ans=0
for i in range(cnt+1):
    ans=ans+len(dp[i]&p_set[i])

print(ans)
Problem p03378 (python)

Fixed submission:
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
b=len([1 for s in a if s<x])
c=len(a)-b
print(min(b,c))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
b=[1 for s in a if s<x]
c=sum(a)-b
print(min(b,c))
Problem p03389 (python)

Fixed submission:
a,b,c=map(int,input().split())
a,b,c=sorted([a,b,c])

#parity=set(list(map(lambda x: x % 2,[a,b,c])))
parity=list(map(lambda x: x % 2,[a,b,c]))

if len(set(parity))==1:
    print(int((3*max(a,b,c)-a-b-c)/2))
else:
    if (b-a)%2==0:
        ex=1
    else:
        ex=2
    print(int((max(a,b,c)-a)/2)+int((max(a,b,c)-b)/2)+int((max(a,b,c)-c)/2) + ex)

Buggy submission (verdict: Runtime Error):
*a=map(int,open(0))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print(t//2)

Buggy submission (verdict: Runtime Error):
*a=map(int,open(0))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print(t//2)

Buggy submission (verdict: Runtime Error):
*a=map(int,open(0))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print(t//2)
Problem p03427 (python)

Fixed submission:
def sol(n):
    #n=input()
    if len(set(n[1:]))<=1 and (n[-1]=='9' or len(n)==1):
      m=0
    else:
      m=1
    print(int(n[0])+9*len(n)-9-m)

n=input()
sol(str(n))

Buggy submission (verdict: Runtime Error):
def sol(n):
    #n=input()
    if len(set(n[1:]))<=1 and (n[-1]=='9' or len(n)==1):
      m=0
    else:
      m=1
    print(int(n[0])+9*len(n)-9-m)

n=input()
sol(str(i))
Problem p03433 (python)

Fixed submission:
n,a=map(int,open(0).read().split())
print('YNeos'[n%500>a::2])

Buggy submission (verdict: Runtime Error):
n,a=map(int,input().split())
print('YNeos'[n%500>a::2])