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

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x = f()[0]
    if x >= 1200:
        print("ARC")
    else:
        print("ABC")

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x = f()[0]
    if x >= 1200:
        print("ARC")
    else print("ABC")

solve()
Problem p03815 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x = f()[0]
    ans = (x//11)*2 
    remain = x%11
    add = 0
    if remain!=0:
        add = (2 if remain >6 else 1)
    
    print(ans + add)

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x = f()
    ans = (x//11)*2 
    remain = x%11
    add = 0
    if remain!=0:
        add = (2 if remain >6 else 1)
    
    print(ans + add)

solve()
Problem p03844 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)

solve()
Problem p03997 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')



def solve():
    a = f()[0]
    b = f()[0]
    h = f()[0]
    print((a+b)*h//2)

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')



def solve():
    a,b,h = f()
    print((a+b)*h//2)

solve()
Problem p02675 (python)

Fixed submission:
N = input()
first = int(N) % 10
if first in ( 2, 4, 5, 7, 9 ):
  ret = 'hon'
elif first in ( 0, 1,6,8 ):
  ret = 'pon'
else:
  ret = 'bon'

print( ret )

Buggy submission (verdict: Runtime Error):
K = int( input() )
S = input()

if len(S) <= K:
  print( S )
else:
  print( S[:K] + '...' )
Problem p02681 (python)

Fixed submission:
a = input('')
b = input('')

if b[:-1] == a:
    print('Yes')

else:
    print('No')

Buggy submission (verdict: Runtime Error):
a = input('')
b = input('')
if b[:-1] == a:
  return 'Yes'
Problem p02922 (python)

Fixed submission:
import math
a,b=map(int,input().split())
ans=0

ans=math.ceil((b-1)/(a-1))
print(ans)

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

ans=math.ceil((b-1)/(a-1))
print(ans)
Problem p03284 (python)

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

if n%k==0:
    print("0")
else:
    print("1")

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

if n%k==0:
    print("0")
else
    print("1")

Buggy submission (verdict: Runtime Error):
n.k=map(int,input().split())
print(n%k)
Problem p03624 (python)

Fixed submission:
s=list(input())
res="None"
s.sort()
str="abcdefghijklmnopqrstuvwxyz"

for i in range (26):
    if not(str[i] in s):
        res=str[i]
        break
 
print(res)

Buggy submission (verdict: Runtime Error):
s=list(input())
res="None"
s.sort()
str="abcdefghijklmnopqrstuvwxyz"
for i in range (len(s)):
    if not(str[i] in s):
        res=str[i]
        break
 
print(res)
Problem p03673 (python)

Fixed submission:
n=int(input())
a_L=list(input().split())
ans1=[]
ans2=[]

if n==1:
	print(a_L[0])
else:
	for i in range(0,n,2):
		ans2.append(a_L[i])
	for i in range(1,n,2):
		ans1.append(a_L[i])


if n%2==0:
	ans1.reverse()
	print(*(ans1+ans2))
else:
	ans2.reverse()
	print(*(ans2+ans1))

Buggy submission (verdict: Runtime Error):
n=int(input())
a_L=list(input().split())
ans1 :list=[]
ans2 :list=[]

if n==1:
	print(a_L[0])
else:
	for i in range(0,n,2):
		ans2.append(a_L[i])
	for i in range(1,n,2):
		ans1.append(a_L[i])


if n%2==0:
	ans1.reverse()
	print(*(ans1+ans2))
else:
	ans2.reverse()
	print(*(ans2+ans1))
Problem p02818 (python)

Fixed submission:
a,b,c=map(int,input().split())
aa=max(0,a-c)
print(aa,max(0,a+b-aa-c))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a>=c:
  print(a-c,b)
else if a+b>=c:
  print(0,a+b-c)
else:
  print(0,0)
Problem p02981 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a*b>=c:
  print(c)
else:
  print(a*b)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split)
if b>=c:
  print(a*c)
else:
  print(a*b)
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())
if x==w/2 and y==h/2:
  a=1
else:
  a=0
print(w*h/2,a)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
if x==w/2 and x==h/2:
  a==1
else:
  a==0
print(w*h/2,a)
Problem p03061 (python)

Fixed submission:
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)

