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

Fixed submission:
n = int(input())
d = int(input())
p = 10**9+7
if d == 1:
    print(n % p)
    exit()
N = [int(i) for i in list(str(n))]
DP0 = [0] * d
DP1 = [0] * d
DP1[0] += 1
for i in N:
    DP0_ = [0] * d
    DP1_ = [0] * d
    for r in range(d):
        for j in range(i):
            DP0_[r] += DP1[(r-j) % d]
            DP1_[r] += DP1[(r-j) % d]
        DP0_[r] += DP0[(r-i) % d]
        DP1_[r] += DP1[(r-i) % d]
        for j in range(i+1, 10):
            DP0_[r] += DP0[(r-j) % d]
            DP1_[r] += DP0[(r-j) % d]
        DP0_[r], DP1_[r] = DP0_[r] % p, DP1_[r] % p
    DP0, DP1 = DP0_, DP1_
print((DP1[0]-1+p) % p)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
n = int(input())
d = int(input())
p = 10**9+7
DP = {}
DP[-1] = [0]*d
DP[0] = [0]*d
DP[0][0] = 1
def dp(i):
    try:
        return DP[i]
    except:
        pass
    q, r = i//10, i % 10
    DP[i] = []
    for j in range(d):
        tmp = 0
        for k in range(r+1):
            tmp += dp(q)[(j-k) % d]
        for k in range(r+1, 10):
            tmp += dp(q-1)[(j-k) % d]
        DP[i].append(tmp)
    return DP[i]
print((dp(n)[0]-1) % p)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = int(input())
p = 10**9+7
DP = {}
DP[-1] = [0]*d
DP[0] = [0]*d
DP[0][0] = 1
def dp(i):
    try:
        return DP[i]
    except:
        pass
    q, r = i//10, i % 10
    DP[i] = []
    for j in range(d):
        tmp = 0
        for k in range(r+1):
            tmp += dp(q)[(j-k) % d]
        for k in range(r+1, 10):
            tmp += dp(q-1)[(j-k) % d]
        DP[i].append(tmp)
    return DP[i]
print((dp(n)[0]-1) % p)
Problem p03262 (python)

Fixed submission:
from functools import reduce
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	def gcd(a,b):
		while b>0:
			a,b=b,a%b
		return a
	print(reduce(gcd,LL))

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	def gcd(a,b):
		while b>0:
			a,b=b,a%b
		return a
	def GCD(LIST):
		if len(LIST)==2:
			return gcd(LIST[0],LIST[1])
		else:
			return(GCD([gcd(LIST[0],LIST[1])]+LIST[2::]))
	print(GCD(LL))

Buggy submission (verdict: Runtime Error):
import math
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])

N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	print(GCD(LL))

Buggy submission (verdict: Runtime Error):
import math
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])

N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	print(GCD(LL))

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	import math
	from functools import reduce
	def gcd(*numbers):
		return reduce(math.gcd, numbers)
	print(gcd(*LL))

Buggy submission (verdict: Runtime Error):
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	def GCD(LIST):
		if len(LIST)==2:
			return math.gcd(LIST[0],LIST[1])
		else:
			return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])
	print(GCD(LL))

Buggy submission (verdict: Runtime Error):
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N)]
	print(GCD(LL))

Buggy submission (verdict: Runtime Error):
import math
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=sorted(x+[X])
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])
if N==1:
	print(abs(X-x[0]))
else:
	LL=[L[i+1]-L[i] for i in range(N-1)]
	print(GCD(LL))
Problem p03309 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=sorted([A[i]-i for i in range(N)])
if N%2==0:
	C=int((B[int(N/2)]+B[int(N/2-1)])/2)
else:
	C=B[int((N-1)/2)]
print(sum([abs(b-C) for b in B]))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[A[i]-i for i in range(N)]
C=median(B)
print(sum([b-C for b in B]))
Problem p03337 (python)

Fixed submission:
A,B=map(int,input().split())
print(max([A+B,A-B,A*B]))

Buggy submission (verdict: Runtime Error):
A,B=input().split()
print(max([A+B,A-B,A*B]))
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="Yes"
for i in range(H):
    for j in range(W):
        Tonari=[]
        if i>0:
            Tonari.append(S[i-1][j])
        if i<H-1:
            Tonari.append(S[i+1][j])
        if j>0:
            Tonari.append(S[i][j-1])
        if j<W-1:
            Tonari.append(S[i][j+1])
        if S[i][j]=='#' and all([t=='.' for t in Tonari]):
            ans="No"
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="No"
for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            if i>0 and S[i-1][j]=='#':
                ans="Yes"
            if i<H-1 and S[i+1][j]=='#':
                ans="Yes"
            if j>0 and S[i][j-1]=='#':
                ans="Yes"
            if j<W-1 and S[i][j+1]='#':
                ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="No"
