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

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

def count(A, B, x):
    N = len(A)
    M = len(B)
    res = 0
    r = -1
    for l in range(N):
        a = A[l]
        while r < M-1 and B[r+1]*a <= x:
            r += 1
        res += r+1
    return res

def count2(A, x):
    res = 0
    for a in A:
        if a*a <= x:
            res += 1
    return res
        

N, K = map(int, readline().split())
A = list(map(int, readline().split()))
Am = []
Ap = []

minus = 0
zero = 0
plus = 0
for a in A:
    if a < 0:
        minus += 1
        Am.append(-a)
    elif a == 0:
        zero += 1
    else:
        plus += 1
        Ap.append(a)

ms = minus*plus
zs = ms + zero*(minus+plus) + zero*(zero-1)//2

Am.sort()
Ap.sort()
Amr = Am[::-1]
Apr = Ap[::-1]

if K <= ms:
    K = ms+1-K
    ok = max(max(Am+[0]), max(Ap+[0]))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if count(Amr, Ap, med) >= K:
            ok = med
        else:
            ng = med
    ans = -ok
elif K <= zs:
    ans = 0
else:
    K -= zs
    ok = max(max(Am+[0]), max(Ap+[0]))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if (count(Amr, Am, med) + count(Apr, Ap, med) - count2(Am, med) - count2(Ap, med))//2 >= K:
            ok = med
        else:
            ng = med
    ans = ok

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

def count(A, B, x):
    N = len(A)
    M = len(B)
    res = 0
    r = -1
    for l in range(N):
        a = A[l]
        while r < M-1 and B[r+1]*a <= x:
            r += 1
        res += r+1
    return res

def count2(A, x):
    res = 0
    for a in A:
        if a*a <= x:
            res += 1
    return res
        

N, K = map(int, readline().split())
A = list(map(int, readline().split()))
Am = []
Ap = []

minus = 0
zero = 0
plus = 0
for a in A:
    if a < 0:
        minus += 1
        Am.append(-a)
    elif a == 0:
        zero += 1
    else:
        plus += 1
        Ap.append(a)

ms = minus*plus
zs = ms + zero*(minus+plus) + zero*(zero-1)//2

Am.sort()
Ap.sort()
Amr = Am[::-1]
Apr = Ap[::-1]

if K <= ms:
    K = ms+1-K
    ok = max(max(Am), max(Ap))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if count(Amr, Ap, med) >= K:
            ok = med
        else:
            ng = med
    ans = -ok
elif K <= zs:
    ans = 0
else:
    K -= zs
    ok = max(max(Am), max(Ap))**2
    ng = 0
    while abs(ok-ng)>1:
        med = (ok+ng)//2
        if (count(Amr, Am, med) + count(Apr, Ap, med) - count2(Am, med) - count2(Ap, med))//2 >= K:
            ok = med
        else:
            ng = med
    ans = ok

print(ans)
Problem p02782 (python)

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

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(2341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

def accumulate2d(X2):
    X = X2
    N = len(X)
    M = len(X[0])
    
    for i in range(N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X

r1, c1, r2, c2 = map(int, readline().split())

def calc(R, C):
    if min(R, C) == 0:
        return 1
    res = R
    for i in range(1, C):
        res = (res + comb(R+i, i+1)) % MOD
    return res
r2 += 1
c2 += 1
print((calc(r2, c2)-calc(r2, c1)-calc(r1, c2)+calc(r1, c1))%MOD)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

MOD = 10**9+7
def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%MOD
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], MOD -2, MOD)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % MOD
    return frac, fraci
frac, fraci = frac(1341398)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%MOD

def accumulate2d(X2):
    X = X2
    N = len(X)
    M = len(X[0])
    
    for i in range(N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X

r1, c1, r2, c2 = map(int, readline().split())

def calc(R, C):
    if min(R, C) == 0:
        return 1
    res = R
    for i in range(1, C):
        res = (res + comb(R+i, i+1)) % MOD
    return res
r2 += 1
c2 += 1
print((calc(r2, c2)-calc(r2, c1)-calc(r1, c2)+calc(r1, c1))%MOD)
Problem p02823 (python)

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

N, A, B = map(int, readline().split())

ans = None
if (B - A) % 2 == 0:
    ans = (B-A)//2
else:
    ans = A + (B - A - 1)//2
    ans = min(ans, N-B+1 + (-A+B-1)//2)    
print(ans)

Buggy submission (verdict: Runtime Error):
    for _ in range(test_case):
import sys
readline = sys.stdin.readline

N, A, B = map(int, readline().split())

ans = None
if (B - A) % 2 == 0:
    ans = (B-A)//2
else:
    ans = A + (B - A - 1)//2
    ans = min(ans, N-B+1 + (-A+B-1)//2)    
print(ans)
Problem p02929 (python)

Fixed submission:
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(200000)

def count(S):
    res = 1
    cnt = 0
    for s in S:
        if s:
            cnt += 1
        else:
            res = (res*cnt)%mod
            cnt -= 1
        if cnt < 0:
            return 0
    return res
N = int(input())
S = [1 if s == 'B' else 0 for s in input().strip()]
L = 2*N
S = [(S[i] + i)%2 for i in range(L)]
if sum(S) != N:
    print(0)
else:
    print(count(S)*frac[N]%mod)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(10000)

def count(S):
    res = 1
    cnt = 0
    for s in S:
        if s:
            cnt += 1
        else:
            res = (res*cnt)%mod
            cnt -= 1
    
    return res
N = int(input())
S = [1 if s == 'B' else 0 for s in input().strip()]
L = 2*N
S = [(S[i] + i)%2 for i in range(L)]
print(count(S)*frac[N]%mod)
Problem p02974 (python)

Fixed submission:
mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2+2*N) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])
Problem p02975 (python)

