Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q = map(int, input().split())
s = [-(10**11)]+[int(input()) for _ in range(A)]+[10**11]
t = [-(10**11)]+[int(input()) for _ in range(B)]+[10**11]
s.sort()
t.sort()

def bi(arr, l, r, val):
    if r-l<=1:
        return l
    m = (l+r)//2
    if val < arr[m]:
        return bi(arr, l, m, val)
    else:
        return bi(arr, m, r, val)

import itertools
for _ in range(Q):
    pos = int(input())
    s_near_id = bi(s, 0, len(s), pos)
    t_near_id = bi(t, 0, len(t), pos)
    print(min( min(abs(pos-s_pos)+abs(s_pos-t_pos), abs(pos-t_pos)+abs(t_pos-s_pos)) for s_pos, t_pos in itertools.product(s[s_near_id:s_near_id+2],t[t_near_id:t_near_id+2]) ))


Fixed submission:
A,B,Q = map(int, input().split())
s = [-(10**11)]+[int(input()) for _ in range(A)]+[10**11]
t = [-(10**11)]+[int(input()) for _ in range(B)]+[10**11]
s.sort()
t.sort()

import bisect
import itertools
for _ in range(Q):
    pos = int(input())
    s_near_id = bisect.bisect_left(s, pos)-1
    t_near_id = bisect.bisect_left(t, pos)-1
    print(min( min(abs(pos-s_pos)+abs(s_pos-t_pos), abs(pos-t_pos)+abs(t_pos-s_pos)) for s_pos, t_pos in itertools.product(s[s_near_id:s_near_id+2],t[t_near_id:t_near_id+2]) ))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
def cost(a, b):
    return abs(h[a] - h[b])
 
c = [0] * N
for i in range(1, N):
    c[i] = min(cost(i, i-k)+c[i-k] for k in range(1, min(K, i)+1))
 
print(c[-1])
 


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
def cost(a, b):
    return abs(h[a] - h[b])
 
c = [0] * N
for i in range(1, N):
    c[i] = min(cost(i, i-k)+c[i-k] for k in range(1, min(K, i)+1))
 