for i in range(W):
    for j in range(H):
        if S[i][j]=='#':
            if i>0 and S[i-1][j]=='#':
                ans="Yes"
            if i<W-1 and S[i+1][j]=='#':
                ans="Yes"
            if j>0 and S[i][j-1]=='#':
                ans="Yes"
            if j<H-1 and S[i][j+1]=='#':
                ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans="Yes"
for i in range(W):
    for j in range(H):
        Tonari=[]
        if i>0:
            Tonari.append(S[i-1][j])
        if i<W-1:
            Tonari.append(S[i+1][j])
        if j>0:
            Tonari.append(S[i][j-1])
        if j<H-1:
            Tonari.append(S[i][j+1])
        if S[i][j]=='#' and all([t=='.' for t in Tonari]):
            ans="No"
print(ans)
Problem p03469 (python)

Fixed submission:
S=list(input())
S[3]='8'
print("".join(S))

Buggy submission (verdict: Runtime Error):
S=input()
S[3]=8
print(S)
Problem p03644 (python)

Fixed submission:
n = int(input())
# n = 100
m = 0
x = 1
for i in range(1, n+1):
    a = i
    c = 0
    while a % 2 == 0:
        a = a//2
        c += 1
    if c > m:
        x = i
    m = max(m, c)
print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
# n = 100
m = 0
for i in range(1, n+1):
    a = i
    c = 0
    while a % 2 == 0:
        a = a//2
        c += 1
    if c > m:
        x = i
    m = max(m, c)
print(x)
Problem p02607 (python)

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

ans = 0
for i in range(n):
    if (i + 1)%2 == 1 and a[i] % 2 == 1:
        ans += 1
print(ans)

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

ans = 0
for i in range(n//2+1):
    if a[2*i] % 2 == 1:
        ans += 1
print(ans)
Problem p03324 (python)

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

if N < 100:
  print(100**D*N)
elif N == 100:
  print(100**D*101)

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

if N < 99:
  print(100**D*N)
elif N = 100:
  print(100**D*101)
Problem p03478 (python)

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

ans = 0
for i in range(1, n+1):
    s = str(i)
    l = 0
    for j in range(len(s)):
        l += int(s[j])
    if l >= a and l <= b:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

ans = 0
for i in range(1, n+1):
    sum = 0
    while i != 0:
        sun += i%10
        i = i//10
    if sum >= a and sum <= b:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

ans = 0
for i in range(1, n+1):
    sum = 0
    while i != 0:
        sun += i%10]
        i = i//10
    if sum >= a and sum <= b:
        ans += i
print(ans)
Problem p02678 (python)

Fixed submission:
from collections import defaultdict
from queue import Queue
g = defaultdict(list)
visted = defaultdict(bool)
N, M = map(int, input().split())
for i in range(M):
    A, B = map(int, input().split())
    g[A].append(B)
    g[B].append(A)

h = [-1] * (N+1)

h2 = defaultdict(list)
def solve(v):
    visited = set()
    q = Queue()
    visited.add(v)
    h[v] = 0
    h2[0].append(v)
    q.put(v)
    while not q.empty():
        v = q.get()
        for c in g[v]:
            if not c in visited:
                visited.add(c)
                h[c] = h[v] + 1
                h2[h[v]+1].append(c)
                q.put(c)

solve(1)
ans = []

for v in range(2, N+1):
    i = h[v]

    for c in g[v]:
        if h[c] == i-1:
            ans.append(c)
            break


print('Yes')
for v in ans:
    print(v)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from queue import Queue
g = defaultdict(list)
visted = defaultdict(bool)
N, M = map(int, input().split())
for i in range(M):
    A, B = map(int, input().split())
    g[A].append(B)
    g[B].append(A)

h = {}
h2 = defaultdict(list)
def solve(v):
    height = 0
    visited = set()
    q = Queue()
    visited.add(v)
    h[v] = height
    h2[height].append(v)
    q.put(v)
    while not q.empty():
        v = q.get()
        height += 1
        for c in g[v]:
            if not c in visited:
                visited.add(c)
                h[c] = height
                h2[height].append(c)
                q.put(c)

