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

Fixed submission:
N,M = map(int,input().split())
li =[]
for i in range(M):
    li.append(list(map(int,input().split())))
    if li[i][0]>N:
        print("-1")
        exit()
st = 10**(N-1)
if N == 1:
    st = 0
for i in range(st,10**N):
    inv = True
    a = str(i)
    for j in range(M):
        if  a[li[j][0]-1] != str(li[j][1]):
            inv = False
            break
    if inv:
        print(i)
        exit()
print("-1")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ln = [-1]*N
for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    if (ln[s] != c) and(ln[s] != -1):
        print("-1")
        exit()
    else:
        ln[s] = c
for j in range(1,M):
    if ln[j] == -1:
        ln[j] = 0
if ln[0] == 0:
    print("-1")
    exit()
if ln[0] == -1:
    ln[0] = 1

print("".join(map(str,ln)))
Problem p02900 (python)

Fixed submission:
import fractions
A,B = map(int,input().split())
m = fractions.gcd(A,B)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

l_m = prime_factorize(m)
if len(l_m) >= 1:
    ans = 2
else:
    print("1")
    exit()
for i in range(1,len(l_m)):
    if not l_m[i] == l_m[i-1]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import fanctions
A,B = map(int,input().split())
m = fanctions.gcd(A,B)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

l_m = prime_factorize(m)
if len(l_m) >= 1:
    ans = 2
else:
    print("1")
    exit()
for i in range(1,len(l_m)):
    if not l_m[i] == l_m[i-1]:
        ans += 1
print(ans)
Problem p02981 (python)

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

Buggy submission (verdict: Runtime Error):
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
count = 0
for n in range (N):
    for nn in range(n):
      distance == sum([all_list[n][d]-all_list[nn][d] for d in range(D)])
    for s in range(250):
      if distance == s**2:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(N):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(round((count - N) / 2))

Buggy submission (verdict: Runtime Error):
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(N):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(round((count - N) / 2))
Problem p02982 (python)

Fixed submission:
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(n):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(count)

Buggy submission (verdict: Runtime Error):
    N,D =map(int, input().split())
    all_list = [list(map(int, input().split())) for i in range(N)]
    #>>>4
    count = 0
    for n in range (N):
        for nn in range(N):
            distance = 0
            for d in range(D):
                kou = (all_list[n][d] - all_list[nn][d])**2
                distance += kou
            for s in range(250):
                if distance == s**2:
                    count += 1
                    break
    print(round((count - N) / 2) +)

Buggy submission (verdict: Runtime Error):
count = 0
    for n in range (N):
        for nn in range(N):
            distance = 0
            for d in range(D):
                kou = (all_list[n][d] - all_list[nn][d])**2
                distance += kou
            for s in range(250):
                if distance == s**2:
                    count += 1
                    break
    print(round((count - N) / 2))
Problem p02994 (python)

Fixed submission:
N,L = map(int,input().split())
if L >=0:
    eat = 0
else:
    eat = N - 1
    for m in range(N):
        if abs(L + m) < abs(L + eat):
            eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
    eat = N - 1
    for m in range(N):
        if abs(L + m) < abs(L + eat):
            eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
def gcm(a,b):
    k = a * b / gcd(a,b)
    return int(k)

A,B,C,D = map(int,input().split())
bk = B - B//C - B//D + B//gcm(C,D)
ak = (A-1) - (A-1)//C - (A-1)//D + (A-1)//gcm(C,D)

print(bk-ak)

Buggy submission (verdict: Runtime Error):
import math
def gcm(a,b):
    k = a * b / math.gcd(a,b)
    return int(k)

A,B,C,D = map(int,input().split())
bk = B - B//C - B//D + B//gcm(C,D)
ak = (A-1) - (A-1)//C - (A-1)//D + (A-1)//gcm(C,D)

print(bk-ak)
Problem p03386 (python)

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

if (b-a+1)/2 < k:
    for i in range(a, b+1):
        print(i)
else:
    for j in range(a, a+k):
        print(j)
    for k in range(b-k+1, b+1):
        print(k)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
numlist = []
 
for i in range(a, b+1):
    if i < a + k or i >  b - k:
        numlist.append(i)

print(numlist[l])
Problem p02639 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]


def test():
    # x = map(int, input().split())
    x = input().split()
    print(x.index("0") + 1)

test()

Buggy submission (verdict: Runtime Error):
# https://qiita.com/c-yan/items/e117269cc447fa61dddf
N = int(input())
A = list(map(int, input().split()))

d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

A = sorted(set(A))
t = [True] * (10 ** 6 + 1)
for a in A:
    if d[a] > 1:
        t[a] = False
    for i in range(a + a, 10 ** 6 + 1, a):
        t[i] = False
