Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = []
    for i in range(n):
        for j in range(i+1,n+1):
            l = bisect.bisect_left(L,s[i:j])
            if l < len(L):
                if L[l] == s[i:j]:
                    continue

            if l < K:
                L.insert(l,s[i:j])
    # print(L)
    print(L[K-1])

main()

Fixed submission:
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,min(n+1,i+6)):
            L.add(s[i:j])

    L = list(L)
    L.sort()
    print(L[K-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,n+1):
            L.add(s[i:j])
    L = list(L)
    L.sort()
    print(L[K-1])

main()

Fixed submission:
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,min(n+1,i+6)):
            L.add(s[i:j])

    L = list(L)
    L.sort()
    print(L[K-1])
main()
Buggy python submission (verdict: Runtime Error):
port numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))
SUM = 0
cnt = 0
print(throw_all)
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)


Fixed submission:
import numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))[::-1]
SUM = 0
cnt = 0
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+1,i+1])
    # print(A)

    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            ans.append([i+1,i+2])

else:
    for i in range(N):
        if A[i] > 0:
            A[i] += MIN
            ans.append(min_i,i+1)
    # print(A)

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])

print(len(ans))
for a in ans:
    print(*a)



Fixed submission:
N = int(input())
A = list(map(int,input().split()))

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+1,i+1])
    # print(A)

    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            ans.append([i+1,i+2])

else:
    for i in range(N):
        if A[i] > 0:
            A[i] += MIN
            ans.append([min_i+1,i+1])
    # print(A)

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])
print(len(ans))
for a in ans:
    print(*a)

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

ans = []
i = 0
while A[i] > 0:
    i += 1
n = i
for i in range(n-1,0,-1):
    if A[i] < A[i-1]:
        A[i-1] += A[i]
        ans.appned(i+1,i)


for i in range(n,N-1):
    if A[i] <= A[i+1]:
        continue
    else:
        if A[i+1] >= 0:
            A[i+1] += A[i]
            ans.append([i+1,i+2])
        else:
            A[i+1] += 2 * A[i]
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])

# print(A)
print(len(ans))
for a in ans:
    print(*a)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))

MIN,MAX = 10**7,-10**7
ans = []
for i in range(N):
    if MIN > A[i]:
        MIN =A[i]
        min_i = i
    if MAX < A[i]:
        MAX = A[i]
        max_i = i

if abs(MIN) <= abs(MAX):
    for i in range(N):
        if A[i] < 0:
            A[i] += MAX
            ans.append([max_i+1,i+1])
    # print(A)

    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            ans.append([i+1,i+2])

else:
    for i in range(N):
        if A[i] > 0:
            A[i] += MIN
            ans.append([min_i+1,i+1])
    # print(A)

    for i in range(N-1,0,-1):
        if A[i] < A[i-1]:
            A[i-1] += A[i]
            ans.append([i+1,i])
print(len(ans))
for a in ans:
    print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

A.sort()
B.sort()
C.sort()

count = 0
for a in A:
    i = bisect.bisect_right(B,a)
    for b in B[i::]:
        j = bisect.bisect_right(C,b)
        count += len(C[j::])
        
print(count)

Fixed submission:
import bisect

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

A.sort()
B.sort()
C.sort()

count = 0
for b in B:
    i = bisect.bisect_left(A,b)
    j = bisect.bisect_right(C,b)
    count += i * (N - j)

print(count)

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

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

my_list = []
A.sort()
B.sort()
C.sort()

count = 0
for a in A:
    i = bisect.bisect_right(B,a)
    for b in B[i::]:
        j = bisect.bisect_right(C,b)
        count += len(C[j::])
        
print(count)

Fixed submission:
import bisect

N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]

A.sort()
B.sort()
C.sort()

count = 0
for b in B:
    i = bisect.bisect_left(A,b)
    j = bisect.bisect_right(C,b)
    count += i * (N - j)

print(count)
Buggy python submission (verdict: Runtime Error):
import math
from collections import defaultdict
import itertools
N = int(input())
town = [[int(i) for i in input().split(' ')] for _ in range(N)]

dist = 0
c = 0
for v in itertools.permutations(town,len(town)):
    c += 1
    sx = v[0][0]
    sy = v[0][1]
    for i in v[1::]:
        dist += math.sqrt((sx - i[0]) ** 2 + (sy - i[1]) ** 2)
        sx, sy = i[0], i[1]