solve(1)
ans = [0] * (N+1)

print('Yes')
for v in range(2, N+1):
    i = h[v]
    print(h2[i-1][0])
Problem p02850 (python)

Fixed submission:
from collections import Counter, defaultdict
from queue import Queue
G = defaultdict(list)

C = Counter()
N = int(input())
ans = {}
o = []
for i in range(N-1):
    a, b = map(int, input().split())
    C[a] += 1
    C[b] += 1
    G[a].append(b)
    G[b].append(a)
    ans[(a, b)] = 0
    o.append((a,b))

cs = [0] * (N+1)
def bfs(v):
    ret = 0
    visited = set()
    q = Queue()
    visited.add(v)
    q.put(v)
    while not q.empty():
        v = q.get()
        counter = 1
        for c in G[v]:
            if not c in visited:
                visited.add(c)
                if counter == cs[v]:
                    counter += 1
                cs[c] = ans[(c,v)] = ans[(v,c)] = counter
                counter += 1
                q.put(c)

bfs(1)
print(C.most_common(1)[0][1])
for a,b in o:
    print(ans[(a,b)])

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
G = defaultdict(list)
C = Counter()
N = int(input())
ans = {}
o = []
for i in range(N-1):
    a, b = map(int, input().split())
    C[a] += 1
    C[b] += 1
    G[a].append(b)
    G[b].append(a)
    ans[(a, b)] = 0
    o.append((a,b))

a = C.most_common(1)[0][0]
b = C.most_common(1)[0][1]

visited = [False] * (N+1)
def dfs(v, p):
    visited[v] = True
    counter = 1
    for c in G[v]:
        if not visited[c]:
            if p != 0 and counter == ans[(v, p)]:
                counter += 1
            ans[(v, c)] = ans[(c, v)] = counter
            counter += 1
            dfs(c, v)

dfs(a, 0)

print(b)
for a,b in o:
    print(ans[(a,b)])

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
G = defaultdict(list)
C = Counter()
N = int(input())
ans = {}
o = []
for i in range(N-1):
    a, b = map(int, input().split())
    C[a] += 1
    C[b] += 1
    G[a].append(b)
    G[b].append(a)
    ans[(a, b)] = 0
    o.append((a,b))

a = C.most_common(1)[0][0]
b = C.most_common(1)[0][1]

visited = [False] * (N+1)
def dfs(v, p):
    visited[v] = True
    counter = p
    for c in G[v]:
        if not visited[c]:
            c2,v2 = min(c,v), max(c,v)
            counter += 1
            if counter == N+1:
                counter = 1
            ans[(c2, v2)] = counter
            dfs(c, counter)

dfs(a, 0)

print(b)
for a,b in o:
    print(ans[(a,b)])
Problem p02909 (python)

Fixed submission:
a = ['Sunny', 'Cloudy', 'Rainy']
s = input()

i = a.index(s)
print(a[(i + 1) % 3])

Buggy submission (verdict: Runtime Error):
a = ['Sunny', 'Cloudy', 'Rainy']
s = input()

i = a.index(s)
print(a[i + 1 % 3])
Problem p02939 (python)

Fixed submission:
S = input()

l = [0] * (len(S) + 1)
l[1] = 1
if S[0] == S[1]:
    l[2] = 1
else:
    l[2] = 2

for i in range(3, len(S)+1):
    if S[i-1] != S[i-2]:
        l[i] = l[i-1] + 1
    else:
        l[i] = l[i-3] + 2

print(l[-1])

Buggy submission (verdict: Runtime Error):
S = input()
def f(i):
    if i == 0:
        return 0
    if i == 1:
        return 1
    if i == 2:
        if S[i-1] == S[i-2]:
            return 1
        else:
            return 2
    if S[i-1] == S[i-2]:
        return f(i-1) + 1
    else:
        return f(i-3) + 2

print(f(len(S)))
Problem p02993 (python)

Fixed submission:
l = ['%d%d'%(i, i) for i in range(10)]
S = input()
if sum([S.count(i) for i in l]) > 0:
    print('Bad')
else:
    print('Good')

Buggy submission (verdict: Runtime Error):
l = ['%d%d'%(i, i) for i in range(10)]
S = input()
if S.count(l) > 0:
    print('Bad')
else:
    print('Good')
Problem p02996 (python)

