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

Fixed submission:
N,M=[int(_) for _ in input().split()]
PS=[input().split() for _ in range(M)]
count=[0]*(N+1)
isac=[0]*(N+1)
for p,s in PS:
 p=int(p)
 if isac[p]==1:
    continue
 if s=='AC':
  isac[p]=1
 else:
  count[p]+=1
wa=0
ac=0
for i in range(N+1):
 if isac[i]==1:
  ac+=1
  wa+=count[i]
print(ac,wa)

Buggy submission (verdict: Runtime Error):
N, M, *PS = open(0).read().split()
N, M = [int(_) for _ in [N, M]]
cor = [0] * (N + 1)
pen = [0] * (N + 1)
for p, s in PS:
    p = int(p)
    if cor[p] == 1:
        continue
    if s == 'AC':
        cor[p] = 1
    else:
        pen[p] += 1
ans = [0, 0]
for i in range(1, N + 1):
    if cor[p] == 0:
        continue
    ans[0] += 1
    ans[1] += pen[ @ ]
print(*ans)
Problem p02807 (python)

Fixed submission:
import itertools
mod = 10**9 + 7
stdin = [int(_) for _ in open(0).read().split()]
N, X = stdin[0], stdin[1:]
A = [pow(i, mod - 2, mod) for i in range(N)]
D = [0] + [a - b for a, b in zip(X[1:], X[:-1])]
f = 1
for i in range(1, N):
    f *= i
    f %= mod
A = [d * f * a % mod for d, a in zip(D, list(itertools.accumulate(A)))]
print(sum(A) % mod)

Buggy submission (verdict: Runtime Error):
import numpy as np

stdin = np.array([int(_) for _ in open(0).read().split()])
N, X = stdin[0], stdin[1:]
A = np.array([pow(i, mod - 2, mod) for i in range(N)])
D = X[1:] - X[:-1]
f = 1
for i in range(1, N):
    f *= i
    f %= mod
A = np.cumsum(A)
A *= f
A %= mod
A[1:] *= D
A %= mod
print(np.sum(A) % mod)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
i8 = np.int64
mod = 10**9 + 7


def main(stdin):
    N, X = stdin[0], stdin[1:]
    D = X[1:] - X[:-1]
    f = 1
    for i in range(1, N):
        f *= i
        f %= mod
    A = np.cumsum(np.array([pow(i, mod - 2, mod) for i in range(N)], dtype=i8), dtype=i8)
    A *= f
    A %= mod
    A[1:] *= D
    A %= mod
    print(np.sum(A) % mod)


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    main(stdin)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
i8 = np.int64
mod = 10**9 + 7


def main(stdin):
    N, X = stdin[0], stdin[1:]
    D = X[1:] - X[:-1]
    f = 1
    for i in range(1, N):
        f *= i
        f %= mod
    A = np.cumsum(np.array([pow(i, mod - 2, mod) for i in range(N)], dtype=i8))
    A *= f
    A %= mod
    A[1:] *= D
    A %= mod
    print(np.sum(A) % mod)


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    main(stdin)
Problem p02814 (python)

