Harryxun/stf_run huggingface dataset:
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())

mappings = []

for i in range(n):
    mapping = [int(i) for i in input().split()]
    mappings.append(mapping)

for cx in range(101):
    for cy in range(101):
        H = -1
        for i in range(n):
            x,y,h = mappings[i]
            if h == 0:
                pass
            else:
                if H == -1:
                    H = h+abs(x-cx)+abs(y-cy)
                elif H!=h+abs(x-cx)+abs(y-cy):
                    break

                if i == len(mappings)-1:
                    ans = (cx,cy,H)

cx,cy,H = ans
print(cx,cy,H)


### FIXED CODE ###

#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
xyh = []
for i in range(N):
    x, y, h = LI()
    xyh.append([x, y, h])


"""

C_x C_y H

XYの高度はmax(H - abs(X - C_x) - abs(Y - C_y), 0)
"""
xyh = sorted(xyh, key=lambda xyh: xyh[2], reverse=True)

# print(xyh)
ans = (0,0,0)
for c_x in range(101):
    for c_y in range(101):
        H = 0
        flag = True
        for i, (x, y, h) in enumerate(xyh):
            if i == 0:
                H = h + abs(x - c_x) + abs(y - c_y)
            if h != max(H - abs(x - c_x) - abs(y - c_y), 0):
            # if H != max(h + abs(x - c_x) + abs(y - c_y), 0):
                flag = False
        if flag:
            ans = (c_x, c_y, H)
    
X, Y, H = ans
print(X, Y, H)
n=int(input())
d=[]
for i in range(n):
  s=list(input())
  s.sort()
  d.append(s)
d.sort()
def kaijou(X):
  if X==1:
    return 1
  return X*kaijou(X-1)
x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

print(d)
print(x)

for i in range(len(x)):
  if x[i]>1:
    x[i]=kaijou(x[i])/2
  else:
    x[i]=0
print(sum(x))

### FIXED CODE ###

n=int(input())
d=[list(input()) for i in range(n)]
count=0
ans=0
for i in range(n):
  d[i].sort()
d.sort()

for i in range(n-1):
  if d[i]==d[i+1]:
    count+=1
  elif d[i]!=d[i+1]:
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  if i==(n-2):
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  
print(int(ans))
N,M= map(int,input().split())

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

bc = [0]*M

for i in range(M):
    bc[i]=list(map(int, input().split()))


a.sort()
bc.sort(key=lambda x:-x[1])

# print(a)
# print(bc)
# ans = sum(a)
pre_ind = 0
now_ind = 0
for i in range(M):
    key = bc[i][0]
    value = bc[i][1]
    now_ind += key

    if value > a[now_ind-1]:
        a=a[:pre_ind]+[value]*key + a[now_ind:]
        pre_ind = now_ind


    else:
        max_count = key
        # print(key)
        key2 = key
        for j in range(key):
            now_ind -= 1
            key2 -= 1
            if value > a[now_ind-1]:
                a=a[:pre_ind]+[value]*key2 + a[now_ind:]
                # print(key2)
                break
        break

# print(a)

print(sum(a))













### FIXED CODE ###

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

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

bc = [0]*M

for i in range(M):
    bc[i]=list(map(int, input().split()))


a.sort()
bc.sort(key=lambda x:-x[1])

# print(a)
# print(bc)
ans = sum(a)
pre_ind = 0
now_ind = 0
for i in range(M):
    key = bc[i][0]
    value = bc[i][1]
    now_ind += key
    if now_ind > N:
        now_ind = N

    if value > a[now_ind-1]:
        ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
        # a=a[:pre_ind]+[value]*(now_ind-pre_ind)+ a[now_ind:]
        pre_ind = now_ind
        if now_ind == N:
            # print("ok")
            break
    else:
        max_count = key
        # print(key)
        key2 = key
        for j in range(key-1):
            now_ind -= 1
            key2 -= 1
            if value > a[now_ind-1]:
                # a=a[:pre_ind]+[value]*(now_ind-pre_ind) + a[now_ind:]
                ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
                # print(key2)
                break
        break

# print(a)

# print(sum(a))
print(ans)
A=[0]*(10**5+1)
for i in a:
	A[i]+=1

for bc in BC:
	diff= bc[1]-bc[0]
	SUM+=diff*A[bc[0]]
	A[bc[1]]+=A[bc[0]]
	A[bc[0]]-=A[bc[0]]
	print(SUM)

### FIXED CODE ###

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
a=input_array()
q=int(input())
BC=[input_array() for _ in range(q)]
SUM=sum(a)

A=[0]*(10**5+1)
for i in a:
	A[i]+=1

for bc in BC:
	diff= bc[1]-bc[0]
	SUM+=diff*A[bc[0]]
	A[bc[1]]+=A[bc[0]]
	A[bc[0]]-=A[bc[0]]
	print(SUM)
