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

for i in range(n - 1):
    print(a.index(i + 1) + 1, end = ' ')
print(a.index(n) + 1)

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

order = [0] * n

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

print(' '.join(map(str, order)))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

while m > 0:
    idx = a.index(max(a))
    if a[idx] == 0:
        break
    a[idx] = a[idx] // 2
    m -= 1
print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

while m > 0:
    a_max = heapq.heappop(a)
    if a_max == 0:
        break
    heapq.heappush(a, (-1)*(-a_max // 2))
    m -= 1
print(sum(a)*(-1))

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

a.sort(reverse = True)

cnt = [[a[i]] for i in range(n)]

for i in range(n):
    while 1:
        a[i] = a[i] // 2
        cnt[i].append(a[i])
        if a[i] == 0:
            break
while m > 0:
    max_num = [cnt[i][0] for i in range(n)]
    max_index = max_num.index(max(max_num))
    if cnt[max_index][0] == 0:
        break
    del cnt[max_index][0]
    m -= 1
max_num = [cnt[i][0] for i in range(n)]
print(sum(max_num))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

while m > 0:
    a_max = heapq.heappop(a)
    if a_max == 0:
        break
    heapq.heappush(a, (-1)*(-a_max // 2))
    m -= 1
print(sum(a)*(-1))

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

for i in range(1, m+1):
    a.sort()
    a[-1] = a[-1] // 2
    if sum(a) == 0:
        break
print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

while m > 0:
    a_max = heapq.heappop(a)
    if a_max == 0:
        break
    heapq.heappush(a, (-1)*(-a_max // 2))
    m -= 1
print(sum(a)*(-1))

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

log_a = [math.log2(x) for x in a]
if sum(log_a) < m:
    print(0)
else:
    for i in range(1, m+1):
        a.sort()
        a[-1] = a[-1] // 2
    print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

while m > 0:
    a_max = heapq.heappop(a)
    if a_max == 0:
        break
    heapq.heappush(a, (-1)*(-a_max // 2))
    m -= 1
print(sum(a)*(-1))
Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
ans = sum([i for i in range(n)])
print(ans)

Fixed submission:
n =int(input())
ans = n * (n - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
colorn = list(map(int, input().split()))
color = colorn[0:3]
n = colorn[-1]
color.sort()

a, b, c = color[2], color[1], color[0]

a_max = n // a
cnt = 0

for i in range(a_max + 1):
    b_max = (n - a * i) // b
    for j in range(b_max + 1):
        c_max = (n - a * i - b * j) // c
        for k in range(c_max, c_max + 2):
            if a * i + b * j + c * k == n:
                cnt += 1
            elif a * i + b * j + c * k > n:
                break     
print(cnt)

Fixed submission:
colorn = list(map(int, input().split()))
color = colorn[0:3]
n = colorn[-1]
color.sort()

a, b, c = color[2], color[1], color[0]

a_max = n // a
cnt = 0
ip, jp, kp = -1, -1, -1

for i in range(a_max + 1):
    b_max = (n - a * i) // b
    d = n - a * i
    flag = 0
    for j in range(b_max + 1):
        c_max = (n - a * i - b * j) // c
        for k in range(c_max, c_max + 2):
            if a * i + b * j + c * k == n:
                cnt += 1
                if ip == i:
                    dj = j - jp
                    cnt += ((d // b - j) // dj)
                    flag = 1
                    break
                else:
                    ip, jp, kp = i, j, k
            elif a * i + b * j + c * k > n:
                break
        if flag == 1:
            break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
colorn = list(map(int, input().split()))
color = colorn[0:3]
n = colorn[-1]
color.sort()

a, b, c = color[2], color[1], color[0]

a_max = n // a
b_max = n // b
c_max = n // c
cnt = 0

for i in range(a_max + 1)[::-1]:
    b_max = (n - a * i) // b
    for j in range(b_max + 1)[::-1]:
        c_max = (n - a * i - b * j) // c
        for k in range(c_max + 1)[::-1]:
            if a * i + b * j + c * k == n:
                cnt += 1
            elif a * i + b * j + c * k < n:
                break     
print(cnt)

Fixed submission:
colorn = list(map(int, input().split()))
color = colorn[0:3]
n = colorn[-1]
color.sort()

a, b, c = color[2], color[1], color[0]

a_max = n // a
cnt = 0
ip, jp, kp = -1, -1, -1

for i in range(a_max + 1):
    b_max = (n - a * i) // b
    d = n - a * i
    flag = 0
    for j in range(b_max + 1):
        c_max = (n - a * i - b * j) // c
        for k in range(c_max, c_max + 2):
            if a * i + b * j + c * k == n:
                cnt += 1
                if ip == i:
                    dj = j - jp
                    cnt += ((d // b - j) // dj)
                    flag = 1
                    break
                else:
                    ip, jp, kp = i, j, k
            elif a * i + b * j + c * k > n:
                break
        if flag == 1:
            break
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

ab = 0
ba = 0
c2 = 0
c3 = 0
for x in s:
    if 'AB' in x:
        ab += x.count('AB')    
    if x[-1] == 'A' and x[0] == 'B':
        ba = 1
    if x[-1] == 'A' and x[0] != 'B':
        c2 += 1
    if x[-1] != 'A' and x[0] == 'B':
        c3 += 1
if ba > 0:
    if c2 + c3 > 0:
        ans = ab + ba + min(c2, c3)
    else: # c2 = c3 =0
        ans = ab + ba - 1
print(ans)


Fixed submission:
n = int(input())
s = [input() for i in range(n)]

ab = 0
ba = 0
c2 = 0
c3 = 0
for x in s:
    if 'AB' in x:
        ab += x.count('AB')    
    if x[-1] == 'A' and x[0] == 'B':
        ba += 1
    if x[-1] == 'A' and x[0] != 'B':
        c2 += 1
    if x[-1] != 'A' and x[0] == 'B':
        c3 += 1
if ba > 0:
    if c2 + c3 > 0:
        ans = ab + ba + min(c2, c3)
    else: # c2 = c3 =0
        ans = ab + ba - 1
else:
    ans = ab + min(c2, c3)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

a.sort()
minus, plus = [], []

for x in a:
    if x < 0:
        minus.append(x)
    else:
        plus.append(x)

tmp = sum([abs(x) for x in a])

if len(minus) % 2 == 0:
    print(tmp)
else:
    if abs(minus[-1]) > plus[0]:
        print(tmp - plus[0] * 2)
    else:
        print(tmp + minus[-1] * 2)

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

a.sort()
minus, plus = [], []

for x in a:
    if x < 0:
        minus.append(x)
    else:
        plus.append(x)

tmp = sum([abs(x) for x in a])

if len(minus) % 2 == 0:
    print(tmp)
else:
    if plus == [] or abs(minus[-1]) < plus[0]:
        print(tmp + minus[-1] * 2)
    else:
        print(tmp - plus[0] * 2)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9] * 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]))
        else:
            break
print(dp[n - 1])

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

dp = [10**9] * 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]))
        else:
            break
print(dp[n - 1])

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

dp = [10**10] * 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 = [10**9] * 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]))
        else:
            break
print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]

dp = [[0] * (w + 1) for i in range(n + 1)]

for i in range(n):
    for sum_w in range(w + 1):
        if sum_w - wv[i][0] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - wv[i][0]] + wv[i][1])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(dp[n][w])

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