Fixed submission:
import fractions
import math
#gcd = math.gcd
gcd = fractions.gcd
n, m = [int(_) for _ in input().split()]
a = sorted([int(_) // 2 for _ in input().split()])
lcm = a[0]
for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
    if lcm > 10**10:
        print(0)
        exit()
for b in a:
    if (lcm // b) % 2 == 0:
        print(0)
        exit()
ans = m // lcm
if ans % 2 == 0:
    ans -= 1
if ans < 0:
    print(0)
    exit()
print(ans // 2 + 1)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = [int(_) for _ in input().split()]
a = np.array([int(_) // 2 for _ in input().split()], dtype=np.int64)
l = np.lcm.reduce(a)
ans = m // l
if ans % 2 == 0:
    ans -= 1
print(ans // 2 + 1)
Problem p02890 (python)

Fixed submission:
import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, n + 1):
    r = 0
    while i - j > 0:
        if (i - j) * c[-1 - j] <= acc[-1 - j]:
            r = acc[-1 - j] // (i - j)
            break
        else:
            j += 1
    print(r)
for _ in range(N - n):
    print(0)

Buggy submission (verdict: Runtime Error):
import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, N + 1):
    r = 0
    if j < n - 1:
        while i - j > 0:
            if (i - j) * c[-1 - j] <= acc[-1 - j]:
                r = acc[-1 - j] // (i - j)
                break
            else:
                j += 1
    print(r)

Buggy submission (verdict: Runtime Error):
import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, N + 1):
    r = 0
    while i - j > 0:
        if (i - j) * c[-1 - j] <= acc[-1 - j]:
            r = acc[-1 - j] // (i - j)
            break
        else:
            j += 1
    print(r)
Problem p02909 (python)

Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy submission (verdict: Runtime Error):
#dp[i][j]:S[i-x:i]==S[j-x:j]となる最大のx
import numpy as np

def solve(NS):
    N = NS[0]
    S = NS[1:]
    dp=np.zeros((N+1,N+1),dtype=int)
    for i in range(N - 1):
        for j in range(i + 1, N):
            dp[i][j] = min(j - i, dp[i - 1][j - 1] + 1) if S[i] == S[j] else 0
    return dp.max()

def main():
    NS = np.array([int(input())] + [ord(_) for _ in input()])
    print(solve(NS))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', 'i8(i8[:])')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()
Problem p02911 (python)

Fixed submission:
N, K, Q = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(Q)]
s = [K - Q] * (N + 1)
for a in A:
    s[a] += 1
for i in range(1, N + 1):
    if s[i] > 0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np


def main(stdin):
    N, K, Q = stdin[:3]
    ans = np.full(N + 1, K - Q, dtype=np.int64)
    for i in stdin[3:]:
        ans[i] += 1
    ans = np.where(ans > 0, 'Yes', 'No')
    return ans[1:]


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8[:](i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    print(*main(stdin), sep='\n')

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np


def main(stdin):
    N, K, Q = stdin[:3]
    ans = np.full(N + 1, K - Q, dtype=np.int64)
    for i in stdin[3:]:
        ans[i] += 1
    ans = np.where(ans > 0, 'Yes', 'No')
    return ans[1:]


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    print(*main(stdin), sep='\n')

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np


def main(stdin):
    N, K, Q = stdin[:3]
    ans = np.full(N + 1, K - Q, dtype=np.int64)
    for i in stdin[3:]:
        ans[i] += 1
    ans = np.where(ans > 0, 'Yes', 'No')
    print(*ans[1:], sep='\n')


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    main(stdin)
Problem p02923 (python)

Fixed submission:
N = int(input())
H = [int(_) for _ in input().split()]
ans = now = 0
for i in range(N - 1):
    if H[i] < H[i + 1]:
        ans = max(ans, now)
        now = 0
    else:
        now += 1
print(max(ans, now))

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(_) for _ in input().split()]
ans = 0
for i in range(N - 1):
    if H[i] < H[i + 1]:
        ans = max(ans, now)
        now = 0
    now += 1
print(max(ans, now))
Problem p02926 (python)

Fixed submission:
import itertools
N = int(input())
XY = [[int(_) for _ in input().split()] for _ in range(N)]
xy1 = []
xy2 = []
xy3 = []
xy4 = []
for x, y in XY:
    if x >= 0:
        if y >= 0:
            xy1 += [[x, y]]
        else:
            xy4 += [[x, y]]
    else:
        if y >= 0:
            xy2 += [[x, y]]
        else:
            xy3 += [[x, y]]
xy1.sort(key=lambda xy: float('inf') if xy[0] == 0 else xy[1] / xy[0])
xy2.sort(key=lambda xy: xy[1] / xy[0])
xy3.sort(key=lambda xy: xy[1] / xy[0])
xy4.sort(key=lambda xy: -float('inf') if xy[0] == 0 else xy[1] / xy[0])
XY = xy1 + xy2 + xy3 + xy4
N = len(XY)
XY *= 2
acc = list(
    itertools.accumulate(XY, func=lambda a, b: [a[0] + b[0], a[1] + b[1]]))
ans = 0
for i in range(N):
    for j in range(i + 1, i + N + 1):
        x = acc[j][0] - acc[i][0]
        y = acc[j][1] - acc[i][1]
        ans = max(ans, x**2 + y**2)
print(ans**0.5)

Buggy submission (verdict: Runtime Error):
import math
import itertools
N = int(input())
TX = []
for _ in range(N):
    x, y = [int(_) for _ in input().split()]
    t = math.atan2(y, x)
    TX += [(t, x)]
    TY += [(t, y)]
TX.sort()
TY.sort()
xa = [0] + list(itertools.accumulate(TX))
ya = [0] + list(itertools.accumulate(TY))
ans = 0
for i, j in itertools.combinations(range(len(xa)), 2):
    ans = max(ans, (xa[j] - xa[i])**2 + (ya[j] - ya[i])**2)
print(ans**0.5)
Problem p02957 (python)

Fixed submission:
A, B = [int(_) for _ in input().split()]
if (A + B) % 2:
    print('IMPOSSIBLE')
else:
    print((A + B) // 2)

Buggy submission (verdict: Runtime Error):
if (A + B) % 2:
    print('IMPOSSIBLE')
else:
    print((A + B) // 2)
Problem p02960 (python)

Fixed submission:
import itertools
S = input()[::-1]
mod = 10**9 + 7
A = [0] * 13
N = 0
for i, v in enumerate(S):
    p = pow(10, i, 13)
    if v == '?':
        A[p] += 1
    else:
        N += int(v) * p
        N %= 13
dp = [0] * 13
dp[N] = 1
for i, v in enumerate(A):
    for _ in range(v):
        dp_old = dp[:]
        for j, k in itertools.product(range(1, 10), range(13)):
            x = (j * i + k) % 13
            dp[x] += dp_old[k]
            dp[x] %= mod
print(dp[5])

Buggy submission (verdict: Runtime Error):
import itertools
S = input()[::-1]
mod = 10**9 + 7
A = [0] * 13
N = 0
for i, v in enumerate(S):
    p = pow(10, i, 13)
    if v == '?':
        A[p] += 1
    else:
        N += int(v) * p
        N %= 13
dp = [0] * 13
dp[N] = 1
for i, v in enumerate(A):
    for _ in range(v):
        dp_old = dp.copy()
        for j, k in itertools.product(range(1, 10), range(13)):
            x = (j * i + k) % 13
            dp[x] += dp_old[k]
            dp[x] %= mod
print(dp[5])
Problem p02973 (python)

Fixed submission:
from bisect import bisect_right as br
INF = 10 ** 10
n = int(input())
alst = [int(input()) for _ in range(n)][::-1]
dp = [INF] * (n + 1)
dp[0] = -1
ans = 0
for a in alst:
  ind = br(dp, a)
  dp[ind] = a
  ans = max(ans, ind)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]


class SegmentTree():
    def __init__(self, array, f, e, size):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        e : 
            identity element of the monoid
        size : int
            limit for array size
        """
        self.f = f
        self.e = e
        self.size = size
        self.n = n = len(array)
        self.dat = dat = [e] * n + array + [e] * (2 * size - 2 * n)
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def modify(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            dat[p >> 1] = f(dat[p], dat[p ^ 1])
            p >>= 1

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, e, n, dat = self.f, self.e, self.n, self.dat
        res = e
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(res, dat[r])
            l >>= 1
            r >>= 1
        return res


size = 10**5+5
e = (0,0)
def f2(xs,ys):
    if ys[0]>0:
        return ys
    else:
        return xs
ST = SegmentTree(list(zip([size]+[0]*(size-1),range(size))), f=lambda x,y:f2(x,y), e=e, size=size)
ans = 0
for a in A:
    bs = ST.query(0,a)
    if bs[1]==0:
        c=ST.query(a,a+1)[0]
        ST.modify(a,(c+1,a))
        ans+=1
    else:
        c=ST.query(a,a+1)[0]
        ST.modify(a,(c+1,a))
        ST.modify(bs[0],(bs[0],bs[1]-1))
print(ans)
Problem p02975 (python)

Fixed submission:
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for x in A:
    count[x] += 1
if len(count) == 1:
    a = list(count.keys())[0]
    if a == 0:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[b] == count[a] * 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for a in A:
    count[a] += 1
if len(count) == 1:
    a = count.keys()[0]
    if a ^ a == a:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[a] == 1 and count[b] == 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for a in A:
    count[a] += 1
if len(count) == 1:
    a = count.keys()[0]
    if a ^ a == a:
        print('Yes')
        exit()
elif len(count) == 2:
    a, b = count.keys()
    if a ^ a == b and b ^ b == a and count[a] == count[b]:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')
Problem p02999 (python)

Fixed submission:
X, A = [int(_) for _ in input().split()]
if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
    dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
    if S[n] == T[m]:
        dp[n + 1][m + 1] += dp[n][m]
    dp[n + 1][m + 1] %= mod
print(dp[-1][-1])
Problem p03061 (python)

Fixed submission:
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
gcd = lambda x, y: gcd(y, x % y) if x % y else y
L = list(itertools.accumulate(A, func=gcd))
R = list(itertools.accumulate(A[::-1], func=gcd))[::-1]
ans = max(R[1], L[-2])
for i in range(1, N - 1):
    ans = max(ans, gcd(L[i - 1], R[i + 1]))
print(ans)
# https://img.atcoder.jp/abc125/editorial.pdf

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(_) for _ in input().split()]


class SegmentTree():
    def m(self, v1, v2):  # ***monoid***
        return math.gcd(v1, v2)

    def __init__(self, array):
        m = self.m
        e = self.e = 0  # ***identity element***
        size = self.size = 10**6  # ***limit for array size***
        n = self.n = len(array)
        dat = self.dat = [e] * n + array + [e] * (2 * size - 2 * n)
        for i in range(n - 1, 0, -1):  # build
            dat[i] = m(dat[i << 1], dat[i << 1 | 1])

    def modify(self, p, v):  # set value at position p (0-indexed)
        m, n, dat = self.m, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            dat[p >> 1] = m(dat[p], dat[p ^ 1])
            p >>= 1

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        m, e, n, dat = self.m, self.e, self.n, self.dat
        res = e
        l += n
        r += n
        while l < r:
            if l & 1:
                res = m(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = m(res, dat[r])
            l >>= 1
            r >>= 1
        return res


ST = SegmentTree(A)
ans = 0
for i, a in enumerate(A):
    ST.modify(i, ST.e)
    ans = max(ans, ST.query(0, N))
    ST.modify(i, a)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
gcd = lambda x, y: gcd(y, x % y) if x % y else y
G = list(itertools.accumulate(A, func=gcd))
g = G[-1]
if G[0] == g:
    ans = list(itertools.accumulate(A[1:], func=gcd))[-1]
else:
    for i in range(1, N - 1):
        if G[i] == g:
            ans = max(
                gcd(G[i - 1],
                    list(itertools.accumulate(A[i + 1:], func=gcd))[-1]),
                G[-2])
            break
print(ans)
Problem p03076 (python)

Fixed submission:
import math
ABCDE = [int(input()) for _ in range(5)]
print(
    sum([10 * math.ceil(_ / 10)
         for _ in ABCDE]) + min([10] + [_ % 10 for _ in ABCDE if _ % 10]) - 10)

Buggy submission (verdict: Runtime Error):
import math
ABCDE = [int(input()) for _ in range(5)]
print(
    sum([10 * math.ceil(_ / 10)
         for _ in ABCDE]) + min([_ % 10 for _ in ABCDE if _ % 10]) - 10)
Problem p03111 (python)

Fixed submission:
import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = 10**10
for K in itertools.product(range(4), repeat=N):
    A = [[] for _ in range(4)]
    for i in range(N):
        A[K[i]] += [L[i]]
    if len(A[1]) and len(A[2]) and len(A[3]):
        cost = 10 * (N - len(A[0]) - 3)
        cost += abs(a - sum(A[1]))
        cost += abs(b - sum(A[2]))
        cost += abs(c - sum(A[3]))
        ans = min(cost, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = 10**10
for K in itertools.product(range(4), repeat=N):
    A = [[] for _ in range(N)]
    for i in range(N):
        A[K[i]] += [L[i]]
    if len(A[1]) and len(A[2]) and len(A[3]):
        cost = 10 * (N - len(A[0]) - 3)
        cost += abs(a - sum(A[1]))
        cost += abs(b - sum(A[2]))
        cost += abs(c - sum(A[3]))
        ans = min(cost, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
N, a, b, c = [int(_) for _ in input().split()]
L = [int(input()) for _ in range(N)]
ans = float('inf')
for K in itertools.product(range(4), repeat=N):
    A = [[] for _ in range(N)]
    for i in range(N):
        k = K[i]
        A[k] += [L[i]]
    if len(A[1]) and len(A[2]) and len(A[3]):
        cost = 10 * (max(len(A[1]) - 1, 0) + max(len(A[2]) - 1, 0) + max(
            len(A[3]) - 1, 0))
        cost += abs(a - sum(A[1]))
        cost += abs(b - sum(A[2]))
        cost += abs(c - sum(A[3]))
        ans = min(cost, ans)
print(ans)
Problem p03128 (python)

Fixed submission:
import collections
N, M = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])
n_m = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
m_n = {}
for a in A:
    m_n[n_m[a]] = a
dp = collections.defaultdict(lambda: -float('inf'))
dp[0] = 0
for i in range(1, N + 1):
    dp[i] = max(dp[i - m] + 1 for m, n in m_n.items())
ans = ''
ms = sorted(m_n.keys(), key=lambda _: m_n[_], reverse=True)
d = dp[N]
while N:
    for m in ms:
        if dp[N - m] == dp[N] - 1:
            N -= m
            ans += str(m_n[m])
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
N, M = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])
n_m = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
m_n = {}
for a in A:
    m_n[n_m[a]] = a
countm = len(m_n)
dp = collections.defaultdict(lambda: -float('inf'))
dp[0] = 0
for i in range(1, N + 1):
    dp[i] = max(dp[i - m] + 1 for m, n in m_n.items())
ans = ''
ms = sorted(m_n.keys(), key=lambda _: m_n[_], reverse=True)
d = dp[N]
while N:
    for m in ms:
        if dp[N - m] == dp[N] - 1:
            N -= m
            ans += f'{m_n[m]}'
            break
print(ans)
Problem p03138 (python)

Fixed submission:
import math
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
count = [0] * 40
if K == 0:
    print(sum(A))
    exit()
for a in A:
    for i in range(40):
        if a >> i & 1:
            count[i] += 1
ans = sum(count[_] * 2**_ for _ in range(int(math.log2(K)) + 1, 40))
while K:
    b = int(math.log2(K))
    if count[b] * 2 > N:
        #0をたてる
        ans += count[b] * 2**b
        K = 2**b - 1
    else:
        #1を立てる
        ans += (N - count[b]) * 2**b
        if K - 2**b:
            ans += sum(count[_] * 2**_
                       for _ in range(1 + int(math.log2(K - 2**b)), b))
        else:
            ans += sum(count[_] * 2**_ for _ in range(b))
        K -= 2**b
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
count = [0] * 39
for a in A:
    for i in range(39):
        if a >> i & 1:
            count[i] += 1
if K:
    ans = sum(count[_] * 2**_ for _ in range(int(math.log2(K)) + 1, 39))
else:
    ans = sum(A)
while K:
    b = int(math.log2(K))
    if count[b] * 2 > N:
        #0をたてる
        ans += count[b] * 2**b
        K = 2**b - 1
    else:
        #1を立てる
        ans += (N - count[b]) * 2**b
        if K - 2**b:
            ans += sum(count[_] * 2**_
                       for _ in range(1 + int(math.log2(K - 2**b)), b))
        else:
            ans += sum(count[_] * 2**_ for _ in range(b))
        K -= 2**b
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
count = [0] * 39
for a in A:
    for i in range(40):
        if a >> i & 1:
            count[i] += 1
if K:
    ans = sum(count[_] * 2**_ for _ in range(int(math.log2(K)) + 1, 39))
else:
    ans = sum(A)
while K:
    b = int(math.log2(K))
    if count[b] * 2 > N:
        #0をたてる
        ans += count[b] * 2**b
        K = 2**b - 1
    else:
        #1を立てる
        ans += (N - count[b]) * 2**b
        if K - 2**b:
            ans += sum(count[_] * 2**_
                       for _ in range(1 + int(math.log2(K - 2**b)), b))
        else:
            ans += sum(count[_] * 2**_ for _ in range(b))
        K -= 2**b
print(ans)