N=int(input())
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
n = int(input())
A = input().split()
m = [int(a) for a in A]
ans = 0
for i in range(n):
    B = m[:]
    B.pop(i)
    gcm = gcd(B[0], B[1])
    cand = gcm
    for j in range(len(B)-2):
        cand = gcd(B[j+2], gcm)
    if cand > ans:
        ans = cand
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = int(input())
A = input().split()
m = [int(a) for a in A]
ans = 0
for i in range(n):
    B = m[:]
    B.pop(i)
    cand = gcd_list(B)
    if cand > ans:
        ans = cand
print(ans)
Problem p03071 (python)

Fixed submission:
A, B = map(int, input().split())
s = 0
if A>=B:
    s=A
    A=A-1
else:
    s=B
    B=B-1
S = s
if A>=B:
    s=A
    A=A-1
else:
    s=B
    B=B-1
S=S+s
print(S)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
int s
if A>=B:
    s=A
else:
    s=B
S = 2*s - 1
print(S)
Problem p03076 (python)

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
s=[k for k in [a%10,b%10,c%10,d%10,e%10] if k>0]
if s==[]:
  t=0
else:
  t=min(s)
ans = (a//10+(a%10!=0))*10+(b//10+(b%10!=0))*10+(c//10+(c%10!=0))*10+(d//10+(d%10!=0))*10+(e//10+(e%10!=0))*10+(s!=[])*(-10+t)
print(ans)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
s=min([k for k in [a%10,b%10,c%10,d%10,e%10] if k>0])
ans = (a//10+(a%10!=0))*10+(b//10+(b%10!=0))*10+(c//10+(c%10!=0))*10+(d//10+(d%10!=0))*10+(e//10+(e%10!=0))*10-10+s
print(ans)
Problem p03085 (python)

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

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

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input(),split())
h, w = map(int, input(),split())
print((H-h)*(W-w))
Problem p02741 (python)

Fixed submission:
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(S[K-1])

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 4000
L = 8001
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and c[i] != '?' and b[j] != '?':
            bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L):  # Bの左端をずらす
    for j in range(L):  # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)
Problem p02742 (python)

Fixed submission:
H, W = map(int, input().split())
w = W//2
h = H//2
lh = H - h
lw = W- w

if H < 2 or W < 2:
    print(1)
else:
    print(lh * lw + w * h)

Buggy submission (verdict: Runtime Error):
4 5
Problem p02745 (python)

Fixed submission:
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 4000
L = 8001
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            k = i - j + OFFSET
            ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and b[i] != '?' and c[j] != '?':
            bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L):  # Bの左端をずらす
    for j in range(L):  # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 4000
L = 8001
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and c[i] != '?' and b[j] != '?':
            bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L):  # Bの左端をずらす
    for j in range(L):  # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)

Buggy submission (verdict: Runtime Error):
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 7
L = 15
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            ab[i - j + OFFSET] = False # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and c[i] != '?' and b[j] != '?':
            bc[i - j + OFFSET] = False # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L): # Bの左端をずらす
    for j in range(L): # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000000)

N = int(input())


class Node:
    def __init__(self, index):
        self.index = index
        self.edges = []

class Edge:
    def __init__(self, index, a, b):
        self.a = a
        self.b = b
        self.index = index
        self.color = 0

    def to(self, fm):
        if fm == self.a:
            return self.b
        elif fm == self.b:
            return self.a
        else:
            return None


nodes = [Node(i) for i in range(N)]
edges = []
for i in range(N-1):
    a, b = map(int, input().split())
    edge = Edge(i, a-1, b-1)
    edges.append(edge)
    nodes[a-1].edges.append(i)
    nodes[b-1].edges.append(i)

passed = set()


def rec(node, via_color, K):
    passed.add(node.index)
    color = 1
    for edge_index in node.edges:
        edge = edges[edge_index]
        to_node_index = edge.to(node.index)
        if to_node_index in passed:
            continue
        if color == via_color:
            color += 1
        edge.color = color
        K = rec(nodes[to_node_index], color, K)
        color += 1
    return max(color-1, K)