dp = [[0] * (w + 1) for i in range(n + 1)]

for i in range(n):
    for sum_w in range(w + 1):
        if sum_w - wv[i][0] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - wv[i][0]] + wv[i][1])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(max(dp[n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]

dp = [[0] * (w + 1) for i in range(n + 1)]

for i in range(n):
    for sum_w in range(w + 1):
        if sum_w - wv[i][0] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - wv[i][0]] + wv[i][1])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(max(dp[n]))

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

dp = [[0] * (w + 1) for i in range(n + 1)]

for i in range(n):
    for sum_w in range(w + 1):
        if sum_w - wv[i][0] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - wv[i][0]] + wv[i][1])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(max(dp[n]))
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
sum_v = sum(wv[i][1] for i in range(n))
sum_w = sum(wv[i][0] for i in range(n))

dp = [[sum_w + 1] * (sum_v + 1) for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sum_v + 1):
        if j - wv[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wv[i][1]] + wv[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = 0
for j in range(sum_v + 1):
    if dp[n][j] <= w:
        ans = max(ans, j)
print(ans)

Fixed submission:
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
sum_v = sum(wv[i][1] for i in range(n))
sum_w = sum(wv[i][0] for i in range(n))

dp = [[sum_w + 1] * (sum_v + 1) for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sum_v + 1):
        if j - wv[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wv[i][1]] + wv[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = 0
for j in range(sum_v + 1):
    if dp[n][j] <= w:
        ans = max(ans, j)
print(ans)
Buggy python submission (verdict: Runtime Error):
sd = input()
t = input()

for i in range(len(sd) - len(t) + 1):
    cnt = 0
    q = 0
    for j in range(len(t)):
        if sd[i + j] == '?':
            q += 1
            continue
        if sd[i + j] == t[j]:
            cnt += 1
    if cnt == len(t) - q:
        idx = i
        s = sd[:idx] + t + sd[idx + len(t) + 1:]
        for k in range(len(sd)):
            if s[k] == '?':
                s = s[:k] + 'a' + s[k + 1:]
                print(s)
        break
else:
    print('UNRESTORABLE')

Fixed submission:
s = input()
t = input()

for i in range(len(s) - len(t) + 1)[::-1]:
    cnt = 0
    q = 0
    for j in range(len(t))[::-1]:
        if s[i + j] == '?':
            q += 1
        elif s[i + j] == t[j]:
            cnt += 1
    
    if cnt == len(t) - q:
        idx = i
        s = s[:idx] + t + s[idx + len(t):]
        for k in range(len(s)):
            if s[k] == '?':
                s = s[:k] + 'a' + s[k + 1:]
        print(s)
        break
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))
set_a = set(a + lower_a + upper_a)