Fixed submission:
N = int(input())
l = [[int(j) for j in input().split()] for i in range(N)]
l = sorted(l, key=lambda x:x[1])
s = 0
ans = 'Yes'
for a,b in l:
    s += a
    if s > b:
        ans = 'No'
        break

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = [[int(j) for j in input().split()] for i in range(N)]
l = sorted(l, lambda x:x[1])
s = 0
ans = 'Yes'
for a,b in l:
    s += a
    if s > b:
        ans = 'No'
        break

print('Yes')
Problem p03026 (python)

Fixed submission:
from collections import defaultdict
from sys import setrecursionlimit, getrecursionlimit

setrecursionlimit(100*getrecursionlimit())

N = int(input())
g = defaultdict(list)
K = []
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    K.append((a,b))

C = sorted([int(i) for i in input().split()], reverse=True)

a = {i:0 for i in range(1, N+1)}

visited = defaultdict(bool)
ct = 0
def dfs(v):
    global ct
    visited[v] = True
    a[v] = C[ct]
    ct += 1
    for c in g[v]:
        if not visited[c]:
            dfs(c)

dfs(1)

ans1 = 0
ans2 = ' '.join([str(b) for b in a.values()])
for b, c in K:
    ans1 += min(a[b], a[c])

print(ans1)
print(ans2)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from sys import setrecursionlimit, getrecursionlimit

setrecursionlimit(10*getrecursionlimit())

N = int(input())
g = defaultdict(list)
K = []
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    K.append((a,b))

C = sorted([int(i) for i in input().split()], reverse=True)

a = {i:0 for i in range(1, N+1)}

visited = defaultdict(bool)
ct = 0
def dfs(v):
    global ct
    visited[v] = True
    a[v] = C[ct]
    ct += 1
    for c in g[v]:
        if not visited[c]:
            dfs(c)

dfs(1)

ans1 = 0
ans2 = ' '.join([str(b) for b in a.values()])
for b, c in K:
    ans1 += min(a[b], a[c])

print(ans1)
print(ans2)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from sys import setrecursionlimit, getrecursionlimit

setrecursionlimit(10*getrecursionlimit())

N = int(input())
g = defaultdict(list)
K = []
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    K.append((a,b))

C = sorted([int(i) for i in input().split()], reverse=True)

a = {i:0 for i in range(1, N+1)}

visited = defaultdict(bool)
ct = 0
def dfs(v):
    global ct
    visited[v] = True
    a[v] = C[ct]
    ct += 1
    for c in g[v]:
        if not visited[c]:
            dfs(c)

dfs(1)

ans1 = 0
ans2 = ' '.join([str(b) for b in a.values()])
for b, c in K:
    ans1 += min(a[b], a[c])