print(sum(1 for a in A if t[a]))
Problem p03700 (python)

Fixed submission:
#coding: utf-8
import math

N, A, B = map(int, input().split())
monster = [int(input()) for i in range(N)]


def enough(T):
    attack = B * T
    diff = A-B
    count = 0
    for i in monster:
        tmp = math.ceil((i - attack)/diff)
        if tmp > 0:
            count += tmp

    if count <= T:
        return True
    else:
        return False

def bs():
    left = 0
    right = 1000000000

    while left < right:
        mid = (left + right) // 2
        if enough(mid):
            right = mid
        else:
            left = mid + 1
    return left

print(bs())

Buggy submission (verdict: Runtime Error):
#coding: utf-8

line = input().strip()
N = int(line[0])
A = int(line[2])
B = int(line[4])
monster = [int(input()) for i in range(N)]

times = 0
while len(monster) > 0:
    n = monster.index(max(monster)) #一番体力が大きい魔物のインデックス
    monster[n] = monster[n] - A
    if monster[n] < 1:
        monster[n] = 0

    for i, x in enumerate(monster):
        if i != n:
            monster[i] = monster[i] - B
            if monster[i] < 1:
                monster[i] = 0
    for i in monster:
        if i == 0:
            monster.remove(0)

    times = times + 1

print (times-1)

Buggy submission (verdict: Runtime Error):
#coding: utf-8



line = input().strip()
N = int(line[0])
A = int(line[2])
B = int(line[4])
monster = [int(input()) for i in range(N)]

times = 0
while len(monster) > 0:
    n = monster.index(max(monster)) #一番体力が大きい魔物のインデックス
    print('max', n)
    print('monster', monster)
    monster[n] = monster[n] - A
    if monster[n] < 1:
        monster[n] = 0

    for i, x in enumerate(monster):
        if i != n:
            monster[i] = monster[i] - B
            if monster[i] < 1:
                monster[i] = 0
    for i in monster:
        if i == 0:
            monster.remove(0)


    times = times + 1

print (times-1)
Problem p03000 (python)

Fixed submission:
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
ans=1
curr=0
ind=0
while(curr<=x):
    if(ind>=n):
        break
    curr+=a[ind]
    ind+=1
    if(curr>x):
        break
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
ans=1
curr=0
ind=0
while(curr<=x):
    curr+=a[ind]
    ind+=1
    if(curr>x):
        break
    ans+=1
print(ans)
Problem p02639 (python)

Fixed submission:
l = list(map(int,input().split()))
for i in range(len(l)):
	if l[i] == 0:
		print(i+1)

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

for i in range(len(l)):
  if l[i] == 0:
    return i
Problem p02684 (python)

Fixed submission:
N,K = map(int,input().split())
list1 = list(map(int,input().split()))
visited_town = [[] for i in range(N+1)] #どの町にいつ訪れたか,配列の0あける。
visited_time = [None for i in range(2*N)] #訪れた町の時系列。こっちは0あけない。

visited_town[1].append(0) 
visited_time[0] = 1

cycle_start = -1
cycle_end = -1

for i in range(1,2*N):
  next_town = list1[visited_time[i-1]-1]
  visited_town[next_town].append(i)
  visited_time[i] = next_town
  if len(visited_town[next_town]) == 2:
    cycle_start = visited_town[next_town][0]
    cycle_end   = visited_town[next_town][1]
    break

if K < cycle_start:
  ans = visited_time[K]
  print(ans)
else :   
  syuuki = cycle_end-cycle_start
  cycle = visited_time[cycle_start:cycle_end]
  ans = cycle[(K-cycle_start) % syuuki]
  print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
list1 = list(map(int,input().split()))
visited_town = [[] for i in range(N+1)] #どの町にいつ訪れたか,配列の0あける。
visited_time = [None for i in range(2*N)] #訪れた町の時系列。こっちは0あけない。

visited_town[1].append(0) 
visited_time[0] = 1

cycle_start = -1
cycle_end = -1
cycle_detect = False

for i in range(1,min([K,2*N])):
  next_town = list1[visited_time[i-1]-1]
  visited_town[next_town].append(i)
  visited_time[i] = next_town
  if len(visited_town[next_town]) == 2:
    cycle_start = visited_town[next_town][0]
    cycle_end   = visited_town[next_town][1]
    cycle_detect = True
    break

print(visited_time)

if (!cycle_detect)
  ans = visited_time[K]
  print(ans)
else :   
  syuuki = cycle_end-cycle_start
  cycle = visited_time[cycle_start:cycle_end]
  ans = cycle[(K-cycle_start) % syuuki]
  print(ans)
