Harryxun/stf_run huggingface dataset:
from collections import defaultdict, deque

def solve(graph, edges, n, start_idx):
  flg = [False for _ in range(n)] #未検索のノードはFlase
  flg[start_idx] = True
  
  cost = [float('inf') for _ in range(n)]
  cost[start_idx] = 0
  
  prv_edges = [None for _ in range(n)]
  
  prv_node = start_idx  
  while not all(flg):
    for node, dis in graph[prv_node]:
      if cost[node] > dis:
        cost[node] = dis
        
        tmp_edge = sorted([prv_node, node])
        if tmp_edge in edges:
          edges.remove(tmp_edge)
        if prv_edges[node] is not None and prv_edges[node] not in edges:
          edges.append(prv_edges[node])
        prv_edges[node] = tmp_edge
    
    min_cost = float('inf')
    tmp_idx = -1
    for i in range(n):
      if flg[i] is False and min_cost > cost[i]:
        min_cost = cost[i]
        tmp_idx = i
    prv_node = tmp_idx
    flg[prv_node] = True
    #print(start_idx, prv_node, cost, edges, prv_edges)
  return edges

n, m = map(int, input().split())
graph = defaultdict(list)
edges = []

for i in range(m):
  a,b,c = map(int, input().split())
  graph[a-1].append([b-1,c])
  graph[b-1].append([c-1,c])
  edges.append(sorted([a-1,b-1]))

for i in range(n):
  edges = solve(graph, edges, n, i)
print(len(edges))

### FIXED CODE ###

INF = float('inf')

def dijkstra(s,N,M,cost,ans):
  d = [INF] * N
  used = [False] * N
  d[s] = 0
  prvv = [[] for _ in range(N)]
  while True:
    v = -1
    for i in range(N):
      if (not used[i]) and (v == -1): v = i
      elif (not used[i] and d[i] < d[v]): v = i
    if v == -1: break
    used[v] = True
  
    for j in range(N):
      if d[j] > d[v]+cost[v][j]:
        d[j] = d[v]+cost[v][j]
        prvv[j] = [v]
      elif d[j] == d[v]+cost[v][j]:
        d[j] = d[v]+cost[v][j]
        prvv[j].append(v)
  
  for i, vs in enumerate(prvv):
    for v in vs:
      ans.add(tuple(sorted([v,i])))

  return prvv

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

cost = [[INF for _ in range(N)] for _ in range(N)]
for i in range(M):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c


ans =set([])
for i in range(N):
  dijkstra(i,N,M,cost,ans)
print(M-len(ans))
#print(ans)
import math
import collections
import fractions
import itertools

def solve():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    x.sort()
    if n >= m:
        print(0)
    else:
        diff = [abs(x[i] - x[i+1]) for i in range(m-1)]
        diff.sort(reverse=True)
        ans = sum(diff)
        for i in range(n-1):
            ans -= diff[i]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import math
import collections
import fractions
import itertools

def solve():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    x.sort()
    if n >= m:
        print(0)
    else:
        diff = [abs(x[i] - x[i+1]) for i in range(m-1)]
        diff.sort(reverse=True)
        ans = sum(diff)
        for i in range(n-1):
            ans -= diff[i]
        print(ans)
    return 0

if __name__ == "__main__":
    solve()
import itertools
from collections import defaultdict
H,W,N=map(int, raw_input().split())

A=[ [None for i in range(W+1) ] for j in range(H+1)]
for i in range(N):
	a,b=map(int, raw_input().split())
	A[a][b]=1

d=[-1,0,1]
D=list(itertools.product(d,d))

l=defaultdict(lambda: 0)

for x in range(2,H):
	for y in range(2,W):
		cnt=0
		for i,j in D:
			#print x+i,y+j,A[x+i][y+j]
			if A[x+i][y+j]==1:
				cnt+=1
		l[cnt]+=1

print l

for i in range(10):
	print l[i]


### FIXED CODE ###

import itertools
from collections import defaultdict
from collections import Counter
H,W,N=map(int, raw_input().split())