K = rec(nodes[0], 0, 1)
print(K)
for edge in edges:
    print(edge.color)

Buggy submission (verdict: Runtime Error):
N = int(input())


class Node:
    def __init__(self, index):
        self.index = index
        self.edges = []

class Edge:
    def __init__(self, index, a, b):
        self.a = a
        self.b = b
        self.index = index
        self.color = 0

    def to(self, fm):
        if fm == self.a:
            return self.b
        elif fm == self.b:
            return self.a
        else:
            return None


nodes = [Node(i) for i in range(N)]
edges = []
for i in range(N-1):
    a, b = map(int, input().split())
    edge = Edge(i, a-1, b-1)
    edges.append(edge)
    nodes[a-1].edges.append(edge)
    nodes[b-1].edges.append(edge)

passed = set()


def rec(node, via_color, K):
    passed.add(node.index)
    color = 1
    for edge in node.edges:
        to_node_index = edge.to(node.index)
        if to_node_index in passed:
            continue
        if color == via_color:
            color += 1
        edge.color = color
        K = rec(nodes[to_node_index], color, K)
        color += 1
    return max(color-1, K)


K = rec(nodes[0], 0, 1)
print(K)
for edge in edges:
    print(edge.color)
Problem p02900 (python)

Fixed submission:
from fractions import gcd
A, B = map(int, input().split())
G = gcd(A, B)

# nの[素因数, その数]のリストを返す
def prime_factoring(n):
    from math import sqrt
    factors = []
    for num in range(2, int(sqrt(n))+1):
        if n % num == 0:
            count = 0
            while(n % num == 0):
                n //= num
                count += 1
            factors.append([num, count])
    else:
        if n != 1:
            factors.append(n)
    return factors