print(ans1)
print(ans2)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
g = defaultdict(list)
K = []
for i in range(N-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
    K.append((a,b))

C = sorted([int(i) for i in input().split()], reverse=True)

a = {i:0 for i in range(1, N+1)}

visited = defaultdict(bool)
ct = 0
def dfs(v):
    global ct
    visited[v] = True
    a[v] = C[ct]
    ct += 1
    for c in g[v]:
        if not visited[c]:
            dfs(c)

dfs(1)

ans1 = 0
ans2 = ' '.join([str(b) for b in a.values()])
for b, c in K:
    ans1 += min(a[b], a[c])

print(ans1)
print(ans2)
Problem p03030 (python)

Fixed submission:
n = int(input())
l = []
for i in range(n):
  a, b = input().split()
  l.append((i+1, a, int(b)))
  
l = sorted(l, key=lambda x: (x[1],-x[2]))
for i in l:
  print(i[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(N):
  a, b = input().split()
  l.append((i+1, a, int(b)))
  
l = sorted(l, key=lambda x: (x[1],x[2]))
for i in l:
  print(i[0])
Problem p03044 (python)

Fixed submission:
from sys import setrecursionlimit, getrecursionlimit
setrecursionlimit(getrecursionlimit()*10000)
from collections import defaultdict
g = defaultdict(list)
visited = defaultdict(bool)
N = int(input())
ans = [0] * N

def dfs(v, d=0):
    if visited[v]:
        return
    visited[v] = True
    if d % 2:
        ans[v-1] = 1
    for c,w in g[v]:
        dfs(c, d+w)

for j in range(N-1):
    u,v,w = map(int, input().split())
    g[u].append((v, w))
    g[v].append((u, w))

dfs(1)

for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
g = defaultdict(list)
visited = defaultdict(bool)
N = int(input())
ans = [0] * N

def dfs(v, d=0):
    if visited[v]:
        return
    visited[v] = True
    if d % 2:
        ans[v-1] = 1
    for c,w in g[v]:
        dfs(c, d+w)

for j in range(N-1):
    u,v,w = map(int, input().split())
    g[u].append((v, w))
    g[v].append((u, w))

dfs(1)

for a in ans:
    print(a)
Problem p03069 (python)

Fixed submission:
N = int(input())
S = input()

b = [0] * N
for i, s in enumerate(S):
    if s == '#':
        b[i] = b[i-1] + 1
    else:
        b[i] = b[i-1]
b = [0] + b + [0]
ans = N
for i in range(N+1):
    ans = min(ans, b[i] + N - i - b[N] + b[i-1])

print(ans)

Buggy submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func ini() {
	var buf = make([]byte, 10000)
	sc.Buffer(buf, 1000000)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	ini()
	N, _ := strconv.Atoi(nextLine())
	S := nextLine()
	b := make([]int, N+1)

	for i, s := range S {
		if s == '#' {
			b[i+1] = b[i] + 1
		} else {
			b[i+1] = b[i]
		}
	}
	ans := N
	for i := 1; i < N+1; i++ {
		ans = min(ans, b[i]+N-i-b[N]+b[i-1])
	}
	fmt.Println(ans)
}
Problem p03085 (python)

Fixed submission:
a = input()
if a == 'A': print('T')
elif a == 'T':print('A')
elif a == 'C': print('G')
else:print('C')

Buggy submission (verdict: Runtime Error):
a = input()
if a == 'A': print('T')
elif a == 'T':print('A')
else a == 'C': print('G')
else:print('C')
Problem p03105 (python)

Fixed submission:
A, B, C = map(int, input().split())
print(min(B//A, C))

Buggy submission (verdict: Runtime Error):
100 1 10
Problem p03128 (python)

Fixed submission:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

# dp[i] = i本使ってできる最大の数

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

dp = [-1] * (N + 1)
dp[0] = 0

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

print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

# dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - h[a] < 0: continue
        dp[i] = max(dp[i-h[a]] + 1, dp[i])

digit = dp[N]
ans = ''

n = N
for d in range(digit):
    for a in A:
        if dp[n - h[a]] == digit - 1:
            ans += str(a)
            n -= h[a]
            digit -= 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

# dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
dp = [-float('inf')] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - h[a] < 0: continue
        dp[i] = max(dp[i-h[a]] + 1, dp[i])

digit = dp[N]
ans = ''

n = N
for d in range(digit):
    for a in A:
        if dp[n - h[a]] == digit - 1:
            ans += str(a)
            n -= h[a]
            digit -= 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

# xを作るために使うマッチの本数
h = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

# dp[i] = i 本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
dp = [-float('inf')] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        #if i - h[a] < 0: continue
        dp[i] = max(dp[i-h[a]] + 1, dp[i])


digit = dp[N]
ans = ''

n = N
for d in range(digit):
    for a in A:
        if dp[n - h[a]] == digit - 1:
            ans += str(a)
            n -= h[a]
            digit -= 1
            break
print(ans)
Problem p03138 (python)

Fixed submission:
from numpy import array
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
k = '{0:040b}'.format(K)
a = array([[int(i) for i in '{0:040b}'.format(a)] for a in A])
ans = list(k)

f = False
for i in range(40):
    if k[i] == '0' and not f:
        continue
    ik = a[:, [i]].sum()
    zk = N - ik
    if ik > zk:
        ans[i] = '0'
        f = True
    else:
        ans[i] = '1'

ans = ''.join(ans)
k = int(ans, 2)
print(sum([x ^ k for x in A]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
m = max(K, max(A))
l = len('{0:b}'.format(m))
fs = '{0:0'+str(l)+'b}'
import numpy as np
a = np.array([[int(i) for i in fs.format(a)] for a in A])
ans = ''

for i in range(N):
    ik = a[:, [i]].sum()
    zk = N - ik
    if ik > zk:
        ans += '0'
    else:
        ans += '1'

def f(X):
    return sum([x ^ X for x in A])

print(f(int(ans,2)))
Problem p03193 (python)

Fixed submission:
N, H, W = map(int, input().split())
ans = 0
for i in range(N):
    a, b = map(int, input().split())
    if a >= H and b >= W:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268