d=[-1,0,1]
D=list(itertools.product(d,d))

A=defaultdict(lambda: 0)
for i in range(N):
	a,b=map(int, raw_input().split())
	for dx,dy in D:
		cx=a+dx
		cy=b+dy
		if cx>=2 and cx<=H-1 and cy>=2 and cy<=W-1:
			A[(cx,cy)]+=1

C=Counter(A.values())


for i in range(10):
	if i==0:
		print (H-2)*(W-2)-sum(C.values())
	else:
		print C[i]
N = int(input())
H = list(map(int,input().split()))

#indexi番目にいるときの最小コスト
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print(func(N-1))


### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
import sys
import functools
#indexi番目にいるときの最小コスト
sys.setrecursionlimit(pow(10,6))

@functools.lru_cache(None)
def func(i):
    if i==0:
        return 0
    if i==1:
        return abs(H[0]-H[1])
    return min(func(i-1)+abs(H[i]-H[i-1]),func(i-2)+abs(H[i-2]-H[i]))

print(func(N-1))
import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [ ( 2*p1[0] + 1*p2[0] ) / 3. , ( 2*p1[1] + 1*p2[1]) / 3. ]
    t = [ ( 1*p1[0] + 2*p2[0] ) / 3. , ( 1*p1[1] + 2*p2[1]) / 3. ]
    u = [ ( t[0] - s[0] ) *0.5 - ( t[1] - s[1] )*sin60 + s[0],
        ( t[0] - s[0] )*sin60 + ( t[1] - s[1] )*0.5 + s[1] ]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n  = raw_input()
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

### FIXED CODE ###

import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [(2*p1[0]+1*p2[0])/3., (2*p1[1]+1*p2[1])/3.]
    t = [(1*p1[0]+2*p2[0])/3., (1*p1[1]+2*p2[1])/3.]
    u = [(t[0]-s[0])*0.5 - (t[1]-s[1])*sin60+ s[0],
        (t[0]-s[0])*sin60 + (t[1]-s[1])*0.5 + s[1]]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n = int(raw_input())
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]
N,Q = map(int, input().split())
l = list(map(int,input().split()))

ans = 0
for i in range(0,M):
  ans = ans + l[i]
  
if(ans > N):
  print("-1")
else:
  print(N-ans)  

### FIXED CODE ###

N,Q = map(int, input().split())
l = list(map(int,input().split()))
 
ans = 0
for i in range(0,Q):
  ans = ans + l[i]
  
if(ans > N):
  print("-1")
else:
  print(N-ans)
n = int(input())
s = input()

shiro_num = s.count(".")
kuro_num = n - shiro_num

right_kuro_num = kuro_num
right_siro_num = shiro_num

result = shiro_num

for e in s:
    if e == '.':
        right_siro_num -= 1
    else:
        right_kuro_num -= 1
    num = right_siro_num + kuro_num - right_kuro_num
    result = min(num,result)

print(result)

### FIXED CODE ###

a, b,c = list(map(int, input().split()))

result = 'Yes'
t = min(a,b)
u = max(a,b)
if c > t and c < u:
    print(result)
else :
    result = 'No'
    print(result)
n = int(input().split()[0])
v_list = list(map(int, input().split()))

# 奇数番目の数
odd_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 1]
# 偶数番目の数
even_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 0]

# 奇数の最頻値（No1とNo2)
odd_counter = collections.Counter(odd_list)
odd_1 = odd_counter.most_common()[0][0]

if len(odd_counter) >= 2:
    odd_2 = odd_counter.most_common()[1][0]
else:
    odd_2 = '*' # dummy

# 偶数の最頻値（No1とNo2)
even_counter = collections.Counter(even_list)
even_1 = even_counter.most_common()[0][0]

if len(even_counter) >= 2:
    even_2 = even_counter.most_common()[1][0]
else:
    even_2 = '+' # dummy

# 以前の方法だと条件分岐が複雑になるので
# とりうる操作を全部試して、回数が少ない方をとる