print(len(prime_factoring(G))+1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
A, B = map(int, input().split())

cdMap = [0] * min(A, B)
count = 0
tmp = 1

for i in range(1, min(A, B)+1):
    if A%i==0 and B%i==0 and gcd(i, tmp) == 1:
        tmp *= i
        count += 1
print(count)
Problem p02952 (python)

Fixed submission:
N = input()
length = len(N)

count = 0
last = 0
for i in range(length-1):
    last = i
    if i % 2 == 0:
        count += 9*(10**i)

number = int(N)
if length == 1:
    count = number
elif last%2 == 1:
    count += number + 1 - 10**(last+1)
print(count)

Buggy submission (verdict: Runtime Error):
N = input()
length = len(N)

count = 0
last = 0
for i in range(length-1):
    last = i
    if i % 2 == 0:
        count += 9*(10**i)

number = int(N)
if i%2 == 1:
    count += number + 1 - 10**(last+1)
print(count)
Problem p02972 (python)

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


def get_divisors(n, reverse=False):
    from math import sqrt
    divisors = []
    for num in range(1, int(sqrt(n))+1):
        if n % num == 0:
            divisors.append(num)
            if n//num != num:
                divisors.append(n//num)
    return sorted(divisors, reverse=reverse)

status = [0] * N
answers = []
for i in range(N, 0, -1):
    if A[i-1] == status[i-1]:
        continue
    answers.append(i)
    divisors = get_divisors(i)
    a = A[i-1]
    for divisor in divisors:
        status[divisor-1] = (1 + status[divisor-1]) % 2

print(len(answers))
for ans in answers:
    print(ans, end=" ")

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

def get_divisors(n, reverse=False):
    from math import sqrt
    divisors = []
    for num in range(1, int(sqrt(n))+1):
        if n % num == 0:
            divisors.append(num)
            if n//num != num:
                divisors.append(n//num)
    return sorted(divisors, reverse=reverse)

total = sum(A)
divisors = get_divisors(total, reverse=True)
ans = -1
for d in divisors:
    R = [a%d for a in A]
    R.sort(reverse=True)
    pr = 0
    nr = -sum(R)
    for i, r in enumerate(R):
        pr += d-r
        nr += r
        if nr+pr >= 0:
            if pr <= K and nr+pr == 0:
                ans = d
            break
    if ans != -1:
        print(ans)
        break
else:
    print(1)
Problem p03006 (python)

Fixed submission:
N = int(input())
x = []
y = []
for i in range(N):
    new_x, new_y = map(int, input().split())
    x.append(new_x)
    y.append(new_y)

dist_list = []
count_list = []
for i in range(N):
    for j in range(i+1, N):
        p = x[i] - x[j]
        q = y[i] - y[j]
        for index, dist in enumerate(dist_list):
            x_dist, y_dist= dist
            if (x_dist == p and y_dist == q) or (x_dist == -p and y_dist == -q):
                count_list[index] += 1
                break
        else:
            dist_list.append([p, q])
            count_list.append(1)

if N == 1:
    print(1)
else:
    print(N - max(count_list))

Buggy submission (verdict: Runtime Error):
N = int(input())
x = []
y = []
for i in range(N):
    new_x, new_y = map(int, input().split())
    x.append(new_x)
    y.append(new_y)

dist_list = []
count_list = []
for i in range(N):
    for j in range(i+1, N):
        p = x[i] - x[j]
        q = y[i] - y[j]
        for index, dist in enumerate(dist_list):
            x_dist, y_dist= dist
            if (x_dist == p and y_dist == q) or (x_dist == -p and y_dist == -q):
                dist_list[index] = [x_dist, y_dist]
                count_list[index] += 1
                break
        else:
            dist_list.append([p, q])
            count_list.append(1)

print(N - max(count_list))
Problem p02675 (python)

Fixed submission:
s = input()
c = s[-1]
if c in '24579':
    print("hon")
elif c in '0168':
    print("pon")
else:
    print("bon")

Buggy submission (verdict: Runtime Error):
s = input()[-1]
if s in "2479":
    print("hon")
elif s in "0168":
    print("pon")
else
    print("bon")
Problem p02681 (python)

Fixed submission:
x = input()
y = input()
 
if len(x) > 10:
  print('No')
elif len(y) - len(x) != 1:
  print('No')
elif x.islower() ==False or x.isalpha() != True:
  print('No')
elif x != y[:-1]:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
x = input()
y = input()

if len(x) > 10:
  print('No')
elif len(y) - len(x) !=:
  print('No')
elif x.islower() ==False:
  print('No')
else:
  print('Yes')
Problem p02717 (python)

Fixed submission:
x,y,z=map(int,input().split())
print("{} {} {}".format(z,x,y))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
A = list(map(int,input().split()))
s=sum(A)
c=0
for a in A:
    if a >= s/(4*m):
        c=c+1

if c>=m:
     print('Yes')
else:
    print("No")
Problem p03112 (python)

Fixed submission:
from bisect import bisect
A,B,Q=map(int, input().split())
s=[int(input()) for _ in range(A)] + [10**11]
t=[int(input()) for _ in range(B)] + [10**11]
for _ in range(Q):
	x = int(input())
	ans = []
	ps = bisect(s, x)
	pt = bisect(t, x)
	for vs in (s[ps], s[ps-1]):
		for vt in (t[pt], t[pt-1]):
			ans.append(abs(x - vs) + abs(vs - vt))
			ans.append(abs(x - vt) + abs(vt - vs))
	print(min(ans))

Buggy submission (verdict: Runtime Error):
    from bisect import bisect
    A,B,Q=map(int, input().split())
    s=[int(input()) for _ in range(A)] + [99**99]
    t=[int(input()) for _ in range(B)] + [99**99]
    snt=[0]*A + [99**99]
    tns=[0]*B + [99**99]
    for i in range(A):
    	p = bisect(t, s[i])
    	snt[i] = min(abs(s[i] - t[p-1]), abs(s[i] - t[p]))
    for i in range(B):
    	p = bisect(s, t[i])
    	tns[i] = min(abs(t[i] - s[p-1]), abs(t[i] - s[p]))
    for _ in range(Q):
    	x = int(input())
    	ans = []
    	p = bisect(s, x)
    	ans.append(abs(s[p] - x) + snt[p])
    	ans.append(abs(s[p-1] - x) + snt[p-1])
    	p = bisect(t, x)
    	ans.append(abs(t[p] - x) + tns[p])
    	ans.append(abs(t[p-1] - x) + tns[p-1])
    	print(min(ans))
Problem p03128 (python)

Fixed submission:
v=[-1,2,5,5,4,5,6,3,7,6]

N,M=map(int, input().split())
A=sorted(map(int, input().split()), reverse=True)

dp=[0]*(N+999)
mp=[[] for _ in range(N+999)]

for a in reversed(A):
	dp[v[a]] = 1
	mp[v[a]] = [a]

for i in range(N+1):
	for a in A:
		if i-v[a] >= 0 and dp[i-v[a]] > 0 and dp[i] < 1 + dp[i-v[a]]:
			dp[i] = 1 + dp[i-v[a]]
			mp[i] = [a] + mp[i-v[a]]

print("".join(map(str, mp[N])))

Buggy submission (verdict: Runtime Error):
v=[-1,2,5,5,4,5,6,3,7,6]

N,M=map(int, input().split())
A=sorted(map(int, input().split()), reverse=True)

dp=[0]*(N+1)
mp=[[] for _ in range(N+1)]

for a in reversed(A):
	dp[v[a]] = 1
	mp[v[a]] = [a]

for i in range(N+1):
	for a in A:
		if i-v[a] >= 0 and dp[i-v[a]] > 0 and dp[i] < 1 + dp[i-v[a]]:
			dp[i] = 1 + dp[i-v[a]]
			mp[i] = [a] + mp[i-v[a]]

print("".join(map(str, mp[N])))

Buggy submission (verdict: Runtime Error):
v=[-1,2,5,5,4,5,6,3,7,6]

N,M=map(int, input().split())
A=sorted(map(int, input().split()), reverse=True)

dp=[0]*(N+1)
mp=[[] for _ in range(N+1)]

for a in reversed(A):
	dp[v[a]] = 1
	mp[v[a]] = [a]

for i in range(N+1):
	for a in A:
		if i-v[a] >= 0 and dp[i-v[a]] > 0 and dp[i] < 1 + dp[i-v[a]]:
			dp[i] = 1 + dp[i-v[a]]
			mp[i] = [a] + mp[i-v[a]]

print("".join(map(str, mp[N])))

Buggy submission (verdict: Runtime Error):
"""
1,2,3,4,5,6,7,8,9
2,5,5,4,5,6,3,7,6

"""

v=[None,2,5,5,4,5,6,3,7,6]

N,M=map(int, input().split())
A=sorted(map(int, input().split()), reverse=True)

dp=[0]*(N+1)
mp=[[] for _ in range(N+1)]

for a in reversed(A):
	dp[v[a]] = 1
	mp[v[a]] = [a]

for i in range(N+1):
	for a in A:
		if i-v[a] >= 0 and dp[i-v[a]] > 0 and dp[i] < 1 + dp[i-v[a]]:
			dp[i] = 1 + dp[i-v[a]]
			mp[i] = [a] + mp[i-v[a]]

print("".join(map(str, mp[N])))

Buggy submission (verdict: Runtime Error):
"""
1,2,3,4,5,6,7,8,9
2,5,5,4,5,6,3,7,6

"""

v=[None,2,5,5,4,5,6,3,7,6]

N,M=map(int, input().split())
A=sorted(map(int, input().split()), reverse=True)
B=sorted(set([v[i] for i in A]))

dp=[0]*(N+1)

for i in range(N+1):
	dp[i] = max([0] + [1+dp[i-b] for b in B if i-b>0])

ans=[None]*dp[N]
for i in range(len(ans)):
	for a in A:
		if dp[N] == 1 + dp[N-v[a]]:
			if i+1 == len(ans) and N - v[a] > 0:
				continue
			N -= v[a]
			ans[i] = a
			break

print("".join(map(str, sorted(ans, reverse=True))))