Problem p03076 (python)

Fixed submission:
import math
ary1 = [int(input()) for x in range(5)]
x1 = sum(10*math.ceil(x/10) for x in ary1)
x2 = max([10-(y % 10) if y % 10 !=0 else 0 for y in ary1 ])
ans = x1 - x2
print(ans)

Buggy submission (verdict: Runtime Error):
import math
ary1 = [int(input()) for x in range(5)]
ans = sum(10*math.ceil(x/10) for x in ary1) - max([10-(y % 10) for y in ary1 if y % 10 !=0])
print(ans)
Problem p03244 (python)

Fixed submission:
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [[0,i] for i in range(10**5+2)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)


if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  x1 = n-list3[0][0]-list4[1][0]
  x2 = n-list3[1][0]-list4[0][0]
  print(min(x1,x2))

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [[0,i] for i in range(10**5+2)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)


if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  x1 = n-list3[0][0]-list4[1][0]
  x2 = n-list3[1][0]-list4[0][0]
  print(min(x1,x2)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [0] * 10**5
  ary1 = [[0,i] for i in range(10**5+1)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)

print(n-list3[0][0]-list4[0][0])

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [0] * 10**5
  ary1 = [[0,i] for i in range(10**5+1)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)

if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  if list3[0][0] >= list4[0][0]:
    print(n-list3[0][0]-list4[1][0])
  else:
    print(n-list3[1][0]-list4[0][0])
Problem p03274 (python)

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

def f(min1,max1):
  if min1>=0 and max1>=0:
    return abs(max1)
  elif min1<=0 and max1 <=0:
    return abs(min1)
  else:
    return min([-2*min1 + max1,-min1 + 2*max1])

ans = 2*10**9
for i in range(N-K+1):
  min1 = xlist[i]
  max1 = xlist[i+K-1]
  dist =f (min1,max1) 
  if dist < ans :
    ans = dist

print(ans)

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

def f(list1):
  min1 = list1[0]
  max1 = list1[-1]
  if min1>=0 and max1>=0:
    return abs(max1)
  elif min1<0 and max1 <0:
    return abs(min1)
  else:
    return total+min([abs(min1),abs(max1)])

ans = 2*10**8 + 2
for i in range(N-K+1):
  dist =f (xlist[i:i+K]) 
  if dist < ans :
    ans = dist

print(ans)
Problem p02675 (python)

Fixed submission:
num = input()
lst = list(map(int, num))
ele = lst[-1]
if ele==2 or ele==4 or ele==5 or ele==7 or ele==9:
  	print("hon")
elif ele==0 or ele==1 or ele==6 or ele==8:
 	print("pon")
elif ele==3:
	print("bon")

Buggy submission (verdict: Runtime Error):
num = input()
lst = list(map(int, num))
ele = lst[-1]
if ele==2 or ele==4 or ele==5 or ele==7 or ele==9:
  	print("hon")
elif ele==1 or ele==6 or ele==8:
 	print("pon")
elif ele==3
	print("bon")

Buggy submission (verdict: Runtime Error):
num = input()
lst = lst(map(int, num))
ele = lst[-1]
if ele==2 or ele==4 or ele==5 or ele==7 or ele==9:
  	print("hon")
elif ele==1 or ele==6 or ele==8:
 	print("pon")
elif ele==3
	print("bon")
Problem p02924 (python)

Fixed submission:
S=int(input())
#N=list(map(int,input().split()))
ans=(S-1)*S//2
print(ans)

Buggy submission (verdict: Runtime Error):
S=long(input())
#N=list(map(int,input().split()))

ans=long((S-1)*S/2)

print(ans)
Problem p02755 (python)

Fixed submission:
a, b = map(int, input().split())
for i in range(10000):
  if int(i * 0.08) == a and int(i * 0.1) == b:
    print(i)
    exit()
print(-1)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
for i in range(10000):
  if int(i * 0.08) == a and int(i * 0.1) == b:
    print(i)
    exit()
print(=1)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
A, B = input().split()
1 <= A <= 100
1 <= B <= 100
sum = A*B
print(sum)

Buggy submission (verdict: Runtime Error):
1<=A<=100
1<=B<=100
A = input(int())
B = input(int())
sum = A*B
print(sum)

Buggy submission (verdict: Runtime Error):
A = 1<=A<=100
B = 1<=B<=100
sum = A*B
print(sum)
Problem p02687 (python)

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
S = input()
if S = ABC:
  print("ARC")
elif S = ARC:
  print("ABC")
else:
Problem p03106 (python)

Fixed submission:
a, b, c = map(int, input().split())
cnt = 0
for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        cnt += 1
        if cnt == c:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
cnt = 0
for i in range(1,min(b,c)):
  if a%i==0 and b%i==0:
    cnt++
    if cnt == c:
      print(i)
      break
Problem p02641 (python)

Fixed submission:
X,N = map(int,input().split(" "))
target = X
if N != 0:
    p_list = list(map(int,input().split(" ")))

    target_num_min = X
    target_num_plus = X
    if X in p_list:
        while True:
            target_num_min -= 1
            if target_num_min not in p_list:
                target = target_num_min
                break
            target_num_plus += 1
            if target_num_plus not in p_list:
                target = target_num_plus
                break
print(target)

Buggy submission (verdict: Runtime Error):
X,N = map(int,input().split(" "))
if N != 0:
    p_list = list(map(int,input().split(" ")))
target = X
target_num_min = X
target_num_plus = X
if X in p_list:
    while True:
        target_num_min -= 1
        if target_num_min not in p_list:
            target = target_num_min
            break
        target_num_plus += 1
        if target_num_plus not in p_list:
            target = target_num_plus
            break
print(target)
Problem p02848 (python)

Fixed submission:
word = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
word_reverse={v: k for k, v in word.items()}
x=input()
y=input()
Ans=''
for i in y:
  if word[i]+int(x) > 25:
    z = (word[i]+int(x)) % 26
  else:z=word[i]+int(x)
  Ans=Ans+word_reverse[z]

print(Ans)

Buggy submission (verdict: Runtime Error):
word = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
word_reverse={v: k for k, v in word.items()}
x=input()
y=input()
Ans=''
for i in x:
  Ans=Ans+word_reverse[word[i]+int(y)]

print(Ans)
Problem p02639 (python)

Fixed submission:
x = list(map(int, input().split()))
for i in range(0, len(x)):
  if x[i] == 0:
    print(i + 1)
    break

Buggy submission (verdict: Runtime Error):
x = list(map(int, input().split()))
for i in range(0, len(x)):
  if x[i] == 0:
    print(i + 1)
    return
Problem p02848 (python)

Fixed submission:
N = int(input())
S = input().strip()
after = []
for s in S:
  x = ord(s) + N
  if x > ord('Z'):
    x = x - 26
  after.append(chr(x))
print(''.join(after))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input().strip()
after = []
for s in S:
  x = ord(s) + N
  if x > ord('Z'):
    x = x - ord('Z')
  after.append(chr(x))
print(''.join(x))
Problem p03128 (python)

Fixed submission:
import sys
sys.setrecursionlimit(150000)


d = [2,5,5,4,5,6,3,7,6]

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

memo = [ "-" for _ in range(N + 1)]

def find(N):
    global memo
    if memo[N] != "-":
        return memo[N]

    mval = ""
    val = ""
    for a in A:
        if d[a - 1] < N:
            val = find(N - d[a - 1])
            if val == "":
                continue
            val = val + str(a)
        elif d[a - 1] == N:
            val = str(a)
        else:
            continue

        if len(mval) < len(val) or (len(mval) == len(val) and mval < val):
            mval = val
    memo[N] = mval
    return memo[N]

m = find(N)
print(m)

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

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

memo = [ "-" for _ in range(N + 1)]

def find(N):
    global memo
    if memo[N] != "-":
        return memo[N]

    mval = ""
    val = ""
    for a in A:
        if d[a - 1] < N:
            val = find(N - d[a - 1])
            if val == "":
                continue
            val = val + str(a)
        elif d[a - 1] == N:
            val = str(a)
        else:
            continue

        if len(mval) < len(val) or (len(mval) == len(val) and mval < val):
            mval = val
    memo[N] = mval
    return memo[N]

m = find(N)
print(m)

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

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

memo = [ "-" for _ in range(N + 1)]

def find(N):
    global memo
    if memo[N] != "-":
        return memo[N]

    mval = ""
    val = ""
    for a in A:
        if d[a - 1] < N:
            val = str(find(N - d[a - 1]))
            if val == "":
                continue
            val = val + str(a)
        elif d[a - 1] == N:
            val = str(a)
        else:
            continue

        if len(mval) < len(val) or mval < val:
            mval = val
    memo[N] = mval
    return memo[N]

m = find(N)
print(m)

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

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

memo = [ "-" for _ in range(N + 1)]

def find(N):
    global memo
    if memo[N] != "-":
        return memo[N]

    mval = ""
    val = ""
    for a in A:
        if d[a - 1] < N:
            val = str(find(N - d[a - 1]))
            if val == "":
                continue
            val = val + str(a)
        elif d[a - 1] == N:
            val = str(a)

        if len(mval) < len(val) or mval < val:
            mval = val
    memo[N] = mval
    return memo[N]

m = find(N)
print(m)