print(dist/c)

Fixed submission:
N = int(input())
T = [int(i) for i in input().split(' ')]
M = int(input())
PX = []
for _ in range(M):
    PX.append([int(i) for i in input().split(' ')])
SUM = sum(T)

for p,x in PX:
    print(SUM - T[p-1] + x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    ac = a.copy()
    del ac[i]
    print(max(ac))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    ac = a.copy()
    del ac[i]
    print(max(ac))


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)
Buggy python submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7


def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    return [w[0], w[1]]


def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m


def Cmb(n, k):
    res = 1
    for i in range(1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * mod_inv(i, mod) % mod
    for i in range(1, n - k + 1):
        res = res * mod_inv(i, mod) % mod
    return res


n, m = list(map(int, input().split()))
a = [int(input()) for _ in range(m)]
l = len(a)

if 1 in [a[i + 1] - a[i] for i in range(l - 1)]:
    print(0)
    sys.exit()

b = [-1] + a + [n + 1]
c = []
for bi, bi2 in zip(b[:-1], b[1:]):
    c.append((bi2 - 1) - (bi + 1))  # width 2 を取れる数


def count(n):
    ret = 0
    for i in range(n // 2 + 1):
        ret += Cmb(n - i, i) % mod
    return ret


ans = 1
for ci in c:
    ans *= count(ci) % mod
    ans %= mod

print(ans)


Fixed submission:
p, q, r = list(map(int, input().split()))
print(p + q + r - max(p, q, r))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import factorial

input = sys.stdin.readline

Mod = 10**9 + 7


def Cmb(n, k):
    return factorial(n) // (factorial(n - k) * factorial(k)) % Mod


n, m, k = list(map(int, input().split()))

ans = 0

for i in range(1, n + 1):
    ans += i * (n - i) * m**2 % Mod

for i in range(1, m + 1):
    ans += i * (m - i) * n**2 % Mod

ans *= Cmb(n * m - 2, k - 2)
ans %= Mod

print(ans)


Fixed submission:
import sys
from math import factorial

input = sys.stdin.readline

Mod = 10**9 + 7


def Cmb(n, k):
    return factorial(n) // (factorial(n - k) * factorial(k)) % Mod


n, m, k = list(map(int, input().split()))

ans = 0

for i in range(1, n + 1):
    ans += i * (n - i) * m**2 % Mod

for i in range(1, m + 1):
    ans += i * (m - i) * n**2 % Mod

ans *= Cmb(n * m - 2, k - 2)
ans %= Mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

Mod = 10**9 + 7


def Cmb(n, k):
    return factorial(n) // (factorial(n - k) * factorial(k)) % Mod


n, m, k = list(map(int, input().split()))

ans = 0

for i in range(1, n + 1):
    ans += i * (n - i) * m**2 % Mod

for i in range(1, m + 1):
    ans += i * (m - i) * n**2 % Mod

ans *= Cmb(n * m - 2, k - 2)
ans %= Mod

print(ans)


Fixed submission:
import sys
from math import factorial

input = sys.stdin.readline

Mod = 10**9 + 7


def Cmb(n, k):
    return factorial(n) // (factorial(n - k) * factorial(k)) % Mod


n, m, k = list(map(int, input().split()))

ans = 0

for i in range(1, n + 1):
    ans += i * (n - i) * m**2 % Mod

for i in range(1, m + 1):
    ans += i * (m - i) * n**2 % Mod

ans *= Cmb(n * m - 2, k - 2)
ans %= Mod

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n // m == n % m:
            ans += m

print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m != 0 and n // m == n % m:
            ans += m

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd

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

if n <= 2:
    print(max(a))
    sys.exit()

l = [0] * n
r = [0] * n
l[0] = a[0]
r[-1] = a[-1]

for i in range(n - 1):
    l[i + 1] = gcd(l[i], a[i + 1])
    r[-1 - (i + 1)] = gcd(r[-1 - i], a[-1 - (i + 1)])

ans = 0
for i in range(n - 2):
    ans = max(ans, gcd(l[i], r[i + 2]))
ans = max(ans, l[-2], r[1])
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
 
 
L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
 
for i in range(N-1, -1, -1):
    R[i] = gcd(R[i+1], A[i])
 
ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
 
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))