if even_1 == odd_1:
    # 偶数側の操作回数（最頻値で置き換え）
    even_op_count = len([v for v in even_list if v != even_1])
    # 奇数の操作回数
    odd_op_count = len([v for v in odd_list if v != odd_2])
    count_1 = even_op_count + odd_op_count

    # 偶数側の操作回数
    even_op_count = len([v for v in even_list if v != even_2])
    # 奇数側の操作回数（最頻値で置き換え）
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count_2 = even_op_count + odd_op_count

    count = min(count_1, count_2)
else:
    # 偶数側も奇数側も最頻値で置き換えればよい
    even_op_count = len([v for v in even_list if v != even_1])
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count = even_op_count + odd_op_count

print(count)


### FIXED CODE ###

# https://atcoder.jp/contests/abc111/tasks/arc103_a
# C - /\/\/\/
import collections

n = int(input().split()[0])
v_list = list(map(int, input().split()))

# 奇数番目の数
odd_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 1]
# 偶数番目の数
even_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 0]

# 奇数の最頻値（No1とNo2)
odd_counter = collections.Counter(odd_list)
odd_1 = odd_counter.most_common()[0][0]

if len(odd_counter) >= 2:
    odd_2 = odd_counter.most_common()[1][0]
else:
    odd_2 = '*' # dummy

# 偶数の最頻値（No1とNo2)
even_counter = collections.Counter(even_list)
even_1 = even_counter.most_common()[0][0]

if len(even_counter) >= 2:
    even_2 = even_counter.most_common()[1][0]
else:
    even_2 = '+' # dummy

# 以前の方法だと条件分岐が複雑になるので
# とりうる操作を全部試して、回数が少ない方をとる

if even_1 == odd_1:
    # 偶数側の操作回数（最頻値で置き換え）
    even_op_count = len([v for v in even_list if v != even_1])
    # 奇数の操作回数
    odd_op_count = len([v for v in odd_list if v != odd_2])
    count_1 = even_op_count + odd_op_count

    # 偶数側の操作回数
    even_op_count = len([v for v in even_list if v != even_2])
    # 奇数側の操作回数（最頻値で置き換え）
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count_2 = even_op_count + odd_op_count

    count = min(count_1, count_2)
else:
    # 偶数側も奇数側も最頻値で置き換えればよい
    even_op_count = len([v for v in even_list if v != even_1])
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count = even_op_count + odd_op_count

print(count)
import fractions
from functools import reduce
N,M= map(int,input().split())
A=[int(x) for x in input().split()]
def lcmpair(a,b):
    return (a*b)// fractions.gcd(a,b)
def lcm(List):
    return reduce(lcmpair,List,1)
lcmB = lcm(A) //2

crit = 0
pena = 0
num = A[0]
while num%2 == 0:
    crit +=1
    num = num//2
count = 0
for i in A:
    count = 0
    while i%2 == 0 :
        count +=1
        i = i//2
    if count != crit:
        pena = 1

if lcmB > M:
    print(0)
elif pena ==1:
    print(0)