Fixed submission:
from collections import Counter
N = int(input())

A = list(map(int, input().split()))
if all(a == 0 for a in A):
        print('Yes')
elif N % 3:
    print('No')
else:
    n = N//3
    CA = Counter(A)
    ans = 'Yes'
    t = []
    for k, v in CA.items():
        if not v % n:
            t.append(k)
        
    if len(t) == 3 and (t[0]^t[1] == t[2] and t[2]^t[1] == t[0] and t[0]^t[2] == t[1]):
        ans = 'Yes'
    elif len(t) == 2 and (t[0] == 0 or t[1] == 0):
        ans = 'Yes'
    else:
        ans = 'No'
        
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
if M & 1:
    print(-1)
    sys.exit()
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1
Edge1 = Edge[:]
Dim1 = Dim[:] 
Ans = []
used = set()
for i in sorted(range(N), key = lambda x: Dim[x]):
    Edge[i].sort(key = lambda x: Dim[x], reverse = True)
    while Dim[i] > 1:
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j1 = Edge[i].pop()
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j2 = Edge[i].pop()
        Ans.append((i+1, j1+1))
        Ans.append((i+1, j2+1))
        Dim[i] -= 2
        Dim[j1] -= 1
        Dim[j2] -= 1
        used.add((i, j1))
        used.add((i, j2))
        used.add((j1, i))
        used.add((j2, i))
if not len(Ans) == M:
    Edge = Edge1[:]
    Dim = Dim1[:]
    Ans = []
    used = set()
    for i in sorted(range(N), key = lambda x: Dim[x]):
        Edge[i].sort(key = lambda x: Dim[x], reverse = True)
    while Dim[i] > 1:
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j1 = Edge[i].pop()
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j2 = Edge[i].pop()
        Ans.append((i+1, j1+1))
        Ans.append((i+1, j2+1))
        Dim[i] -= 2
        Dim[j1] -= 1
        Dim[j2] -= 1
        used.add((i, j1))
        used.add((i, j2))
        used.add((j1, i))
        used.add((j2, i))

for a in Ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())

A = list(map(int, input().split()))
if all(a == 0 for a in A):
        print('Yes')
elif N % 3:
    print('No')
else:
    n = N//3
    CA = Counter(A)
    ans = 'Yes'
    t = []
    for k, v in CA.items():
        if v != n:
            ans = 'No'
        t.append(k)
        
    if not (t[0]^t[1] == t[2] and t[2]^t[1] == t[0] and t[0]^t[2] == t[1]):
        ans = 'No'
    print(ans)
Problem p03005 (python)

Fixed submission:
N, K = map(int, input().split())
if K == 1:
    print(0)
else:
    print(N-K)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
X, Y = list(map(list, zip(*XY)))

P = [abs(x1 - x2) for x1, x2 in combinations(X, 2)]
P = list(set(P))
Q = [abs(y1 - y2) for y1, y2 in combinations(Y, 2)]
Q = list(set(Q))
ans = 10**10
XY.sort()
for p in P:
    for q in Q:
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y+q))
        ans = min(ans, la)
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y-q))
        ans = min(ans, la)
print(ans)
Problem p03006 (python)

Fixed submission:
from collections import Counter
from itertools import combinations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
A = Counter()
for (x1, y1), (x2, y2) in combinations(XY, 2):
    A[(x1-x2, y1-y2)] += 1
if N == 1:
    print(1)
else:
    print(N - max(A.values()))

Buggy submission (verdict: Runtime Error):
from itertools import combinations
from operator import itemgetter
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
X, Y = list(map(list, zip(*XY)))

P = [abs(x1 - x2) for x1, x2 in combinations(X, 2)]
P = set(P)
if 0 in P:
    P.remove(0)