print(c[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

def cost(a, b):
    return abs(h[a] - h[b])

c = [0] * N
for i in range(1, N):
    c[i] = min(
        [cost(i, i-k)+c[i-k] for k in range(1, min(K, i)+1)]
        )

print(c[-1])



Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
def cost(a, b):
    return abs(h[a] - h[b])
 
c = [0] * N
for i in range(1, N):
    c[i] = min(cost(i, i-k)+c[i-k] for k in range(1, min(K, i)+1))
 
print(c[-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
scores = []

for i in range(N):
    scores.append(tuple(map(int, input().split())))

mem = [[None]*3 for i in range(N)]

def getScore(day, act):
    if mem[day][act] is not None:
        return mem[day][act]
    score = scores[day][act]
    if day < N-1:
        score += max(getScore(day+1, (act+1)%3), getScore(day+1, (act+2)%3))
    mem[day][act] = score
    return score

print(max(getScore(0, act) for act in range(3)))



Fixed submission:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N = ii()
    sa,sb,sc = 0,0,0
    for _ in range(N):
        a,b,c=mis()
        nsa = max(sb,sc)+a
        nsb = max(sc,sa)+b
        nsc = max(sa,sb)+c
        sa,sb,sc = nsa,nsb,nsc
    print(max(sa,sb,sc))

main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

a = N
for i in range(N):
    a = min(a, S[:i].count('W')+S[i+1:].count('E'))

print(a)


Fixed submission:
N = int(input())
S = input()

a = S[1:].count('E')
W = 0
E = a
for i in range(1, N):
    if S[i - 1] == 'W':
        W += 1
    if S[i] == 'E':
        E -= 1
    a = min(W + E, a)

print(a)
Buggy python submission (verdict: Runtime Error):
def main():
    a, b, c = map(int, input().split())
    count = 0
    while (a | b | c) & 1 == 0:
        if a==b==c:
            print(-1)
            return
        a, b, c = (b + c) >> 1, (c + a) >> 1, (a + b) >> 1
        count += 1
        print(a,b,c)
    
    print(count)

while True:
    main()


Fixed submission:
def main():
    a, b, c = map(int, input().split())
    if a == b == c:
        print(0 if a & 1 else -1)
        return
    count = 0
    while (a | b | c) & 1 == 0:
        a, b, c = (b + c) >> 1, (c + a) >> 1, (a + b) >> 1
        count += 1
    
    print(count)
 
main()
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

def r(i, g):
    if i == N:
        return 0
    elif g < w[i]:
        return r(i + 1, g)
    else:
        return max(r(i + 1, g - w[i]) + v[i], r(i + 1, g))

print(r(0, W))

Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

memo = {i:{} for i in range(N)}

def r(i, g):
    global memo
    if i == N:
        return 0
    elif g in memo[i]:
        return memo[i][g]
    elif g < w[i]:
        a = r(i + 1, g)
    else:
        a = max(r(i + 1, g - w[i]) + v[i], r(i + 1, g))
    
    memo[i][g] = a
    return a

print(r(0, W))
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()

S = ''
for i in range(len(O)):
    S += O[i]
    S += E[i]

print(S)


Fixed submission:
O = input()
E = input()

S = ''
for i in range(len(O)):
    S += O[i]
    if len(E) > i:
        S += E[i]

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))

c = 0
for i in range(2, n):
    for j in range(2, 7):
        if (7 * i + j - 7) * 9 % 11 == k:
            c += 1

print(c)

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

p = int((n - 2) / 11)
c = p * 5
for i in range(2 + p * 11 , n):
    for j in range(2, 7):
        if (7 * i + j - 7) * 9 % 11 == k:
            c += 1

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


count = 0
for c in range(1, N):
    d = Counter(prime_factorize(N - c))

    tmp = 1
    for x in d.values():
        tmp *= x + 1
    count += tmp

print(count)


Fixed submission:
N = int(input())
ans = 0
for a in range(1, N):
    ans += (N-1) // a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9 + 7
a = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        a += (A[i] * A[j])
print(a % mod)

Fixed submission:
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9 + 7
a = 0
for i in range(N):
    a += sum(A[:i]) * A[i]
    a %= mod
print(a)


Fixed submission:
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9 + 7
a = 0
for i in range(N):
    a += sum(A[:i]) * A[i]
print(a % mod)


Fixed submission:
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9 + 7
a = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        a += A[i] * A[j]
        a %= mod
print(a)


Fixed submission:
mod = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]
S = sum(A) % mod

ans = 0
for i in range(N):
    S -= A[i]
    if S < 0: S += mod

    ans += S * A[i]
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
input()
print(a if (a:=reduce(lambda x,y:int(x)*int(y), input().split()))<=1e18 else -1)

Fixed submission:
input()
s=1
for a in map(int,input().split()):
  if a==0:s=0;break
  if s>0:s*=a
  if s>1e18:s=-1
print(s)
Buggy python submission (verdict: Runtime Error):
import queue
I=lambda:map(int,input().split())
N,M=I()
ls=[[] for _ in range(M+1)]
for _ in[0]*M:
  A,B=I()
  ls[A]+=[B]
  ls[B]+=[A]
q = queue.Queue()
v=[-1]*(N+1)
v[0]=v[1]=0
q.put(1)
while not(q.empty()):
  top=q.get()
  for l in ls[top]:
    if v[l]<0:
      v[l]=top
      q.put(l)
if -1 in v:
  print("No")
else:
  print("Yes")
  [print(k) for k in v[2::]]

Fixed submission:
import queue
I=lambda:map(int,input().split())
N,M=I()
ls=[[] for _ in range(N+1)]
for _ in[0]*M:
  A,B=I()
  ls[A]+=[B]
  ls[B]+=[A]
q = queue.Queue()
v=[-1]*(N+1)
v[0]=v[1]=0
q.put(1)
while not(q.empty()):
  top=q.get()
  for l in ls[top]:
    if v[l]<0:
      v[l]=top
      q.put(l)
if -1 in v:
  print("No")
else:
  print("Yes")
  [print(k) for k in v[2::]]
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
*A,=map(int,input().split())
d={}
for a in A:
    k=a
    while k>=1:
        d[k-k//2]=d.get(k-k//2,0)+1
        k=k//2
s=0
i=0
for k in sorted(list(d.keys()), key=lambda x:-x):
    if i+d[k]<=M:
        i+=d[k]
        s+=k*d[k]
    else:
        s+=k*(M-i)
        break
print(sum(A)-s)

Fixed submission:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
*A,=map(int,input().split())
d={}
for a in A:
    k=a
    while k>=1:
        d[k-k//2]=d.get(k-k//2,0)+1
        k=k//2
s=0
i=0
for k in sorted(list(d.keys()), key=lambda x:-x):
    if i+d[k]<=M:
        i+=d[k]
        s+=k*d[k]
    else:
        s+=k*(M-i)
        break
print(sum(A)-s)

Fixed submission:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def f():
  N,M=map(int,input().split())
  A=np.array(list(map(int,input().split())))
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  sa=(np.sort(np.array(l))[-M:]).sum()
  print(A.sum()-sa)
f()

Fixed submission:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Buggy python submission (verdict: Time Limit Exceeded):
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Fixed submission:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
*A,=map(int,input().split())
l=[]
for a in A:
    k=a
    while k>=1:
        l+=[k-k//2]
        k=k//2
print(sum(A)-sum(sorted(l)[-M:]))

Fixed submission:
def f():
  N,M=map(int,input().split())
  *A,=map(int,input().split())
  l=[]
  for a in A:
      k=a
      while k>=1:
          l+=[k-k//2]
          k=k//2
  print(sum(A)-sum(sorted(l)[-M:]))
if __name__=="__main__":
  f()
Buggy python submission (verdict: Runtime Error):
*A=map(int,input().split());print(sum(A)-max(A))

Fixed submission:
*A,=map(int,input().split());print(sum(A)-max(A))
Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:map(int,input().split())
R,G,B,N=I()
r=0
for i in range(N//R+1):
    for j in range(N//G+1):
        if N-i*R-j*G>=0 and (N-i*R-j*G)%B==0:
            r+=1
#            print(i,j,N-i-j)
print(r)

Fixed submission:
I=lambda:map(int,input().split())
R,G,B,N=I()
r=0
for i in range(N//R+1):
    for j in range(N//G+1):
        if N-i*R-j*G>=0 and (N-i*R-j*G)%B==0:
            r+=1
print(r)
Buggy python submission (verdict: Runtime Error):
import bisect
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':m.append(i+1)
#print(m)
for i in range(Q):
    l,r=I()
    li=bisect.bisect_left(m,l)
    ri=bisect.bisect_left(m,r)
    #print(i,li,ri)
    if m[ri-1]==r:
        print(ri-li-1)
    else:
        print(ri-li)

Fixed submission:
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[0]
for i in range(N-1):
    m+=[m[-1]+(1 if S[i:i+2]=='AC' else 0)]
#print(m)
for i in range(Q):
    l,r=I()
    print(m[r-1]-m[l-1])

Buggy python submission (verdict: Runtime Error):
import bisect
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        m += [i]
#print(m)
for i in range(Q):
    l,r=I()
    li=bisect.bisect_left(m,l-1)
    ri=bisect.bisect_left(m,r-1)
    #print(i,li,ri)
    print(ri-li-1 if m[ri-1]==r else ri-li)

Fixed submission:
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[0]
for i in range(N-1):
    m+=[m[-1]+(1 if S[i:i+2]=='AC' else 0)]
#print(m)
for i in range(Q):
    l,r=I()
    print(m[r-1]-m[l-1])
Buggy python submission (verdict: Runtime Error):
#解説より
cost=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=sorted(map(int,input().split()))[::-1]
dp=[0]
for i in range(1,N+1):
    l=[dp[i-cost[a]]for a in A if i>=cost[a]]
    if len(l)==0:dp+=[-1]
    else:dp+=[max(l)+1]
S=''
Sum=0
for i in range(dp[N]):
    for a in A:
        if dp[N-Sum-cost[a]]==dp[N]-1-i:
            S+=str(a)
            Sum+=cost[a]
            break
print(S)

Fixed submission:
#解説より
cost=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=sorted(map(int,input().split()))[::-1]
dp=[0]
for i in range(1,N+1):
    l=[dp[i-cost[a]]for a in A if i>=cost[a]]
    if len(l)==0:dp+=[-1]
    else:dp+=[max(l)+1]
S=''
Sum=0
for i in range(dp[N]):
    for a in A:
        if N-Sum-cost[a]>=0 and dp[N-Sum-cost[a]]==dp[N]-1-i:
            S+=str(a)
            Sum+=cost[a]
            break
print(S)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print(a+b/2)

Fixed submission:
a,b=map(int,input().split())
print(a+b//2)
Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Fixed submission:
S=input()
print(S[::-1]if len(S)==3 else S)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
T=input()
X=0
for s in S:
    if ord(s)>96:X+=1;S=S.replace(s,chr(X+47))
Y=0
for t in T:
    if ord(t)>96:Y+=1;T=T.replace(t,chr(Y+47))
print('Yes'if S==T else'No')

Fixed submission:
S=input()
T=input()
X=0
for i in range(len(S)):
    s=S[i]
    if ord(s)>96:
        X+=1
        S=S.replace(s,chr(X+47))
Y=0
for i in range(len(T)):
    t=T[i]
    if ord(t)>96:
        Y+=1
        T=T.replace(t,chr(Y+47))
print('Yes'if S==T else'No')
Buggy python submission (verdict: Time Limit Exceeded):
N,X=map(int,input().split())
x=list(map(int,input().split()))
w=[x[-1]]
for y in x[N-2::-1]:w+=[w[-1]+y]
r=1e20
for k in range(1,N+1):
    s=0
    for j in range(1,1+((N+k-1)//k)):
        s+=max(5,2*j+1)*(w[min(N,k*j)-1]-(0 if j==1 else w[k*j-k-1]))
    s+=(N+k)*X
    r=min(s,r)
print(r)

Fixed submission:
N,X=map(int,input().split())
w=[0]
for i in map(int,input().split()):w+=[w[-1]+i]
print(min(5*w[N]+k*X+sum(2*w[j]for j in range(N-k*2,0,-k))for k in range(1,N+1))+N*X)

Buggy python submission (verdict: Time Limit Exceeded):
N,X=map(int,input().split())
x=list(map(int,input().split()))
w=[x[-1]]
for y in x[N-2::-1]:w+=[w[-1]+y]
print(min(sum(max(5,2*j+1)*(w[min(N,k*j)-1]-(0 if j==1 else w[k*j-k-1]))for j in range(1,1-(-N//k)))+(N+k)*X for k in range(1,N+1)))

Fixed submission:
N,X=map(int,input().split())
w=[0]
for i in map(int,input().split()):w+=[w[-1]+i]
print(min(5*w[N]+k*X+sum(2*w[j]for j in range(N-k*2,0,-k))for k in range(1,N+1))+N*X)
Buggy python submission (verdict: Runtime Error):
n=input()
print("No"if int(n)%sum(int(i)for i in n) else"Yes")

Fixed submission:
s=input()
print(s.count("+")-s.count("-"))
Buggy python submission (verdict: Runtime Error):
n=int(input())
r=0
b=0
for i in range(n):
 t=int(input())
 if i==0!=t or b+1<t:print(-1);exit()
 elif b>=t:r+=b
 b=t
print(r+b)

Fixed submission:
a,b,c,k=map(int,input().split())
print(a-b if k%2==0 else b-a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input())for _ in[0]*n]
if n%2==0:
    m1=n//2
    m2=m1+1
    m1i=a.index(m1)
    m2i=a.index(m2)
    a1=[a[i] for i in range(m1i) if a[i]<m1]
    a2=[a[i] for i in range(m1i+1,n) if a[i]<m1]
    al=sorted(a2)+a1
    a3=[a[i] for i in range(m2i) if a[i]>m2]
    a4=[a[i] for i in range(m2i+1,n) if a[i]>m2]
    ar=a4+sorted(a3)
    r=len(a2)+len(a3)
    l=al.index(m1-1)
    r+=m1-2-l
    r+=ar.index(m2+1)
else:
    m=n//2+1
    mi=a.index(m)
    a1=[a[i] for i in range(mi) if a[i]<m]
    a2=[a[i] for i in range(mi+1,n) if a[i]<m]
    al=sorted(a2)+a1
    a3=[a[i] for i in range(mi) if a[i]>m]
    a4=[a[i] for i in range(mi+1,n) if a[i]>m]
    ar=a4+sorted(a3)
    r=len(a2)+len(a3)
    l=al.index(m-1)
    r+=m-2-l
    r+=ar.index(m+1)
print(r)

Fixed submission:
n=int(input())
p=[int(input())-1for _ in[0]*n]
q=[0]*n
for i in range(n):q[p[i]]=i
r,c=0,1
for i in range(n-1):
    c=c+1if q[i]<q[i+1]else 1
    if r<c:r=c
if r<c:r=c
print(n-r)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
l=len(s)
a=[]
for i in range(l):
    for j in range(i,l):
        jbreak = False
        sij = s[i:j+1]
        #print(sij)
        if not(sij in a):
            if a==[]:
                a.append(sij)
            elif len(a) < k:
                a.insert(0,sij)
                for m in range(len(a)-1):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: break
            else:
                a.insert(0,sij)
                breakflag = False
                for m in range(k):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: 
                        breakflag=True
                        break
                if not(breakflag):jbreak = True
        if j-i>k: break
print(a[k-1])

Fixed submission:
s=input()
k=int(input())
l=len(s)
a={s[i:i+j+1] for i in range(l) for j in range(k+1)}
a=list(a)
a.sort()
print(a[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
l=len(s)
a=[]
for i in range(l):
    for j in range(i,l):
        jbreak = False
        sij = s[i:j+1]
        #print(sij)
        if not(sij in a):
            if a==[]:
                a.append(sij)
            elif len(a) < k:
                a.insert(0,sij)
                for m in range(len(a)-1):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: break
            else:
                a.insert(0,sij)
                breakflag = False
                for m in range(k):
                    if a[m]>a[m+1]:
                        a[m],a[m+1]=a[m+1],a[m]
                    else: 
                        breakflag=True
                        break
                if not(breakflag):jbreak = True
print(a[k-1])

Fixed submission:
s=input()
k=int(input())
l=len(s)
a={s[i:i+j+1] for i in range(l) for j in range(k+1)}
a=list(a)
a.sort()
print(a[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
l=len(s)
a={s[i:j] for i in range(l) for j in range(i+1,l+1)}
b=list(a)
b.sort()
print(b[k-1])

Fixed submission:
s=input()
k=int(input())
l=len(s)
a={s[i:i+j+1] for i in range(l) for j in range(k+1)}
a=list(a)
a.sort()
print(a[k-1])
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input())
print((x-a)%b)

Fixed submission:
print((int(input())-int(input()))%int(input()))
Buggy python submission (verdict: Runtime Error):
print(sum(map(int,list(input()))))

Fixed submission:
n,a,b = map(int,input().split())
r = 0
for i in range(n+1):
    wa = sum(map(int,list(str(i))))
    if a <= wa and wa <= b: r += i
print(r)
Buggy python submission (verdict: Runtime Error):
S=input()
T='AKIHABARA'
i=0;j=0
while 1:
    if S[i]==T[j]:i+=1;j+=1
    elif 'A'==T[j]:j+=1
    else:break
    if i>=len(S):break
print('YES'if i==len(S) else 'NO')

Fixed submission:
S=input()
N=len(S)
K,I,H,B,R=S.find('K'),S.find('I'),S.find('H'),S.find('B'),S.find('R')
f = (K==0 or K==1) and K==I-1==H-2 and (H+1==B or S[H+1]=='A') and (B+1==R or S[B+1]=='A') and (R==N-2 and S[R+1]=='A' or R==N-1)
T='AKIHABARA'
i=0;j=0;g=True
while 1:
    if S[i]==T[j]:i+=1;j+=1
    elif T[j]=='A':j+=1
    else:g=False;break
    if i==len(S):break
    elif j==9:g=False;break
print('YES'if f and g else 'NO')
Buggy python submission (verdict: Runtime Error):
print(int(sqrt(int(input())))**2)

Fixed submission:
import math
print(int(math.sqrt(int(input())))**2)
Buggy python submission (verdict: Runtime Error):
*a=map(int,input().split());print(sum(a)-max(a))

Fixed submission:
*a,=map(int,input().split());print(sum(a)-max(a))
Buggy python submission (verdict: Runtime Error):
def color(r):
  if r<3200:return r//400
  else:return 8
colors = [0]*9
N=int(input())
for a in map(int,input().split()):
  colors[color(a)]+=1
base=0
for i n range(8):
  if colors[i]>0:base+=1
print(base, base+colors[8])

Fixed submission:
c=[0]*9
input()
for a in map(int,input().split()):c[min(a//400,8)]+=1
b=0
for i in range(8):b+=1if c[i]>0 else 0
print(max(b,1), b+c[8])
Buggy python submission (verdict: Runtime Error):
I=lambda:map(int,input().split())
N,M=I()
r=range(N)
m={i:0 for i in r}
for _ in[0]*M:a,b=I();m[a]+=+1;m[b]+=1
for i in r:print(m[i])

Fixed submission:
I=lambda:map(int,input().split())
N,M=I()
r=range(N)
m={i:0 for i in r}
for _ in[0]*M:
  a,b=I()
  m[a-1]+=1
  m[b-1]+=1
for i in r:print(m[i])
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print("GREATER"if A>B else"LESS"if A<B else"EQUAL")

Fixed submission:
A,B=int(input()),int(input())
print("GREATER"if A>B else"LESS"if A<B else"EQUAL")