else:
    print(((M//lcmB)+1)//2)   

### FIXED CODE ###

K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i) - bin(i).rfind("1") - 1)
print(round(ans))

### FIXED CODE ###

print(input().count("1"))
import numpy as np
s = input()
n = len(s)
chid = np.ones(n)
x = np.zeros((n,n))
for i in range(n):
    if s[i] == 'R':
        x[i][i+1] = 1
    else:
        x[i][i-1] = 1
        
x = np.linalg.matrix_power(x,10*100)
print(*map(int,np.dot(chid,x)))

### FIXED CODE ###


S = input()
n = len(S)
ans = [0 for i in range(n)]
for i in range(n):
    if S[i:i+2] == "RL":
        for j in range(i,-1,-1):
            if S[j] == "R":
                ans[i + (i-j) % 2] += 1
            else:
                break
        for j in range(i+1,n):
            if S[j] == "L":
                ans[i + (j-i) % 2] += 1
            else:
                break

print(*ans)
n = input()
d = {"S":[none]*13, "H":[none]*13, "C":[none]*13, "D":[none]*13}

for i in range(n):
	x, y = raw_input().split()
	d[x][int(y)-1] = True

for k in ["S","H","C","D"]:
	for i in range(13):
		if d[k][i]:
		print ("%s %d"%(k, i+1))

### FIXED CODE ###

n = int(raw_input())
lst = []
#store all the cards
for i in ["S","H","C","D"]:
	for j in xrange(1,14):
		lst.append("{0} {1}".format(i,j))
#discard the given cards
for i in range(n):
	a = raw_input()
	lst.remove(a)
#print the result
for i in range(len(lst)):
	print lst[i]
A,B-map(int,input().split())
A=A-1
B=B-1
print(A*B)

### FIXED CODE ###

A,B=map(int,input().split())
A=A-1
B=B-1
print(A*B)
l = input().split(" ")
n= int(l[0])
m= int(l[1])
x= int(l[2])
y= int(l[3])
xcon=[]
ycon= []
if x > y:
    print("War")
else:
    xcon = input().split(" ")
    for i in range(n-1):
        xcon[i] = int(xcon[i])
    ycon = input().split(" ")
    for i in range(m-1):
        ycon[i]=int(ycon[i])
    xcon = sorted(xcon)
    ycon = sorted(ycon)
    if x <= xcon[n] <ycon[0] <=  y :
        print("No war")
    else:
        print("War")

### FIXED CODE ###

l = input().split(" ")
n= int(l[0])
m= int(l[1])
x= int(l[2])
y= int(l[3])
xcon=[]
ycon= []

xcon = input().split(" ")
for i in range(n):
    xcon[i] = int(xcon[i])

ycon = input().split(" ")
for i in range(m):
    ycon[i]=int(ycon[i])

xcon = sorted(xcon)
ycon = sorted(ycon)

if max(x,xcon[-1]) < min(ycon[0],y):
    print("No War")
else:
    print("War")
N,M = map(int,input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i],B[i] = map(int,input().split())
C = [set()]
C[0].add(A[0])
C[0].add(B[0])
for i in range(1,M):
    for j in range(len(C)):
        if A[i] in C[j] or B[i] in C[j]:
            C[j].add(A[i])
            C[j].add(B[i])
        else:
            C.append({A[i],B[i]})
ans = 0
for j in range(len(C)):
    if len(C[j]) > ans:
        ans = len(C[j])
print(ans)

### FIXED CODE ###

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
    
N, M = map(int,input().split())
A = [None] * M
B = [None] * M
for i in range(M):
    A[i], B[i] = map(int,input().split())
uf = UnionFind(N)
for j,h in zip(A,B):
    uf.Unite(j,h)
print(min(uf.root)*(-1))
#154c
n = int(input())
a = [input() for _ in range(n)]

if len(list(set(a))) != len(a):
  print('NO')
else:
  print('YES')

### FIXED CODE ###

#154c
n = int(input())
a = list(input().split())

if len(list(set(a))) != len(a):
  print('NO')
else:
  print('YES')
a = int(input())
x = list(map(int,input().split()))
ax = list(set(x))
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
t = (len(x) == x.count(ax[0]) + x.count(ax[1]) + x.count(ax[2])) * (x.count(ax[1]) == x.count(ax[0]) and x.count(ax[0]) == x.count(ax[2])) + (sum(x) == 0)

y(1,t)

### FIXED CODE ###

a = int(input())
x = list(map(int,input().split()))
ax = list(set(x))
x.sort()
ax = list(set(x))
def ch(l):
    # print(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]])
    for i, j ,k in zip(l,l[1:] + [l[0]], l[2:] + [l[0]] +[l [1]]):
        if j != i ^ k: break
    else:
        return(1)
    return(0)
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')
if len(ax) < 3:
    if (sum(x) == 0) :
        print("Yes")
        exit()
    if (len(ax)) <2:
        print("No")
        exit()
    if x.count(0)*2 == x.count(ax[1]) and len(x) == x.count(0) + x.count(ax[1]):
        print("Yes")
        exit()
        
    print("No")
    exit()
t = (len(x) == x.count(ax[0]) + x.count(ax[1]) + x.count(ax[2])) * (x.count(ax[1]) == x.count(ax[0]) and x.count(ax[0]) == x.count(ax[2]))*ch(ax)

y(1,t)
n=int(input())
for i in range(n):
    a,b,c = input().split()
    x = int(a)
    y = int(b)
    z = int(c)
    p = [x,y,z]
    p.sort()
    if pow(p[0],2) + pow(p[1],2) == pow(p[2],2):
        print('YES')
    else:
        print('NO')


### FIXED CODE ###

n=int(input())
for i in range(n):
    a,b,c = input().split()
    x = int(a)
    y = int(b)
    z = int(c)
    p = [x,y,z]
    p.sort()
    if pow(p[0],2) + pow(p[1],2) == pow(p[2],2):
        print('YES')
    else:
        print('NO')
N = input()
List = map(int, input().split())
newList = sorted(List)[::-1]
print(sum(List)[::2] - sum(List)[1::2])

### FIXED CODE ###

N = input()
List = map(int, input().split())
nList = sorted(List)[::-1]
print(sum(nList[::2]) - sum(nList[1::2]))
n,k = map(int,input().split())
x = list(map(int,input().split()))

l = 0
r = k-1
mnm = 1000100010
while r<n:
    a = abs(x[l])+abs(x[l]-x[r])
    b = abs(x[r])+abs(x[r]-x[l])
    if a<=b:
        if a < mnm:
            mnm = a
    else:
        if b < mnm:
            mnm = b
    l += 1
    r += 1
print(mnm)

### FIXED CODE ###

n,i = map(int,input().split())
print(n-i+1)
N,Y=map(int,input().split())
answer=-1,-1,-1
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            answer=x,y,z
            break
    break
print(*answer)

### FIXED CODE ###

S = input()
print(S.replace("7","8",1))
A,B,M=map(int,input().split())

m=[[0] * B for i in range(A)]

a=list(map(int,input().split()))
b=list(map(int,input().split()))

minc=min(a)+min(b)

for i in range(M):
  x,y,c=map(int,input().split())
  cash=a[x]+b[y]-c

  if cash<minc:
    minc=cash


print(minc)

### FIXED CODE ###

A,B,M=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

minc=min(a)+min(b)

for i in range(M):
  x,y,c=map(int,input().split())
  cash=a[x-1]+b[y-1]-c

  if cash<minc:
    minc=cash

print(minc)
a, b, c, d = map(int, input().split())

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d
  print(a)
else:
  d -= a + b
  print(a-min(c, d))

### FIXED CODE ###

a, b, c, d = map(int, input().split())

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d:
  print(a)
else:
  d -= a + b
  print(a-min(c, d))
n = int(input())
m = int(-1 + (n-2) ** 0.5) + 1
for i in range(1,n+1):
  cnt = 0
  for x in range(1, m):
    for y in range(1, m):
      if (x+y)**2-4*(x**2+y**2+x*y-i) >0:
        z = (-(x+y)+((x+y)**2-4*(x**2+y**2+x*y-i))**0.5)/2       
        if z%1 == 0 and z>0:            
          cnt += 1
      else:
        break
  print(cnt)

### FIXED CODE ###

n = int(input())

a = [0]*10001

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1,101):
        v = x*x+y*y+z*z+x*y+y*z+x*z
        if  v < 10001:
        	a[v] += 1
