Buggy python submission (verdict: Runtime Error):
hn_kz = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
kz_hn = {}
n, m, *kzs = map(int, open(0).read().split())
# 本数から数を求める辞書を作る。同じ本数の数は大きい方を取る
for kz in kzs:
    ah = hn_kz[kz]
    if ah in kz_hn:
        kz_hn[ah] = max(kz_hn[ah], kz)
    else:
        kz_hn[ah] = kz
# 最小の本数をhmnに格納
hmn = min(kz_hn.keys())
# まず、最小の本数の数だけで桁[本数]の辞書を作る
kt_hn = {kt * hmn: kt for kt in range(n // hmn + 1)}
# 最小本数以外の数の辞書nkz_hnを作る
nkz_hn = kz_hn.copy()
del nkz_hn[hmn]

inf = 10 ** 9


def keta(hn):
    #    print(hn,kt_hn)
    if hn in kt_hn:
        return kt_hn[hn]
    elif hn < 0:
        return -inf
    else:
        maxketa = -inf
        for hni in nkz_hn.keys():
            newkt = keta(hn - hni) + 1
            if newkt > maxketa:
                maxketa = newkt
        kt_hn[hn] = maxketa
        return maxketa


ans = ""
nokori = n
while nokori > 0:
    for kh in sorted(kz_hn.items(), key=lambda xkh: xkh[1], reverse=True):
        if keta(nokori - kh[0]) == keta(nokori) - 1 and keta(nokori - kh[0]) >= 0:
            ans += str(kh[1])
            nokori -= kh[0]
            break

print(ans)

Fixed submission:
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
hn_kz = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
kz_hn = {}
n, m, *kzs = map(int, open(0).read().split())
# 本数から数を求める辞書を作る。同じ本数の数は大きい方を取る
for kz in kzs:
    ah = hn_kz[kz]
    if ah in kz_hn:
        kz_hn[ah] = max(kz_hn[ah], kz)
    else:
        kz_hn[ah] = kz
# 最小の本数をhmnに格納
hmn = min(kz_hn.keys())
# まず、最小の本数の数だけで桁[本数]の辞書を作る
kt_hn = {kt * hmn: kt for kt in range(n // hmn + 1)}
# 最小本数以外の数の辞書nkz_hnを作る
nkz_hn = kz_hn.copy()
del nkz_hn[hmn]

inf = 10**9

def keta(hn):
    #    print(hn,kt_hn)
    if hn in kt_hn:
        return kt_hn[hn]
    elif hn < 0:
        return -inf
    else:
        maxketa = -inf
        for hni in nkz_hn.keys():
            newkt = keta(hn - hni) + 1
            if newkt > maxketa:
                maxketa = newkt
        kt_hn[hn] = maxketa
        return maxketa

ans = ""
nokori = n
while nokori > 0:
    for kh in sorted(kz_hn.items(), key=lambda xkh: xkh[1], reverse=True):
        if keta(nokori - kh[0]) == keta(nokori) - 1 and keta(nokori)>0:
            ans += str(kh[1])
            nokori -= kh[0]
            break

print(ans)

Fixed submission:
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
hn_kz={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
kz_hn={}
n,m,*kzs=map(int,open(0).read().split())
#本数から数を求める辞書を作る。同じ本数の数は大きい方を取る
for kz in kzs:
    ah=hn_kz[kz]
    if ah in kz_hn:
        kz_hn[ah]=max(kz_hn[ah],kz)
    else:
        kz_hn[ah]=kz
kt_hn={0:0}
#本数から桁数を求める関数
inf=100
def keta(hn):
    if hn in kt_hn:
        return kt_hn[hn]
    elif hn<0:
        return -inf
    else:
        maxketa=-inf
        for hni in kz_hn.keys():
            newkt=keta(hn-hni)+1
            if newkt>maxketa:
                maxketa=newkt
        kt_hn[hn]=maxketa
        return maxketa
#目的の数を作る
ans=""
nokori=n
while nokori>0:
    for kh in sorted(kz_hn.items(),key=lambda xkh:xkh[1],reverse=True):
        if keta(nokori-kh[0])==keta(nokori)-1:
            ans+=str(kh[1])
            nokori-=kh[0]
            break
print(ans)


Fixed submission:
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
hn_kz={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
kz_hn={}
n,m,*kzs=map(int,open(0).read().split())
#本数から数を求める辞書を作る。同じ本数の数は大きい方を取る
for kz in kzs:
    ah=hn_kz[kz]
    if ah in kz_hn:
        kz_hn[ah]=max(kz_hn[ah],kz)
    else:
        kz_hn[ah]=kz
#最小の本数をhmnに格納
hmn=min(kz_hn.keys())
#まず、最小の本数の数だけで桁[本数]の辞書を作る
kt_hn={kt*hmn:kt for kt in range(n//hmn+1)}
#本数から桁数を求める関数
inf=100
def keta(hn):
    if hn in kt_hn:
        return kt_hn[hn]
    elif hn<0:
        return -inf
    else:
        maxketa=-inf
        for hni in kz_hn.keys():
            newkt=keta(hn-hni)+1
            if newkt>maxketa:
                maxketa=newkt
        kt_hn[hn]=maxketa
        return maxketa
#目的の数を作る
ans=""
nokori=n
while nokori>0:
    for kh in sorted(kz_hn.items(),key=lambda xkh:xkh[1],reverse=True):
        if keta(nokori-kh[0])==keta(nokori)-1:
            ans+=str(kh[1])
            nokori-=kh[0]
            break
print(ans)

Fixed submission:
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
hn_kz={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
kz_hn={}
n,m,*kzs=map(int,open(0).read().split())
#本数から数を求める辞書を作る。同じ本数の数は大きい方を取る
for kz in kzs:
    ah=hn_kz[kz]
    if ah in kz_hn:
        kz_hn[ah]=max(kz_hn[ah],kz)
    else:
        kz_hn[ah]=kz
#最小の本数をhmnに格納
hmn=min(kz_hn.keys())
#まず、最小の本数の数だけで桁[本数]の辞書を作る
kt_hn={kt*hmn:kt for kt in range(n//hmn+1)}
#最小本数以外の数の辞書nkz_hnを作る
nkz_hn=kz_hn.copy()
del nkz_hn[hmn]
#本数から桁数を求める関数
inf=100
def keta(hn):
    if hn in kt_hn:
        return kt_hn[hn]
    elif hn<0:
        return -inf
    else:
        maxketa=-inf
        for hni in nkz_hn.keys():
            newkt=keta(hn-hni)+1
            if newkt>maxketa:
                maxketa=newkt
        kt_hn[hn]=maxketa
        return maxketa
#目的の数を作る
ans=""
nokori=n
while nokori>0:
    for kh in sorted(kz_hn.items(),key=lambda xkh:xkh[1],reverse=True):
        if keta(nokori-kh[0])==keta(nokori)-1:
            ans+=str(kh[1])
            nokori-=kh[0]
            break
print(ans)

Fixed submission:
def smax(s1, s2):
    if s1=="N":
        if s2[0]=="N":
            return "N"
        else:
            return s2
    if s2[0] == "N":
        return s1
    l1 = len(s1)
    l2 = len(s2)
    if l1 == l2:
        return max(s1, s2)
    if l1 > l2:
        return s1
    return s2

hon = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
aa = list(map(int, input().split()))
dp = ["N"] * (n + 1)
dp[0]=""
for i in range(2, n + 1):
    for a in aa:
        if i - hon[a] < 0: continue
        dp[i] = smax(dp[i], dp[i - hon[a]] + str(a))
print(dp[-1])