n = int(input())
a = [int(i) for i in input().spliit()]
ans = 0

while True:
  if [i for i in a if i%2 == 1]:
    break
  a = [ i//2 for i in a]
  ans += 1
print(ans)

### FIXED CODE ###

s = input()
s1 = int(s[0])
s2 = int(s[1])
s3 = int(s[2])

print(s1 + s2+s3)
import numpy as np

N = int(input())
Ps = list(map(int, input().split()))
Ps = np.array(Ps)
count = 0

for i in xrange(N):
    low = Ps[i]
    if ( np.sum(Ps[:i] < low) == 0):
        count += 1

print(count)

### FIXED CODE ###

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

if (N==M):
    print('Yes')
else :
    print('No')
n, m = map(int, input().split())
ans = ["0"]*n
if(m==0 and n==1):print(0);exit()
for i in range(m):
    a, b = map(int, input().split())
    if(ans[a-1] == "0"):ans[a-1] = str(b)
    elif(int(ans[a-1]) > b):ans[a-1] = str(b)
if(ans[0] == "0"):print(-1)
else:print("".join(ans))

### FIXED CODE ###

n = int(input())
if(n%2 == 0):print(int(n/2))
else:print(int(n/2)+1)
import sympy
N = int(input())

def enzan(k, yakusu):
    return(k * yakusu)


# def make_divisor_list(num):
#     if num == 1:
#         return 1
#     else:
#         cnt = 2
#         # divisor_list = []
#         # divisor_list.append(1)
#         for i in range(2, num // 2 + 1):
#             if num % i == 0:
#                 # divisor_list.append(i)
#                 cnt += 1
#         # divisor_list.append(num)

#         # return len(divisor_list)
#         return cnt


# def num_divisors_table(n):
#     table = [0] * (n + 1)

#     for i in range(1, n + 1):
#         for j in range(i, n + 1, i):
#             table[j] += 1

#     return table


wa = 0
for k in range(1, N+1):
    wa += enzan(k, sympy.divisor_count(k))

print(wa)

# print(make_divisor_list(4))




### FIXED CODE ###

N = int(input())

ans = 0
for  i in range(1, N + 1):
    ans += i * ((N // i) * ((N // i) + 1))/2

print((int)(ans))
while 1:
    print(float(input())**(1/3))
    if q<0:break


####################################################
####################################################
####################################################
####################################################
####################################################
####################################################
####################################################
####################################################
####################################################
####################################################
########################################################################################################
####################################################
####################################################
########################################################################################################v
############################################################################################################################################################
####################################################
####################################################
####################################################
########################################################################################################v
vv####################################################


### FIXED CODE ###

for e in iter(input,'-1'):
 q=float(e)
 x=q/2
 while abs(x**3-q)>=q*1e-5:x-=(x**3-q)/3/x/x
 print(x)
N = int(input())
A = list(map(int, input().split()))

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

m = [0] * (N+1)
for i in range(N):
    divisors = make_divisors(A[i])
    for d in divisors:
        m[d] += 1

ans = 1
for i in range(N+1):
    if (N-1) <= m[i] and ans < m[i]:
        ans = m[i]

print(ans)

### FIXED CODE ###

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

for i in range(1, N-1):
    left.append(gcd(left[-1], A[i]))
    right.append(gcd(right[-1], A[-1-i]))

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[-1]
    elif i == N-1:
        tmp = left[-1]
    else:
        tmp = gcd(left[i-1], right[N-2-i])
    ans = max(ans, tmp)

print(ans)
x, y = input().split();Sprint("=" if x==y else "<>"[x>y::2])

### FIXED CODE ###

x, y = input().split();print("=" if x==y else "<>"[x>y::2])
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m,s = a[-1],a[0]
if m!=a[-2] or (m+1)//2!=s or (m%2 and s-a[1]) or ((not m%2) and s==a[1]) or any(a.count(i)<2 for i in range(s+1,m)) or s==a[1]==a[2]: print("Impossible")
else: print("Possible")

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m,s = a[-1],a[0]
if m!=a[-2] or (m+1)//2!=s or (m%2 and s-a[1]) or ((not m%2) and s==a[1]) or any(a.count(i)<2 for i in range(s+1,m)) or (n!=2 and s==a[1]==a[2]): print("Impossible")
else: print("Possible")
while 1:
  H,W = map(raw_input().split())
  if H == 0 and W == 0:
    break

  for i in range(H):
    if i%2 == 0:
      if W%2 == 0:
        print "#."*(W/2)
      else:
        print "#."*(W/2) + "#"
    else:
      if W%2 == 0:
        print ".#"*(W/2)
      else:
        print ".#"*(W/2) + "."
  print ""

### FIXED CODE ###

while 1:
  H,W = map(int,raw_input().split())
  if H == 0 and W == 0:
    break

  for i in range(H):
    if i%2 == 0:
      if W%2 == 0:
        print "#."*(W/2)
      else:
        print "#."*(W/2) + "#"
    else:
      if W%2 == 0:
        print ".#"*(W/2)
      else:
        print ".#"*(W/2) + "."
  print ""
from math import gcd
from functools import reduce

def lcm(a, b):return a//gcd(a,b)*b
def lcm_list(x): return reduce(lcm, x)
def gcd_list(x): return reduce(gcd, x)

n,m = map(int, input().split())
a = [*map(lambda x: int(x)//2 , input().split())]
l = lcm_list(a)
if l <= m:
    print((m//l+2-1)//2) # round up
else:
    print(0)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
def lcm(a, b):return a//gcd(a,b)*b

def f(x):
    c = 0
    while x%2==0:
        x //= 2
        c += 1
    return c

n,m = map(int, input().split())
a = list(map(lambda x:int(x)//2, input().split()))
t = f(a[0])
m >>= t
l = 1
for x in a:
    if f(x) != t:
        print(0)
        quit()
    x >>= t
    l = l // gcd(l,x) * x
    if l > m:
        print(0)
        quit()

print((m//l+2-1)//2) # round up
import sys
input=sys.stdin.readline

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

R=[1 for i in range(N+1)]
A,B=map(int,input().split())
R[A]=0
R[B]=0

L=[[]for i in range(N+1)]
L[A].append(B)
L[B].append(A)

for i in range(M):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

l=[A]
P=A
#print(L)

for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            l.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(l)
r=[B]
P=B
for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            r.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(r)
l=l[::-1]
ans=l+r

ANS=str(ans[0])
for i in range(1,len(ans)):
    ANS+=" "+str(ans[i])
print(ANS)

### FIXED CODE ###

import sys
input=sys.stdin.readline

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

R=[1 for i in range(N+1)]
A,B=map(int,input().split())
R[A]=0
R[B]=0

L=[[]for i in range(N+1)]
L[A].append(B)
L[B].append(A)

for i in range(M-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

l=[A]
P=A
#print(L)

for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            l.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(l)
r=[B]
P=B
for i in range(10**6):
    flag=0
    #print("P",L[P])
    for j in L[P]:
        #print("j",L,L[P],j,P)
        if R[j]==1:
            P=j
            R[j]=0
            r.append(j)
            flag+=1
            break
    if flag==0:
        break
#print(r)
l=l[::-1]
ans=l+r

ANS=str(ans[0])
for i in range(1,len(ans)):
    ANS+=" "+str(ans[i])
print(len(ans))
print(ANS)
import math
import functools
n,x=map(int,input().split())
xl=list(map(int,input().split()))
a=[]
for i in range(n):
    a.append(abs(xl[i]-x))
ans=functools.reduce(math.gcd,a)
print(ans)

### FIXED CODE ###

import fractions
import functools
n,x=map(int,input().split())
xl=list(map(int,input().split()))
a=[]
for i in range(n):
    a.append(abs(xl[i]-x))
ans=functools.reduce(fractions.gcd,a)
print(ans)
from numba import njit
import numpy as np
def main(n,a):
  mp=np.zeros((40,40),np.int32)
  o=20
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    #if 0<=cnt5+o<23 and 0<=cnt2+o<23:
    mp[cnt5+o,cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=np.sum(mp[x:,y:])-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

n=int(input())
a=np.array([input() for _ in range(n)])
main(n,a)



### FIXED CODE ###

def main(n,a):
  k=60
  mp=[[0]*k for _ in range(k)]
  o=k//2
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    #if 0<=cnt5+o<23 and 0<=cnt2+o<23:
    mp[cnt5+o][cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[j][i-1]+=mp[j][i]
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[i-1][j]+=mp[i][j]
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=mp[x][y]-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

n=int(input())
a=[input() for _ in range(n)]
main(n,a)
def d_ki():
    import sys
    input = sys.stdin.readline
    N, Q = [int(i) for i in input().split()]

    tree = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) for i in input().split()]
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    ans = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        ans[p - 1] += x

    # 1次元配列だったら単純に累積和を取ればいいのだが、木なので
    # DFSをしなければならない
    def dfs(current, parent=-1):
        for child in tree[current]:
            if child == parent:
                continue
            ans[child] += ans[current]
            dfs(child, current)
    dfs(0)
    return ' '.join(map(str, ans))

print(d_ki())

### FIXED CODE ###

def d_ki():
    import sys
    input = sys.stdin.readline
    N, Q = [int(i) for i in input().split()]

    tree = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = [int(i) for i in input().split()]
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    ans = [0] * N
    for _ in range(Q):
        p, x = [int(i) for i in input().split()]
        ans[p - 1] += x

    # 1次元配列だったら単純に累積和を取ればいいのだが、木なので
    # DFSをしなければならない
    q = [0]
    is_visited = [False] * N
    while q:
        current = q.pop()
        is_visited[current] = True
        for child in tree[current]:
            if is_visited[child]:
                continue
            ans[child] += ans[current]
            q.append(child)
    return ' '.join(map(str, ans))

print(d_ki())
def input_N_T():
    N_T=input().split()
    int_N_T=list(map(int,N_T))
    N=int_N_T[0]
    T=int_N_T[1]
    return [N,T]

N,T=input_N_T()

min_c,min_t=1001,1001

for i in range(N):
    c,t=input_N_T()
    if(t<=T and min(min_c,c)==c):
        min_c,min_t=c,t

if(N==1001 and T==1001):
    print("TLE")
    
else:
print(c)

### FIXED CODE ###

def input_N_T():
    N_T=input().split()
    int_N_T=list(map(int,N_T))
    N=int_N_T[0]
    T=int_N_T[1]
    return [N,T]

N,T=input_N_T()

min_c,min_t=1001,1001

for i in range(N):
    c,t=input_N_T()
    if(t<=T and min(min_c,c)==c):
        min_c=c

if(min_c==1001):
    print("TLE")
    
else:
    print(min_c)
n = int(input())
v = list(sorted(map(int, input().split())))

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v[i+1:n-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

### FIXED CODE ###

n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
d = defaultdict(int)
for b in B:
    d[b] = len(C[bisect.bisect_right(C,b):])
for a in A:
    for b in B[bisect.bisect_right(B,a):]:
        ans += d[b]

print(ans)

### FIXED CODE ###

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
for b in B:
    tmp = bisect.bisect_right(C,b)
    tmp2 = bisect.bisect_left(A,b)
    ans += (n-tmp) * tmp2

print(ans)
a, b = map(int, input().split())
if (a == 1 and b == 2) or (a == 2 and b == 1):
    print(3)
elif (a == 1 and b == 3)or(a==3 and b==1):
    print(2)
elif (a == 2 and b == 3) or (a == 3 and b == 2):
    print(1)


### FIXED CODE ###

A=int(input())
B = int(input())
C = A + B
list = {3: '3', 4: '2', 5: '1'}
print(list[C])
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools


def main():
  r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)
  n, _ = list(map(int, input().split()))
  ps = list(map(int, input().split()))

  cs = [(p, r[p]) for p in ps]
  cs.sort(key=lambda x: x[1])
  a = []
  s, b = cs[0]

  while n - b > 0:
    a.append(s)
    n -= b

  cs.sort(key=lambda x:-x[0])
  cs = [(p, c - b) for p, c in cs if c != b]

  for i in range(1, len(cs) + 1):
    for ps in itertools.product(range(len(cs)), repeat=i):
      if sum(cs[p][1] for p in ps) == n:
        ds = [cs[p][0] for p in ps]
        break

  uds = [d for d in ds if d >= s]
  lds = [d for d in ds if d < s][::-1]

  a = uds + a[len(uds):]
  a = a[-len(lds):] + lds

  print(''.join(str(v) for v in a), flush=True)


if __name__ == '__main__':
  main()



### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def gen(base_digit, base_cost, base_length, digits, remain):
  number = [base_digit] * base_length
  remain -= base_cost * base_length

  if remain == 0:
    print(''.join(str(d) for d in number), flush=True)
    return True

  digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]

  if len(digits) == 0:
    return False

  max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))
  numbers = []

  for repeat in range(1, max_repeat + 1):
    for idxs in itertools.product(range(len(digits)), repeat=repeat):
      if sum(digits[i][1] for i in idxs) != remain:
        continue

      replaces = [digits[i][0] for i in idxs]
      uppers = [d for d in replaces if d > base_digit]
      lowers = [d for d in replaces if d < base_digit]

      num = number[:]

      if len(uppers) > 0:
        num = uppers + num[len(uppers):]

      if len(lowers) > 0:
        num = num[:-len(lowers)] + lowers

      numbers.append(num)

  if len(numbers) == 0:
    return False

  number = max(numbers)

  print(''.join(str(d) for d in number), flush=True)

  return True


def main():
  remain, _ = list(map(int, input().split()))

  digits = {}

  for d in map(int, input().split()):
    if COSTS[d] not in digits or digits[COSTS[d]] < d:
      digits[COSTS[d]] = d

  digits = [(d, c) for c, d in digits.items()]
  base_digit, base_cost = min(digits, key=lambda x: x[1])

  for length in range(remain // base_cost, -1, -1):
    if gen(base_digit, base_cost, length, digits, remain):
      break


if __name__ == '__main__':
  main()