a = list(set(a))

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


if n <= 2:
    print(max(a))
else:
    a.sort()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2]))
    print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
 
 
L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
 
for i in range(N-1, -1, -1):
    R[i] = gcd(R[i+1], A[i])
 
ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
 
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = [ai + bi for (ai, bi) in product(a, b)]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c)]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

d = e - a
k = int(input())

ans = "Yay!" if k >= d else ":("
print(ans)

Buggy python submission (verdict: Runtime Error):
for i in range(5)
	a[i]= int(input())

d = a[4] - a[0]
k = int(input())

ans = 'Yay!' if k >= d else ':('
print(ans)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

d = e - a
k = int(input())

ans = "Yay!" if k >= d else ":("
print(ans)
Buggy python submission (verdict: Runtime Error):
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return ((n // 10) + 1) * 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, (map(lambda e: e % 10, a))))

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)


Fixed submission:
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return ((n // 10) + 1) * 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, list(map(lambda e: e % 10, a))))

    if len(a2) == 0:
        return 10

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)

Buggy python submission (verdict: Runtime Error):
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return (n // 10) * 10 + 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, (map(lambda e: e % 10, a))))

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)


Fixed submission:
a = []

for i in range(5):
    a.append(int(input()))


def ceil10(n):
    if n % 10 == 0:
        return n
    else:
        return ((n // 10) + 1) * 10


def min_1(a):
    a2 = list(filter(lambda a: a > 0, list(map(lambda e: e % 10, a))))

    if len(a2) == 0:
        return 10

    return min(a2)


ans = sum(map(ceil10, a)) - 10 + min_1(a)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = [ai + bi for (ai, bi) in product(a, b)]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c)]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)


Fixed submission:
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ab = [ai + bi for (ai, bi) in product(a[:k], b[:k])]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c[:k])]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ab = [ai + bi for (ai, bi) in product(a, b)]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c)]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)

Fixed submission:
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ab = [ai + bi for (ai, bi) in product(a[:k], b[:k])]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c[:k])]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()

for i in range(q):
    l,r = map(int, input().split())
    sr = s[l-1:r]
    print(sr.count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)

for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, (input().split()))
ans = b
for i in range(a, b):
    ans ^= i
print(ans)


Fixed submission:
a, b = map(int, (input().split()))
if a % 2 ==0:
    if b % 2 ==0:
        print(int((b - a) /2 % 2) ^ b)
    else:
        print(int((b - a + 1)/2 % 2))
else:
    if b % 2 ==0:
        print(a ^ b ^ int((b - a)/2 % 2))
    else:
        print(a ^ int((b - a)/2 %2))
Buggy python submission (verdict: Runtime Error):
from math import gcd
a, b, k = list(map(int, input().split()))
t = gcd(a,b)
c = []
for i in range(1,t+1):
    if t % i ==0:
        c.append(i)
print(c[-k])

Fixed submission:
from fractions import gcd
a, b, k = list(map(int, input().split()))
t = gcd(a, b)
c = []
for i in range(1,t+1):
    if t % i ==0:
        c.append(i)
print(c[-k])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    INF = 10e11
    ret = INF

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    INF = 10e11
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(input())
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from datetime import datetime


def solve(S: str):
    if datetime.strptime(S, "%Y/%m/%d") <= datetime.strptime("2019/4/30", "%Y/%m/%d"):
        print("Heisei")
    else:
        print("TBD")


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)


Fixed submission:
a, b = map(int, input().split())
print(a+b if b%a ==0 else b-a)
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

ret = gcd(a[0], a[1])
for e in a[2:]:
    ret = gcd(ret, e)

print(ret)


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


def gcd(x, y):
    while y != 0:
        x, y = y, x % y

    return x


ret = gcd(a[0], a[1])

for e in a[2:]:
    ret = gcd(ret, e)

print(ret)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from math import gcd

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

print(reduce(gcd, a))


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


def gcd(x, y):
    while y != 0:
        x, y = y, x % y

    return x


ret = gcd(a[0], a[1])

for e in a[2:]:
    ret = gcd(ret, e)

print(ret)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = dp[i]
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)


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

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)