for i in range(n):
  print(a[i+1])
from decimal import Decimal
import math
a,b,c = map(int,input().split())
routeA = pow(a,0.5)
routeB = pow(b,0.5)
routeC = pow(c,0.5)

if Decimal(pow(a,0.5)) + Decimal(pow(b,0.5)) > Decimal(pow(c,0.5)) or math.isclose(routeA+routeB,routeC):
    print('No')
else:
    print('Yes')

### FIXED CODE ###

from decimal import Decimal
import math
a,b,c = map(int,input().split())
d = c - a - b
if d >0 and pow(d,2) > 4 * a * b:
    print('Yes')
else:print('No')
INF = 10**10
arr = [INF,2,5,5,4,5,6,3,7,6]
N,M = map(int,input().split())
src = sorted(list(map(int,input().split())))

dp = [-INF]*(N+1)
dp[0] = 0
for i in range(N):
    for j in src:
        if i + arr[j] <= N:
            dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)
ans = ''
dim = dp[N]
while(dim > 0):
    for i in src[::-1]:
        if dp[N-arr[i]] == dp[N] - 1:
            ans += str(i)
            N -= arr[i]
            break
    dim -= 1
    if dim == 0:
        break
print(ans if ans else 0)

### FIXED CODE ###

INF = 10**10
arr = [INF,2,5,5,4,5,6,3,7,6]
N,M = map(int,input().split())
src = sorted(list(map(int,input().split())))

