Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dp = [[0]*(n) for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        if i == (n-1):
            if s[i] == s[j]:
                dp[i][j] += 1
            continue

        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1        

ans = 0
for i in range(n-1, -1, -1):
    for j in range(i, -1, -1):
        ans = max(ans, min(abs(j-i), dp[i][j]))
print(ans)

Fixed submission:
n = int(input())
s = input()
dp = [[0]*(n) for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        if i == (n-1):
            if s[i] == s[j]:
                dp[i][j] += 1
            continue

        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1        

ans = 0
for i in range(n-1, -1, -1):
    for j in range(i, -1, -1):
        ans = max(ans, min(abs(j-i), dp[i][j]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dp = [[0]*(n) for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(n-1, -1, -1):
        if i == n-1 or j == n-1:
            if s[i] == s[j]:
                dp[i][j] += 1
            continue

        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1        
        else:
            dp[i][j] = dp[i+1][j+1]

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        ans = max(ans, min(abs(j-i), dp[i][j]))
print(ans)

Fixed submission:
n = int(input())
s = input()
dp = [[0]*(n) for _ in range(n)]

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        if i == (n-1):
            if s[i] == s[j]:
                dp[i][j] += 1
            continue

        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1        

ans = 0
for i in range(n-1, -1, -1):
    for j in range(i, -1, -1):
        ans = max(ans, min(abs(j-i), dp[i][j]))
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(G, v):
    seen[v] = True

    for nv in G[v]:
        if seen[nv]:
            continue
        point[nv] += point[v]
        dfs(G, nv)

n, q = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(n-1):
    x, y =  map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)
    G[y].append(x)

seen = [False for _ in range(n)]
root = 0
point = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

dfs(G, root)
print(*point)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(G, v):
    seen[v] = True

    for nv in G[v]:
        if seen[nv]:
            continue
        point[nv] += point[v]
        dfs(G, nv)

n, q = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(n-1):
    x, y =  map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)
    G[y].append(x)

seen = [False for _ in range(n)]
root = 0
point = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

dfs(G, root)
print(*point)
Buggy python submission (verdict: Runtime Error):
s = input()
pr = s[0]
cnt = 0
i = 0
while i < len(s)-1:
    if len(pr) == 1:
        if s[i+1] == pr:
            if i+2 < len(s)-1:
                cnt += 1
                pr = s[i+1:i+3]
                i += 2
            else:
                break
        else:
            cnt += 1
            pr = s[i+1]
            i += 1
    else:
        cnt += 1
        pr = s[i+2]
        i += 1
print(cnt+1)

Fixed submission:
def calc(pr, s):
    cnt = 0
    i = 0
    while i < len(s)-1:
        if len(pr) == 1:
            if s[i+1] == pr:
                if i+2 < len(s):
                    cnt += 1
                    pr = s[i+1:i+3]
                    i += 1
                else:
                    break
            else:
                cnt += 1
                pr = s[i+1]
                i += 1
        else:
            if i+2 < len(s):
                cnt += 1
                pr = s[i+2]
                i += 2
            else:
                break
    return cnt+1

s = input()
pr1 = s[0]
pr2 = s[:2]
print(max(calc(pr1, s), calc(pr2, s)))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
d = []
for _ in range(n):
    a, b = map(int, input().split())
    d.append((b, a))
d.sort(reverse=True)

cnt = m
ans = 0
i = 0
while i < n or cnt > 0:
    if d[i][1] <= cnt:
        ans += d[i][0]
        i += 1
        cnt -= 1
    else:
        i += 1
    if i == n-1 or cnt == 0:
        break        

print(ans)



Fixed submission:
import heapq
n, m = map(int, input().split())
d = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        d[a-1].append(-b)

t = []
heapq.heapify(t)
ans = 0
for i in range(m):
    for dd in d[i]:
        heapq.heappush(t, dd)
    if t:
        ans += heapq.heappop(t)*(-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
b = k
r = n-k
MOD = 10**9+7

def comb(n, k, MOD):
    return fact[n] * invfact[k] * invfact[n-k] % MOD

lenlist = 4*(10**6)
fact = [1] * lenlist
invfact = [1] * lenlist

for i in range(1, lenlist):
    fact[i] = fact[i-1] * i % MOD

invfact[lenlist - 1] = pow(fact[lenlist - 1], MOD-2, MOD)

for i in range(lenlist-1, 0, -1):
    invfact[i-1] = invfact[i] * i % MOD

for i in range(k):
    if i == 0:
        print(r+1)
        continue
    if i > r:
        print(0)
        continue
    ans = comb(r+1, i+1, MOD)
    ans *= comb(b-1, i, MOD)
    ans %= MOD
    print(ans)

Fixed submission:
n, k = map(int, input().split())
b = k
r = n-k
MOD = 10**9+7

def comb(n, k, MOD):
    return fact[n] * invfact[k] * invfact[n-k] % MOD

lenlist = 4*(10**6)
fact = [1] * lenlist
invfact = [1] * lenlist

for i in range(1, lenlist):
    fact[i] = fact[i-1] * i % MOD

invfact[lenlist - 1] = pow(fact[lenlist - 1], MOD-2, MOD)

for i in range(lenlist-1, 0, -1):
    invfact[i-1] = invfact[i] * i % MOD

for i in range(k):
    if i == 0:
        print(r+1)
        continue
    if i > r:
        print(0)
        continue
    ans = comb(r+1, i+1, MOD)
    ans *= comb(b-1, i, MOD)
    ans %= MOD
    print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
b = sorted(a)
c = sorted(a, key=lambda x:x[1])
bd = []
cd = []
for i in range(n-1):
    b0 = b[i+1][0] - b[i][0]
    b1 = b[i+1][1] - b[i][1]
    bd.append((b0, b1))
    
    c0 = c[i+1][0] - c[i][0]
    c1 = c[i+1][1] - c[i][1]
    cd.append((c0, c1))
    
cbd = Counter(bd)
ccd = Counter(cd)
print(n-max(cbd.most_common()[0][1], ccd.most_common()[0][1]))

Fixed submission:
from collections import Counter
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]

if n == 1:
    print(1)
    exit()

b = sorted(a)
sb = []
for i in range(n-1):
    for j in range(i+1, n):
        sb.append((b[i][0] - b[j][0], b[i][1] - b[j][1]))
        
c = Counter(sb)
print(n-c.most_common()[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
r, g, b = sorted([r, g, b], reverse=True)
cnt = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        rg = r*i + g*j
        k = (n-rg)//b
        if k >= 0 and i+j+k >= 1 and rg+b*k == n:
            cnt += 1
print(cnt) 

Fixed submission:
r, g, b, n = map(int, input().split())
r, g, b = sorted([r, g, b], reverse=True)
cnt = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        rg = r*i + g*j
        k = (n-rg)//b
        if k >= 0 and i+j+k >= 1 and rg+b*k == n:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n = int(input())
a = list(set(map(int,input().split())))
a.sort(reverse=True)
b = gcd(a[0], a[1])
c = [a[0], a[1]]
for i in range(2, len(a)):
    g1 = gcd(b, a[i])    
    d = []
    for j in c:
        g2 = gcd(j, a[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if b > 1:
        c.append(b)
    b = g1

if c:
    print(max(c))
else:
    print(1)

Fixed submission:
from fractions import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
oc = []
b = 0
for i, v in c.items():
    if v == 1:
        oc.append(i)
    else:
        if b == 0:
            b = i
        else:
            b = gcd(b, i)

loc = len(oc)
if loc <= 1:
    print(b)
    exit()

c = [oc[0], oc[1]]
e = gcd(oc[0], oc[1])
if loc == 2:
    c.append(e)
for i in range(2, loc):
    g1 = gcd(e, oc[i])
    d = []
    for cc in c:
        g2 = gcd(cc, oc[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if e > 1:
        c.append(e)
    if i == loc-1:
        c.append(g1)
    e = g1

if b >= 2:
    print(max([gcd(cc, b) for cc in c]))
elif b == 0:
    print(max(c))
else:
    print(1)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
b = gcd(a[0], a[1])
c = [a[0], a[1]]
for i in range(2, n):
    g1 = gcd(b, a[i])
    d = []
    for j in c:
        g2 = gcd(j, a[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if b > 1:
        c.append(b)
    b = g1

if c:
    print(max(c))
else:
    print(1)

Fixed submission:
from fractions import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
oc = []
b = 0
for i, v in c.items():
    if v == 1:
        oc.append(i)
    else:
        if b == 0:
            b = i
        else:
            b = gcd(b, i)

loc = len(oc)
if loc <= 1:
    print(b)
    exit()

c = [oc[0], oc[1]]
e = gcd(oc[0], oc[1])
if loc == 2:
    c.append(e)
for i in range(2, loc):
    g1 = gcd(e, oc[i])
    d = []
    for cc in c:
        g2 = gcd(cc, oc[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if e > 1:
        c.append(e)
    if i == loc-1:
        c.append(g1)
    e = g1

if b >= 2:
    print(max([gcd(cc, b) for cc in c]))
elif b == 0:
    print(max(c))
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
total = 0
c = []
for i in range(5):
    a = input()
    b = int(a)
    if int(a[-1]) != 0:
        c.append(int(a[-1]))
        total += b - int(a[-1]) + 10
    else:
        total += b

total += min(c)
total -= 10
print(total)

Fixed submission:
total = 0
c = []
for i in range(5):
    a = input()
    b = int(a)
    if int(a[-1]) != 0:
        c.append(int(a[-1]))
        total += b - int(a[-1]) + 10
    else:
        total += b

if c:
    total += min(c)
    total -= 10
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
c = 0
for i in range(a,b+1):
    d = bin(c ^ i)
    c = int(d,2)   
print(c)

Fixed submission:
a,b = map(int,input().split())
if a % 4 == 0 and b % 4 == 0:
    print(b)
    exit()

c = []
if a % 4 != 0:
    c += list(range(a,a+(4-(a%4))))
c += list(range(b-(b%4),b+1))

e = 0
for i in c:
    d = bin(e ^ i)
    e = int(d,2)
print(e)
Buggy python submission (verdict: Runtime Error):
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)

if m == 1:
    print(0)
    exit()

b = []
for i in range(m-1):
    b.append(abs(a[i+1]-a[i]))
b.sort(reverse=True)

for i in range(n-1):
    b.pop(0)

print(sum(b))

Fixed submission:
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)

if n >= m:
    print(0)
    exit()

b = []
for i in range(m-1):
    b.append(abs(a[i+1]-a[i]))
b.sort(reverse=True)

for i in range(n-1):
    b.pop(0)

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

sa = 0
sb = 0
for i in range(n):
    if i % 2 == 0:
        ab.sort(reverse=True)
        sa += ab[0][0]
        ab.pop(0)
    else:
        ab = sorted(ab, key=lambda x: x[1], reverse=True)
        sb += ab[0][1]
        ab.pop(0)
        
print(sa-sb)

Fixed submission:
n = int(input())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a+b,a,b])
    
ab.sort(reverse=True)
suma = 0
sumb = 0
for i in range(n):
    if i % 2 == 0:
        suma += ab[i][1]
    else:
        sumb += ab[i][2]
print(suma-sumb)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))+[float('inf')]*(10001-n)
dp = [float('inf')]*100001
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
for i in range(m):
    x, y = map(int, input().split())
    G[x].append(y)

memo = [0]*(n+1)
seen = [False]*(n+1)
def dp(v):
    if seen[v]:
        return memo[v]
    ans = 0
    for nv in G[v]:
        ans = max(ans, dp(nv) + 1)

    seen[v] = True
    memo[v] = ans
    return ans

ans = 0
for v in range(1, n+1):
    ans = max(ans, dp(v))
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)

memo = [-1]*n
def dp(v):
    if memo[v] != -1:
        return memo[v]
    res = 0
    for nv in G[v]:
        res = max(res, dp(nv) + 1)
    
    memo[v] = res
    return res

ans = 0
for v in range(n):
    ans = max(ans, dp(v))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
cnt = 0
ans = 0
while True:
    if 'W' not in s:
        break
    
    for i in range(len(s)):
        if s[i] == 'B':
            cnt += 1
        else:
            ans += cnt
            cnt = 0
            s.pop(i)
            break

print(ans)

Fixed submission:
s = list(input())
cnt = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'B':
        cnt += 1
    else:
        ans += cnt

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(357,n+1):
    a = str(i)
    if (a[0] == '3' or a[0] == '5' or a[0] == '7') and ('3' in a and '5' in a and '7' in a):
        sa = set(a)
        if len(sa) == 3 and '3' in sa and '5' in sa and '7' in sa:
            ans += 1
print(ans)

Fixed submission:
import itertools
n = int(input())
a = [3,5,7]
b = list(itertools.product(a,a,a)) + list(itertools.product(a,a,a,a)) + list(itertools.product(a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a,a))
ans = 0
for i in range(len(b)):
    sb = set(b[i])
    if len(sb) == 3 and 3 in sb and 5 in sb and 7 in sb:
        c = ''.join(map(str,b[i]))
        c = int(c)
        if c <= n:
            ans +=1
        else:
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
n,d = map(int,input().split())
a = list(map(int,input().split()))

b = []
c = 0
m = n
for i in range(n):
    for j in range(m):
        for k in range(j+1):
            c += a[k]
        b.append(c)
        c = 0
    m -= 1
    del a[0]
b = list(set(b))

h = list(itertools.permutations(range(len(b)), d))
p = []
q = []
for i in range(len(h)):
    for j in range(d):
        p.append(b[h[i][j]])
        
    for k in range(d-1):
        k += 1
        if k == 1:
            e = bin(p[k])
            f = bin(p[k-1])
            g = int(e,0) & int(f,0)
        g = int(bin(g),0) & int(bin(p[k]),0)
    q.append(g)
    p = []

print(max(q))

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

avg = sum(a)/len(a)
b = []
for aa in a:
    b.append(abs(aa-avg))

print(b.index(min(b)))
Buggy python submission (verdict: Runtime Error):
import itertools
import collections
from scipy.special import comb

n,m = map(int,input().split())
a = list(map(int,input().split()))
ac = [0]
ac += list(itertools.accumulate(a))

re = [i % m for i in ac]
c = collections.Counter(re)

ans = 0
for v in c.values():
    if v >= 2:
        ans += comb(v,2,exact=True)
print(ans)

Fixed submission:
import itertools
import collections
import math

n,m = map(int,input().split())
a = list(map(int,input().split()))
ac = [0]
ac += list(itertools.accumulate(a))

re = [i % m for i in ac]
c = collections.Counter(re)

ans = 0
for v in c.values():
    if v >= 2:
        ans += (math.factorial(v)//math.factorial(v-2))//(math.factorial(2))
print(ans)
Buggy python submission (verdict: Runtime Error):
if n < 1200:
    print('ABC')
elif n < 2800:
    print('ARC')
else:
    print('AGC')

Fixed submission:
n = int(input())
if n < 1200:
    print('ABC')
elif n < 2800:
    print('ARC')
else:
    print('AGC')
Buggy python submission (verdict: Time Limit Exceeded):
import statistics
from decimal import Decimal,ROUND_HALF_UP

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

for i in range(n):
    a[i] -= i+1
a.sort()

med = Decimal(str(statistics.median(a))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(sum([abs(i-med) for i in a]))

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

for i in range(n):
    a[i] -= i+1
a.sort()

ans = 0
for i in range(n):
    ans += abs(a[i] - a[n//2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import statistics
from decimal import Decimal,ROUND_HALF_UP

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

for i in range(n):
    a[i] = a[i]-(i+1)
a.sort()

med = Decimal(str(statistics.median(a))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
if med == 0:
    print(sum([abs(i) for i in a]))
    exit()
    
set_a = list(set(a))
near = float('inf')
for i in range(len(set_a)):
    if abs(med - set_a[i]) < near:
        near = abs(med - set_a[i])
        mid = set_a[i]

print(sum([abs(i-mid) for i in a]))

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

for i in range(n):
    a[i] -= i+1
a.sort()

ans = 0
for i in range(n):
    ans += abs(a[i] - a[n//2])
print(ans)

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

p = []
m = []
for i in range(n):
    a[i] -= i+1
    if a[i] > 0:
        p += [a[i]]
    elif a[i] < 0:
        m += [a[i]]

if sum(p) == abs(sum(m)):
    print(sum([abs(i) for i in a]))
    exit()

pre = sum([abs(i) for i in a])
if sum(p) > abs(sum(m)):
    while True:
        for i in range(n):
            a[i] -= 1
        total = sum([abs(i) for i in a])
        
        if total >= pre:
            print(pre)
            exit()
        pre = total
else:
    while True:
        for i in range(n):
            a[i] += 1
        total = sum([abs(i) for i in a])
        
        if total >= pre:
            print(pre)
            exit()
        pre = total

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

for i in range(n):
    a[i] -= i+1
a.sort()

ans = 0
for i in range(n):
    ans += abs(a[i] - a[n//2])
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

if n == k:
    print(1)
    exit()

l = 0
r = 0
one = False
for i in range(n):
    if a[i] == 1:
        one = True
        continue
    if one == False:
        l += 1
    else:
        r += 1

if k >= min(l+1,r+1):
    n -= k
    if n%(k-1) == 0:
        n //= k-1
    else:
        n //= k-1
        n += 1
    pritn(n+1)
else:
    if l % (k-1) == 0:
        l //= k-1
    else:
        l //= k-1
        l += 1
        
    if r % (k-1) == 0:
        r //= k-1
    else:
        r //= k-1
        r += 1
    print(l+r)

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

if n == k:
    print(1)
    exit()
    
n -= k
if n % (k-1) == 0:
    n //= k-1
else:
    n //= k-1
    n += 1
print(n+1)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while True:
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    if len(k) >= 5:
        break
    if l == len(a)-1:
        break
    l += 1

k = list(set(k))
k.sort()
print(k[K-1])

Fixed submission:
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    l += 1

k = list(set(k))
k.sort()
print(k[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
a = []
for i in range(len(s)+1):
    for j in range(len(s)-i+1):
        if s[j:j+i]:
            a.append(s[j:j+i])
            
a = list(set(a))
a.sort()
print(a[k-1])

Fixed submission:
S = input()
K = int(input())
a = list(set(S))
a.sort()

k = []
l = 0
while l < len(a):
    for i in range(len(S)):
        if S[i] == a[l]:
            for j in range(1,6):
                if i+j <= len(S):
                    k.append(S[i:i+j])
                else:
                    break
    l += 1

k = list(set(k))
k.sort()
print(k[K-1])
Buggy python submission (verdict: Runtime Error):
a, b, c, x, y = map(int, input().split())
xy = [x, y]

if (a + b) // 2 <= c:
  	total_ab = a * x + b * y
    print(total_ab)
else:
    d = c * min(xy) * 2
    if x == y:
        print(d)
    elif x > y:
        print(min((x-y) * a + d, c * max(xy) * 2))
    else:
        print(min((y-x) * b + d, c * max(xy) * 2))

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

total_ab = a * x + b * y
total_c = c * 2 * max(xy)
if x > y:
    total_abc = c * 2 * min(xy) + a * (x-y)
else:
    total_abc = c * 2 * min(xy) + b * (y-x)

total = [total_ab, total_c, total_abc]
print(min(total))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    a = x[:i] + x[i+1:]
    a.sort(reverse=True)
    print(a[n//2-1])

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
sx = sorted(x)

for i in range(n):
    if x[i] < sx[n//2]:
        print(sx[n//2])
    else:
        print(sx[n//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(n-1):
    if max(a) % 2 == 1:
        b.append([abs(max(a)//2+1-a[i]),a[i]])
    b.append([abs(max(a)//2-a[i]),a[i]])
b.sort()

print(max(a),b[0][1])

Fixed submission:
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort()
ma = max(a)

b = bisect.bisect(a,ma//2)
koho = []
if b-1 >= 0:
    koho.append([abs(ma//2-a[b-1]),a[b-1]])
if b < n-1:
    koho.append([abs(ma//2-a[b]),a[b]])

if ma % 2 == 1:
    b2 = bisect.bisect(a,ma//2+1)
    if b2-1 >= 0:
        koho.append([abs(ma//2+1-a[b2-1]),a[b2-1]])
    if b2 < n-1:
        koho.append([abs(ma//2+1-a[b2]),a[b2]])

koho.sort()
print(ma,koho[0][1])