P = list(P)
Q = [abs(y1 - y2) for y1, y2 in combinations(Y, 2)]
Q = set(Q)
if 0 in Q:
    Q.remove(0)
Q = list(Q)
ans = 10**10

XY.sort()
for p in P:
    S = set()
    la = 0
    for x, y in XY:
        if (x, y) not in S:
            la += 1
        S.add((x+p, y))
    ans = min(ans, la)
XY1 = XY[:]
XY1.sort(ley = itemgetter(1))
for q in Q:
    S = set()
    la = 0
    for x, y in XY1:
        if (x, y) not in S:
            la += 1
        S.add((x, y+q))
    ans = min(ans, la)

for p in P:
    for q in Q:
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y+q))
        ans = min(ans, la)
        S = set()
        la = 0
        for x, y in XY:
            if (x, y) not in S:
                la += 1
            S.add((x+p, y-q))
        ans = min(ans, la)
print(ans)
Problem p03023 (python)

Fixed submission:
N = int(input())
print((N-2)*180)

Buggy submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)
Problem p03027 (python)

Fixed submission:
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
        continue
    elif x == 0:
        print(0)
        continue
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Buggy submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
    elif x == 0:
        print(0)
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Buggy submission (verdict: Runtime Error):
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)
Problem p03047 (python)

Fixed submission:
N, K = map(int, input().split())
print(N - K + 1)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
S = [input() for _ in range(N)]
a = 0
b = 0
ans = 0
aru = False
zenaru = True
for s in S:
    TB = (s[0] == 'B')
    TA = (s[-1] == 'A')
    ans += s.count('AB')
    if TB:
        b += 1
        aru = True
    if TA:
        a += 1
        aru = True
    if TA ^ TB:
        zenaru = False
if a == 0 or b == 0:
    print(ans)
    sys.exit()
print(ans + min(a, b) - zenaru)
Problem p03081 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
TX = [list(input().split()) for _ in range(Q)]
def checkl(i):
    for t, x in TX:
        if S[i] == t:
            i += 1 if x == 'R' else -1
        if i < 0:
            return False
        if i == N:
            i = N - 1
    return True
def checkr(i):
    for t, x in TX:
        if S[i] == t:
            i += 1 if x == 'R' else -1
        if i > N - 1:
            return False
        if i == -1:
            i = 0
    return True

ok = N
ng = -1
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if checkl(med):
        ok = med
    else:
        ng = med
L = ok
ok = -1
ng = N
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if checkr(med):
        ok = med
    else:
        ng = med
R = ok
print(max(0, R - L + 1))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = input()
TD = [sys.stdin.readline().split() for _ in range(Q)]

def check(k):
    np = k
    for t, d in TD:
        if s[np] == t:
            if d == 'L':
                np -= 1
            else:
                np += 1
        if not 0 <= np <= N-1:
            return False
    return True

ok = N
ng = -1
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if check(med):
        ok = med
    else:
        ng = med

L = ok

ok = -1
ng = N
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if check(med):
        ok = med
    else:
        ng = med

R = ok
print(R - L + 1)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
TX = [list(input().split()) for _ in range(Q)]
def checkl(i):
    for t, x in TX:
        if S[i] == t:
            i += 1 if x == 'R' else -1
        if i < 0:
            return False
    return True
def checkr(i):
    for t, x in TX:
        if S[i] == t:
            i += 1 if x == 'R' else -1
        if i > N - 1:
            return False
    return True

ok = N
ng = -1
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if checkl(med):
        ok = med
    else:
        ng = med
L = ok
ok = -1
ng = N
while abs(ok - ng) > 1:
    med = (ok + ng)//2
    if checkr(med):
        ok = med
    else:
        ng = med
R = ok
print(max(0, R - L + 1))
Problem p03089 (python)

Fixed submission:
from sys import exit
N = int(input())
B = list(map(int, input().split()))
ctr = 0
ans = []
for _ in range(N):
    ctr = 0
    for i, b in enumerate(B, 1):
        if i == b:
            ctr = i
    ans.append(ctr)
    if ctr == 0:
        print(-1)
        exit()
    B = B[:ctr-1] + B[ctr:]
print('\n'.join([str(s) for s in ans][::-1]))

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
N, M = map(int, readline().split())

def check(Edge, Dim):
    N = len(Edge)
    if any(d&1 for d in Dim):
        return 'No'
    if max(Dim) > 4:
        return 'Yes'
    dc4 = Dim.count(4)
    if dc4 <= 1:
        return 'No'
    if dc4 >= 3:
        return 'Yes'
    a = Dim.index(4)
    st = (a+1)%N
    used = set([a, st])
    stack = [st]
    while stack:
        vn = stack.pop()
        for vf in Edge[vn]:
            if vf not in used:
                stack.append(vf)
                used.add(vf)
    if len(used) == N:
        return 'No'
    return 'Yes'