dp = [-INF]*(N+1)
dp[0] = 0
for i in range(N):
    for j in src:
        if i + arr[j] <= N:
            dp[i+arr[j]] = max(dp[i+arr[j]],dp[i] + 1)
dim = dp[N]
ans  = ''
while(dim > 0):
    for i in src[::-1]:
        if N >= arr[i] and dp[N-arr[i]] + 1 == dp[N]:
            ans += str(i)
            N -= arr[i]
            dim -= 1
            break
print(ans)
W, H, x, y, r = map(int, raw_input().split))
  
if 0 <= x-r and x+r <= W and 0 <= y-r and y+r <= H:
  print "Yes"
else:
 print "No

### FIXED CODE ###

W, H, x, y, r = map(int, raw_input().split())
 
if r <= x and x + r <= W and r <= y and y + r <= H:
 print 'Yes'
else:
 print 'No'
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split])

vector = []
for mi in range(m):
    vector.append(int(input()))


for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]
        
        print(sum)

### FIXED CODE ###

n, m = [int(i) for i in input().split()]
  
matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])
  
vector = []
for mi in range(m):
    vector.append(int(input()))
  
b = []
for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]
  
    print(sum)
import math
x, y = map(int, input().split())
def func(x, y):
    return (x * y) // math.gcd(x, y)

print(func(x, y))

### FIXED CODE ###

a, b = map(int, input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

print(lcm(a,b))
a,b,c=map(int,input().split())
print(min(a%*b*c,a*b%*c,a*b*c%))

### FIXED CODE ###

A, B, C = map(int, input().split())
print(min(C%2*A*B, A%2*B*C, B%2*C*A))
#!/usr/bin/env python
import numpy as np
x, y, z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

### FIXED CODE ###

#!/usr/bin/env python
import numpy as np
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))
S = input()
T = input()
print(S+T)

### FIXED CODE ###

S, T = input().split()
print(T+S)
N, Q = map(int, input().split())

ab_list = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    ab_list[a-1].append(b-1)
    ab_list[b-1].append(a-1)
    
px_list = [list(map(int,input().split())) for _ in range(Q)]
ans = [0] * N

for q, x in px_list:
    ans[q-1] += x

def add_point(num, root=-1):
    for c in ab_list[num]:
        if root == c:
            continue
        ans[c] += ans[num]
        add_point(c, num)
        
add_point(0, -1)

print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())

ab_list = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    ab_list[a-1].append(b-1)
    ab_list[b-1].append(a-1)
    
px_list = [list(map(int,input().split())) for _ in range(Q)]
ans = [0] * N

for q, x in px_list:
    ans[q-1] += x

def add_point(num, root=-1):
    for c in ab_list[num]:
        if root == c:
            continue
        ans[c] += ans[num]
        add_point(c, num)
        
add_point(0, -1)

print(*ans)
n = int(input())
lines = [i for i in range(24, n+1) if i % 2 != 0]

ans = 0
for i in lines:
    cnt = 0
    for j in range(1, i+1):
        if i % j == 0:
            cnt += 1
        if cnt == 8:
            ans += 1
print(ans)


### FIXED CODE ###

a, b = map(int, input().split())
print((a-1) * (b-1))