temp_max = 0
for x in set_a:
    temp_max = max(temp_max, a.count(x) + lower_a.count(x) + upper_a.count(x))
print(temp_max)

Fixed submission:
import collections

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))
extended_a = collections.Counter(a + lower_a + upper_a)

print(extended_a.most_common()[0][1])

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))

temp_max = 0
for k in range(min(a) -1, max(a) + 2):
    cnt = 0
    for lower, upper in zip(lower_a, upper_a):
        if lower <= k <= upper:
            cnt += 1
    temp_max = max(temp_max, cnt)
print(temp_max)

Fixed submission:
import collections

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))
extended_a = collections.Counter(a + lower_a + upper_a)

print(extended_a.most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = [x1 - x0 for x1, x0 in zip(a[1:], a) if x1 - x0 != 0]

def sign(x):
    if x > 0:
        return 1
    elif x < 0:
        return -1
    else:
        return 0

cnt = 0
prev = d[0]
kept = 1
for i in range(1, len(d)):
    if sign(d[i]) == prev:
        kept = 1
    else:
        if kept == 1:
            cnt += 1
            kept = 0
        else:
            kept = 1
    prev = d[i]
else:
    cnt += 1
print(cnt)

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

cnt = n
prev = a[0]
trend ='N'

for i in range(1, n):
    if a[i] > prev:
        if (trend == 'U' or trend == 'N'):
            cnt -= 1
            trend ='U'
        else:
            trend = 'N'
    if a[i] < prev:
        if (trend == 'D' or trend == 'N'):
            cnt -= 1
            trend = 'D'
        else:
            trend = 'N'
    if a[i] == prev:
        cnt -= 1
    prev = a[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())-1
name = []

while n > 0:
    name.insert(0,n%26)
    n //= 26

name[len(name)-1] += 1

name = [chr(i+ord('a')-1) for i in name]

print("".join(name))

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

n = int(input())
name = []
hantei = [1,27,703,18279,475255,12356631,321272407,8353082583,217180147159,5646683826135,146813779479511,3817158266467287]

for i in range(len(hantei)-1):
    if hantei[i] <= n < hantei[i+1]:
        n -= hantei[i]
        while n > 0:
            name.insert(0,n%26)
            n //= 26
        while i+1 > len(name):
            name.insert(0,0)

name = [chr(ord('a')+i) for i in name]

print("".join(name))
Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
s = [input() for i in range(n)]

counter = collections.Counter(s)
most = counter.most_common()
ans = []
for i in range(n):
    if most[i][1] == most[0][1]:
        ans.append(most[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Fixed submission:
import collections
 
n = int(input())
s = [input() for i in range(n)]
 
counter = collections.Counter(s)
most = counter.most_common()
ans = []
for i in range(len(counter.keys())):
    if most[i][1] == most[0][1]:
        ans.append(most[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
s = [input() for i in range(n)]

counter = collections.Counter(s)
ans = []
for i in range(n):
    if counter.most_common()[i][1] == counter.most_common()[0][1]:
        ans.append(counter.most_common()[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Fixed submission:
import collections
 
n = int(input())
s = [input() for i in range(n)]
 
counter = collections.Counter(s)
most = counter.most_common()
ans = []
for i in range(len(counter.keys())):
    if most[i][1] == most[0][1]:
        ans.append(most[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = [input() for i in range(n)]

counter = collections.Counter(s)
ans = []
for i in sorted(list(counter.keys())):
    if counter[i] == counter.most_common()[0][1]:
        print(i)

Fixed submission:
import collections
 
n = int(input())
s = [input() for i in range(n)]
 
counter = collections.Counter(s)
most = counter.most_common()
ans = []
for i in range(len(counter.keys())):
    if most[i][1] == most[0][1]:
        ans.append(most[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = [input() for i in range(n)]

counter = collections.Counter(s)
ans = []
for i in counter.keys():
    if counter[i] == counter.most_common()[0][1]:
        ans.append(i)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Fixed submission:
import collections
 
n = int(input())
s = [input() for i in range(n)]
 
counter = collections.Counter(s)
most = counter.most_common()
ans = []
for i in range(len(counter.keys())):
    if most[i][1] == most[0][1]:
        ans.append(most[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
exist_odd = False

while exist_odd == False:
    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
            if n != i:
                count -= 1
            break
        else:
            a[i] = a[i] / 2
    count += 1
print(count)

Fixed submission:
s = input()
print(s.count('1'))

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

while exist_odd == False:
    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
            if n != i:
                count -= 1
            break
        else:
            a[i] = a[i] / 2
    count += 1
print(count)

Fixed submission:
s = input()
print(s.count('1'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
# list a[i]が偶数かどうかをチェック。ループはとりあえず省略する

exist_odd = False
# in_if = 0
# in_for = 0
# in_while = 0
while exist_odd == False:
    for i in range(n):
        if a[i] % 2 != 0:
            exist_odd = True
            if n != i:
                count -= 1
            break
        else:
            a[i] = a[i] / 2
        # in_if += 1
        # print(in_if)
    count += 1
print(count)

Fixed submission:
s = input()
print(s.count('1'))
Buggy python submission (verdict: Runtime Error):
n, q = [int(x) for x in input().split()]
s = input()
td = [input().split() for _ in range(q)]
lo, hi = 0, n-1

for t, d in reversed(td):
    if d == "L" and s[lo] == t:
        lo += 1
    elif d == "R" and s[hi] == t:
        hi -= 1
    if lo >= hi:
        print(0)
        break
else:
    print(hi-lo+1)


Fixed submission:
a,b,c = input().strip().split()

if a == b and b ==c:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

m = 1000000007
dp = [0] * 4
dp[0] = 1

for c in s:
  if c=='A':
    dp[1] += dp[0]
  elif c=='B':
    dp[2] += dp[1]
  elif c=='C':
    dp[3] += dp[2]
  elif c=='?':
    dp = [dp[0]*3, dp[0]+dp[1]*3, dp[1]+dp[2]*3, dp[2]+dp[3]*3]

print(dp[3]%m)

Fixed submission:
s = input()

m = 1000000007
dp = [0] * 4
dp[0] = 1

for c in s:
  if c=='A':
    dp[1] += dp[0]
  elif c=='B':
    dp[2] += dp[1]
  elif c=='C':
    dp[3] += dp[2]
  elif c=='?':
    dp = [(dp[0]*3)%m, (dp[0]+dp[1]*3)%m, (dp[1]+dp[2]*3)%m, (dp[2]+dp[3]*3)%m]

print(dp[3]%m)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort
s = input().strip()
k = int(input())

sublist = []
for i in range(len(s)):
    if len(sublist)>k:
        sublist = sublist[:k]
    for j in range(i+1,len(s)+1):
        if s[i:j] not in sublist and (len(sublist)<k or sublist[k-1]>s[i:j]):
            insort(sublist,s[i:j])

print(sublist[k-1])

Fixed submission:
from bisect import insort
s = input().strip()
k = int(input())

sublist = []
for i in range(len(s)):
    if len(sublist)>k:
        sublist = sublist[:k]
    for j in range(i+1,len(s)+1):
        if len(sublist)>=k and sublist[k-1]<s[i:j]:
            break
        if s[i:j] not in sublist and (len(sublist)<k or sublist[k-1]>s[i:j]):
            insort(sublist,s[i:j])

print(sublist[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().strip()
k = int(input())

subset = set()
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        subset.add(s[i:j])

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

Fixed submission:
from bisect import insort
s = input().strip()
k = int(input())

sublist = []
for i in range(len(s)):
    if len(sublist)>k:
        sublist = sublist[:k]
    for j in range(i+1,len(s)+1):
        if len(sublist)>=k and sublist[k-1]<s[i:j]:
            break
        if s[i:j] not in sublist and (len(sublist)<k or sublist[k-1]>s[i:j]):
            insort(sublist,s[i:j])

print(sublist[k-1])
Buggy python submission (verdict: Runtime Error):
a, b, c  = [int(x) for x in input().strip().split()]

res = {x for seq in [range(a,min(a+c, b)), range(b, max(a,b-c), -1)] for x in seq}

if a==b:
    res = {a}

for x in sorted(list(res)):
    print(x)


Fixed submission:
s = input()

if all(x in s for x in ['a', 'b', 'c']):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
m = {}

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in m:
        m[s] = 1
    else:
        m[s] += 1

m = int(input())
for i in range(m):
    t = input().strip()
    if t not in m:
        m[t] = -1
    else:
        m[t] -= 1

res = max(m.values())
if res<0:
    res = 0

print(res)

Fixed submission:
memo = {}

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = 1
    else:
        memo[s] += 1

n = int(input())
for i in range(n):
    s = input().strip()
    if s not in memo:
        memo[s] = -1
    else:
        memo[s] -= 1

res =  max(memo.values())
if res<0:
    res = 0

print(res)