Edge = [[] for _ in range(N)]
Dim = [0]*N

for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1

print(check(Edge, Dim))

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
P = list(map(int, input().split()))
Pmin = [None]*N
Pmax = [None]*N
for i, p in enumerate(P):
    k = 20000
    for pj in P[:i]:
        if pj > p:
            k = min(k, pj)
    Pmin[p-1] = k

for i, p in enumerate(P):
    k = -1
    for pj in P[:i:-1]:
        if pj < p:
            k = max(k, pj)
    Pmax[p-1] = k
dp = [[10**15]*(N+2) for _ in range(N+2)]
dp[1][N] = 0
for k in range(N-1, -1, -1):
    for i in range(1, N - k + 1):
        x = dp[i][i+k]
        if Pmax[i+k-1] + 1 <= i:
            dp[i][i+k-1] = min(dp[i][i+k-1], x)
        else:
            dp[i][i+k-1] = min(dp[i][i+k-1], x+A)
        if Pmin[i-1] - 1 >= i+k:
            dp[i+1][i+k] = min(dp[i+1][i+k], x)
        else:
            dp[i+1][i+k] = min(dp[i+1][i+k], x+B)
print(min([dp[i][i] for i in range(1, N+1)]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
Edge = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    Edge[a - 1] += 1
    Edge[b - 1] += 1
if any([i%2 == 1 for i in Edge]):
    print('No')
elif len([i for i in Edge if i > 4]) > 0:
    print('Yes')
elif len([i for i in Edge if i > 2]) > 1:
    print('Yes')
else:
    print('No')
Problem p03125 (python)

Fixed submission:
def inpl(): return list(map(int, input().split()))

A, B = inpl()
print([A+B, B-A][B%A > 0])

Buggy submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))

def match(x):
    return (2, 5, 5, 4, 5, 6, 3, 7, 6)[x-1]
N, M = inpl()
A = inpl()
A.sort(reverse = True)
matnum = set([match(a) for a in A])
maxdig = 1
Dig = [{0}]
for i in range(1,1+N//min(matnum)):
    k = set()
    for v in Dig[-1]:
        for a in matnum:
            k.add(a+v)
    if N in k:
        maxdig = i
    Dig.append(k)
N1 = N
anstr = ''
for i in range(maxdig, 0, -1):
    for a in A:
        if N1-match(a) in Dig[i-1]:
            anstr += str(a)
            N1 -= match(a)
            break
        
print(anstr)
Problem p03128 (python)

Fixed submission:
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = inpl()
A.sort(reverse = True)

inf = float('inf')
match = (inf, 2, 5, 5, 4, 5, 6, 3, 7, 6)
matnum = set([match[a] for a in A])
dp = [0]+[-inf]*N

for i in range(1, N+1):
    dp[i] = max([10*dp[max(-1,i-match[a])] + a for a in A])

print(''.join(sorted(str(dp[-1]), reverse = True)))

Buggy submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = inpl()
A.sort(reverse = True)

inf = float('inf')
match = (inf, 2, 5, 5, 4, 5, 6, 3, 7, 6)
matnum = set([match[a] for a in A])
dp = [0]+[-inf]*N

for i in range(1, N+1):
    dp[i] = max([10*dp[i-match[a]] + a for a in A])

print(''.join(sorted(str(dp[-1]), reverse = True)))

Buggy submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = inpl()
A.sort(reverse = True)

inf = float('inf')
match = (inf, 2, 5, 5, 4, 5, 6, 3, 7, 6)
matnum = set([match[a] for a in A])
dp = [0]+[-inf]*N

for i in range(1, N+1):
    dp[i] = max([10*dp[i-a] + a for a in A])

print(''.join(sorted(str(dp[-1]), reverse = True)))
Problem p03139 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
N, A, B = inpl()
print(min(A,B), max(A+B-N, 0))

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict
N, M = inpl()
Edge = defaultdict(lambda: [])
Par = set(range(N)) 
for _ in range(N-1+M):
    A, B = inpl()
    Par.discard(B-1)
    Edge[A-1].append(B-1)
par = list(Par)[0]
dist = [0]*N
Q = deque([par])
while Q:
    st = Q.pop()
    for en in Edge[st]:
        if dist[en] < dist[st] + 1:
            dist[en] = dist[st] + 1
            if len(Edge[en]) == 1:
                Q.append(en)
            else:
                Q.appendleft(en)
Ans = [0]*N
Q = deque([par]) 
while Q:
    st = Q.pop()
    for en in Edge[st]:
        if dist[en] == dist[st] + 1:
            Ans[en] = st+1
            Q.appendleft(en)
for i in Ans:
    print(i)