Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

d = int(input())
c = list(map(int,input().split()))
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for k in range(330):
    for l in range(33):
        for i in range(d):
            s = sl[i]
            sp = sum(pen)
            temp = -(10**9)
            for j in range(26):
                if s[j]*l*0.1-(sp-pen[j])*(k*0.01) > temp:
                    temp = s[j]*l*0.1-(sp-pen[j])*(k*0.01)
                    tempans = j+1
            ans += [tempans]
            sattemp += s[tempans-1]-sp+pen[tempans-1]
            for j in range(26):
                pen[j] += c[j]
                pen[tempans-1] = 0
        if sattemp > sat:
            sat = sattemp
            fin = ans
        ans = []
        pen = [0]*26
        # print(k,sattemp)
        sattemp = 0
for i in fin:
    print(i)

### FIXED CODE ###

d = int(input())
c = list(map(int,input().split()))
for i in range(d):
    s = list(map(int,input().split()))
    print(s.index(max(s))+1)
### BUGGY CODE ###

N, M = map(int, input().split())
P = []
Y = []
D = [[] for i in range(N)]
for i in range(M):
  p, y = map(int, input().split())
  P.append(p)
  Y.append(y)
  D[p-1].append(y)

for l in D:
  l.sort()

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]-1].index(Y[i])+1).zfill(6)
  print(a+b)

### FIXED CODE ###

N, M = map(int, input().split())
D = [[] for i in range(N)]

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく

ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n')
### BUGGY CODE ###

#ABC158 D - String Formation

S = str(input())
Q = int(input())

for i in range(Q):
    q = input().split(' ')
    if(q[0] == '1'):
        S = S[::-1]

    else:
        if(q[1] == '1'):
            #temp = [q[2]]
            S = q[2] + S
        else:
            S = S + q[2]

print(S)


### FIXED CODE ###

#ABC158 D - String Formation

start = str(input())
Q = int(input())
S = "X"
cnt = 0
q = []
for i in range(Q):
    q.append(input().split(' '))
    if(q[i][0] == '1'):
        #S = S[::-1]
        cnt += 1

cntq = 0
for i in range(Q):
    #q = input().split(' ')
    if(q[i][0] == '1'):
        #S = S[::-1]
        cntq += 1
 
    else:
        if((q[i][1] == '1' and (cnt-cntq)%2 == 0) or(q[i][1] == '2' and (cnt-cntq)%2 == 1)):
            S = q[i][2] + S
        else:
            S = S + q[i][2]

if(cnt%2 == 1):
    start = start[::-1]


#print(S)
print(S.replace("X",start))
### BUGGY CODE ###

N,W=map(int,input().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(1,N+1):
  w[i],v[i]=map(int,input().split())

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

for i in range(1,N+1):
  for j in range(1,W+1):
    #print("i=",i,"j=",j)
    dp[i][j]=max(dp[i][j],dp[i-1][j])
    if j-w[i]<0: continue
    dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])

#print(dp)
print(dp[N][W])


### FIXED CODE ###

N,W=map(int,input().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(1,N+1):
  w[i],v[i]=map(int,input().split())

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

for i in range(1,N+1):
  for j in range(1,W+1):
    #print("i=",i,"j=",j)
    dp[i][j]=max(dp[i][j],dp[i-1][j])
    if j-w[i]<0: continue
    dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])

#print(dp)
print(dp[N][W])
### BUGGY CODE ###

import fractions
mod = 10**9 + 7
n = int(input())
lst = list(map(int, input().split()))
koubai = lst[0]
for i in range(1, n):
    koubai = koubai*lst[i]//fractions.gcd(koubai, lst[i])
 
total = 0
for l in lst:
    b = koubai//l
    total += b
    total %= mod
print(total)

### FIXED CODE ###

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

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

for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
mod = 10**9 + 7
ans = 0
for i in range(n):
    ans += lcm // a[i]
print(ans % mod)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
c = 0
while True:
  for i in A:
    if i%2:
      print(c)
      break
    i //= 2
    
  c += 1


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
c = 0
while True:
  for i in range(n):
    if A[i]%2:
      print(c)
      exit()
    A[i] //= 2
    
  c += 1
### BUGGY CODE ###

def main():
    from itertools import accumulate as ac
    n,k=map(int,input().split())
    kk=2*k
    xyc=[input().split() for _ in [0]*n]
    b=[[0]*(kk+1) for _ in [0]*(kk+1)]
    w=[[0]*(kk+1) for _ in [0]*(kk+1)]
    for x,y,c in xyc:
        if c=="B":b[int(x)%kk+1][int(y)%kk+1]+=1
        else:b[(int(x)+k)%kk+1][int(y)%kk+1]+=1
    b=[list(ac(i)) for i in b]
    for i in range(1,kk+1):
        for j in range(kk+1):
            b[i][j]+=b[i-1][j]
    ans=0
    for i in range(kk):
        if i==0:
            a_t=((i,i+k,0),(i+k,kk,1))
        elif i<k:
            a_t=((0,i,-1),(i,i+k,0),(i+k,kk,1))
        elif i==k:
            a_t=((0,i,-1),(i,kk,0))
        else:
            a_t=((0,i-k,-2),(i-k,i,-1),(i,kk,0))
        for j in range(kk):
            if j==0:
                b_t=((j,j+k,0),(j+k,kk,1))
            elif j<k:
                b_t=((0,j,-1),(j,j+k,0),(j+k,kk,1))
            elif j==k:
                b_t=((0,j,-1),(j,kk,0))
            else:
                b_t=((0,j-k,-2),(j-k,j,-1),(j,kk,0))
            black=[]
            for i,j,l in a_t:
                for x,y,z in b_t:
                    if (l+z)%2==0:
                        black.append((i,x,j,y))
            ret=0
            for tx1,ty1,tx2,ty2 in black:
                ret+=b[tx1][ty1]+b[tx2][ty2]-b[tx1][ty2]-b[tx2][ty1]
            ans=max(ans,ret)
    print(ans)
main()


### FIXED CODE ###

def main():
    from itertools import accumulate as ac
    n,k=map(int,input().split())
    kk=2*k
    xyc=[input().split() for _ in [0]*n]
    b=[[0]*(k+1) for _ in [0]*(kk+1)]
    for x,y,c in xyc:
        if c=="B":
            if int(y)%kk<k:
                b[int(x)%kk+1][int(y)%k+1]+=1
            else:
                b[(int(x)+k)%kk+1][int(y)%k+1]+=1
        else:
            if int(y)%kk<k:
                b[(int(x)+k)%kk+1][int(y)%k+1]+=1
            else:
                b[int(x)%kk+1][int(y)%k+1]+=1
    b=[list(ac(i)) for i in b]
    for i in range(1,kk+1):
        for j in range(k+1):
            b[i][j]+=b[i-1][j]
    ans=0
    for i in range(kk):
        if i==0:
            a_t=((i,i+k,0),(i+k,kk,1))
        elif i<k:
            a_t=((0,i,-1),(i,i+k,0),(i+k,kk,1))
        elif i==k:
            a_t=((0,i,-1),(i,kk,0))
        else:
            a_t=((0,i-k,-2),(i-k,i,-1),(i,kk,0))
        for j in range(k):
            if j==0:
                b_t=((0,k,0),)
            else:
                b_t=((0,j,-1),(j,k,0))
            black=[]
            for i,j,l in a_t:
                for x,y,z in b_t:
                    if (l+z)%2==0:
                        black.append((i,x,j,y))
            ret=0
            for tx1,ty1,tx2,ty2 in black:
                ret+=b[tx1][ty1]+b[tx2][ty2]-b[tx1][ty2]-b[tx2][ty1]
            ans=max(ans,ret)
    print(ans)
main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

for l, r in lr:
    print(s[l-1:r].count('AC'))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

cnt = [0 for _ in range(n)]
for i in range(1, n):
    cnt[i] = cnt[i-1]
    cnt[i] += 1 if s[i-1:i+1] == "AC" else 0

for l, r in lr:
    print(cnt[r-1] - cnt[l-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]
next_list = []
now_list = [(-1,0)]
ok = "."
cnt = 0
goal = 0
direction = ((1,0),(0,1))
while goal == 0:
    
    next_list = set()
    for x, y in now_list:
        if x == W-1 and y == H-1:
            goal = 1
            break
        for nx, ny in direction:
            nx += x
            ny += y
            if nx >= W or ny >= H or nx < 0 or ny < 0:
                continue
            if field[ny][nx] == ok:
                next_list.add((nx,ny))
    if goal == 1:
        pass
    elif len(next_list) > 0:
        now_list = list(next_list)
    else:
        if ok == ".":
            cnt += 1
            direction = ((1,0),(0,1),(-1,0),(0,-1))
            ok = "#"
        else:
            direction = ((1,0),(0,1))
            ok = "."

print(cnt)


### FIXED CODE ###

H, W = map(int, input().split())
#field = [list(input()) for _ in range(H)]
field =[["."] * (W+1)]
for _ in range(H):
    tmp = ["."]
    tmp.extend(list(input()))
    field.append(tmp)

dp = [[10**9] * (W+1) for _ in range(H+1)]
dp[1][0] = 0
dp[0][1] = 0
for h in range(1,H+1):
    for w in range(1,W+1):
        if field[h][w] == ".":
            dp[h][w] = min(dp[h-1][w], dp[h][w-1])
        else:
            u = dp[h-1][w] if field[h-1][w] == "#" else dp[h-1][w] + 1
            l = dp[h][w-1] if field[h][w-1] == "#" else dp[h][w-1] + 1
            dp[h][w] = min(u,l)

print(dp[-1][-1])
### BUGGY CODE ###

k = int(input())

if k % 2 == 0:
    print(-1)
else:
    now = 7
    ans = 1
    md = 7 % k
    while md != 0:
        md *= 10
        md += 7
        md %= k
        ans += 1
    print(ans)



### FIXED CODE ###

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    md = 7 % k
    while md != 0:
        md *= 10
        md += 7
        md %= k
        ans += 1
    print(ans)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())

list_cake_1 = list(map(int, input().split()))
list_cake_2 = list(map(int, input().split()))
list_cake_3 = list(map(int, input().split()))

list_cake_1 = sorted(list_cake_1, reverse=True)
list_cake_2 = sorted(list_cake_2, reverse=True)
list_cake_3 = sorted(list_cake_3, reverse=True)


list_total_sum = [cake_1 + cake_2 + cake_3 for i, cake_1 in enumerate(list_cake_1, 1) for j, cake_2 in enumerate(list_cake_2, 1) for k, cake_3 in enumerate(list_cake_3, 1) if i*j*k <= K]

for element in sorted(list_total_sum, reverse=True)[:K]:
	print(element)

### FIXED CODE ###

import sys

input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())

list_cake_1 = list(map(int, input().split()))
list_cake_2 = list(map(int, input().split()))
list_cake_3 = list(map(int, input().split()))

list_cake_1 = sorted(list_cake_1, reverse=True)
list_cake_2 = sorted(list_cake_2, reverse=True)
list_cake_3 = sorted(list_cake_3, reverse=True)

list_total_sum = []

for i, cake_1 in enumerate(list_cake_1, 1):
	for j, cake_2 in enumerate(list_cake_2, 1):
		for k, cake_3 in enumerate(list_cake_3, 1):
			if i*j*k > K:
				break
			list_total_sum.append(cake_1 + cake_2 + cake_3)

for element in sorted(list_total_sum, reverse=True)[:K]:
	print(element)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    if R * r > N:
        break
    for g in range(3001):
        if R * r + G * g > N:
            break
        elif (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)


### FIXED CODE ###

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        if (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

from math import sqrt

def func(num):
    for i in range(2, lim_n+1):
        for j in range(2, i+1):
            for k in range(2, j+1):
                p = i**2 + j ** 2 + k ** 2
                if p > 2 * num:
                    break
                elif p == 2 * num:
                    if (j + k) - i != 0 and ((j + k) - i) % 2 == 0:
                        if i == j and j == k:
                            if i  % 2 ==1:
                                break
                            return 1
                        elif i != j and j != k:
                            return 6
                        else:
                            return 3
                        
    return 0

n = int(input())
lim_n = int(sqrt(n))
for i in range(1, n+1):
    print(func(i))

### FIXED CODE ###

from math import sqrt

n = int(input())
lim_n = int(sqrt(n*2))
result = [0] * n

for i in range(2, lim_n+1):
    for j in range(2, i+1):
        for k in range(2, j+1):
            p = i**2+j**2+k**2
            if p > 2*n:
                break
            if p % 2 == 1:
                continue
            if (j + k) - i < 2:
                continue
            if i == j and j == k:
                if i  % 2 ==1:
                    continue
                result[p//2-1] += 1
            elif i != j and j != k:
                result[p//2-1] += 6
            else:
                result[p//2-1] += 3

for item in result:
    print(item)
### BUGGY CODE ###

import sys
import math
from collections import defaultdict


def first_prime_list(N):
    D = [1] * (N + 1)

    for i in range(2, N + 1):
        if D[i] != 1:
            continue
        for j in range(1, N // i + 1):
            if D[i * j] == 1:
                D[i * j] = i

    return D


def factorization_with_fpl(A, D):

    Ps = defaultdict(int)
    current_p = D[A]

    while D[A] > 1:
        cnt = 0
        while D[A] == current_p:
            A = A // D[A]
            cnt += 1

        Ps[current_p] = cnt
        current_p = D[A]

    if A != 1:
        Ps[A] = 1

    return Ps


N = int(sys.stdin.readline().rstrip())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]

D = first_prime_list(max(A))

pc = True
sp = True

maxlist = factorization_with_fpl(A[0], D)

GCD = A[0]
for i in range(1,N):
    GCD = math.gcd(GCD, A[i])

for i in range(1, N):
    d = factorization_with_fpl(A[i], D)
    for p in d.keys():
        if min(maxlist[p], d[p]) != 0:
            pc = False
        maxlist[p] = max(maxlist[p], d[p])

if GCD != 1:
    print("not coprime")
elif pc:
    print("pairwise coprime")
else:
    print("setwise coprime")


### FIXED CODE ###

import sys
import math


N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7


def main():
    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

    maxA = max(A)

    # 1 <= a <= maxA までの、要素の登場回数
    C = [0] * (maxA + 1)
    for a in A:
        C[a] += 1

    pc = True

    # p の倍数である個数をカウントする
    for p in range(2, maxA + 1):
        cnt = 0
        for k in range(maxA // p + 1):
            cnt += C[k * p]

        # k*p となるような要素が2個以上あったら、pairwise coprime ではない
        if cnt > 1:
            pc = False

    if pc:
        print("pairwise coprime")
        return

    GCD = A[0]
    for i in range(1, N):
        GCD = math.gcd(GCD, A[i])

    if GCD == 1:
        print("setwise coprime")
        return

    print("not coprime")


main()
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A.sort()

    B = [0] * (max(A) + 1)

    ans = 0
    for i, a in enumerate(A):
        if B[a] == 1:
            continue
        for aa in range(a, max(A) + 1, a):
            B[aa] = 1

        if i != len(A) - 1 and A[i] == A[i + 1]:
            continue

        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    aset = list(set(A))
    aset.sort()

    ans = [0] * (10 ** 6 + 1)

    for a in aset:
        for i in range(2, 10 ** 6 + 1):
            if a * i > 10 ** 6:
                break
            ans[a * i] += 1

    res = 0
    c = collections.Counter(A)
    for a in A:
        if ans[a] == 0 and c[a] == 1:
            res += 1

    print(res)



if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
mod = 10**9+7

E = [[] for _ in [0]*N]
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

ans = K
q = [0]
V = [[-1,-1] for _ in [0]*N]
V[0] = [0,0]
while q:
    qq = []
    for i in q:
        tmp = sorted(set(V[i]))
        cSet = list(range(tmp[0])) + list(range(tmp[0]+1,tmp[-1])) + list(range(tmp[-1]+1,K))
        l = len(cSet)
        for j in E[i]:
            if V[j][0]!=-1:continue
            ans = ans * l % mod
            if ans == 0:break
            qq.append(j)
            V[j] = [cSet.pop(),V[i][0]]
            l -= 1
    q = qq
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
mod = 10**9+7

E = [[] for _ in [0]*N]
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

ans = K
q = [0]
V = [False for _ in [0]*N]
V[0] = True
while q:
    qq = []
    for i in q:
        #tmp = sorted(set(V[i]))
        #cSet = list(range(tmp[0])) + list(range(tmp[0]+1,tmp[-1])) + list(range(tmp[-1]+1,K))
        l = K-2+(i==0)
        for j in E[i]:
            if V[j]:continue
            ans = ans * l % mod
            if ans == 0:break
            qq.append(j)
            V[j] = True
            l -= 1
    q = qq
print(ans)
### BUGGY CODE ###

H, W = map(int, input().split())
T = [[] for i in range(H)]
d = []
num = 0
for i in range(H):
    a = list(input())
    T[i] = a
    for j in range(W):
        if a[j] == '#':
            d.append((i, j, 0))
            num += 1

ma = 0
while len(d) > 0:
    x, y, k = d.pop(0)
    ma = max(ma, k)
    for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == '.':
            T[nx][ny] = '#'
            d.append((nx, ny, k + 1))
            if num == H * W:
                break

print(ma)


### FIXED CODE ###

import sys
H, W = map(int, sys.stdin.readline().split())
INF = float('inf')
S = [[INF] * W for i in range(H)]
for i in range(H):
    a = list(sys.stdin.readline())
    for j in range(W):
        if a[j] == '#':
            S[i][j] = 0

ma = 0
for i in range(1, H):
    for j in range(W):
        S[i][j] = min(S[i][j], S[i - 1][j] + 1)

for i in range(H - 2, -1, -1):
    for j in range(W):
        S[i][j] = min(S[i][j], S[i + 1][j] + 1)

for i in range(H):
    for j in range(1, W):
        S[i][j] = min(S[i][j], S[i][j - 1] + 1)

for i in range(H):
    for j in range(W - 2, -1, -1):
        S[i][j] = min(S[i][j], S[i][j + 1] + 1)

for i in range(H):
    for j in range(W):
        ma = max(ma, S[i][j])

print(ma)
### BUGGY CODE ###

import math

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

l = [0]

for x in range(n+1):
    ans = 0
    ans = math.floor(a*x/b) - a * math.floor(x/b)
    l.append(ans)
    if max(l) > ans:
        break
print(max(l))

### FIXED CODE ###

A,B,N=map(int,input().split())
def f(x):
  return int(A*x/B)-A*int(x/B)

print(f(min(N,B-1)))
### BUGGY CODE ###

n, m = map(int, input().split(' '))
a = []
for i in range(m):
    a.append(int(input()))


s = [0] * (n + 1)
s[0] = 1
for i in range(n):
    j = i + 1
    while(j <= min(n, i + 2)):
        if j not in a:
            s[j] += s[i]
            s[j] = int(s[j] % 1000000007)
        j += 1

print(s[n])


### FIXED CODE ###

n, m = map(int, input().split(' '))
a = set()
for i in range(m):
    a.add(int(input()))


s = [0] * (n + 1)
s[0] = 1
for i in range(n):
    j = i + 1
    while(j <= min(n, i + 2)):
        if j not in a:
            s[j] += s[i]
            s[j] = int(s[j] % 1000000007)
        j += 1

print(s[n])
### BUGGY CODE ###

from sys import stdin
import math
a, b = [int(x) for x in stdin.readline().rstrip().split()]
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
g = gcd(a,b)
h = []
answer = 0
for i in range(g):
    if g % (i+1) == 0:
        h.append(i+1)
for i in range(len(h)):
    if i == 0:
        answer += 1
    else:
        t = 1
        for j in range(i):
            if j != 0:
                if h[i] % h[j] == 0:
                    t = 0
        if t == 1:
            answer += 1
print(answer)
            

### FIXED CODE ###

from sys import stdin
import math
a, b = [int(x) for x in stdin.readline().rstrip().split()]
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
g = gcd(a,b)
answer = factorize(g)
answer = list(set(answer))
print(len(answer) + 1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

#import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

N, M = map(int,input().split())
A = list(map(int, input().split()))
INF = 1e+10
def f(x):
    if x == 1:
        return 2
    if x == 2:
        return 5
    if x == 3:
        return 5
    if x == 4:
        return 4
    if x == 5:
        return 5
    if x == 6:
        return 6
    if x == 7:
        return 3
    if x == 8:
        return 7 
    if x == 9:
        return 6

A.sort(reverse=True)

dp=[-INF]*(N+1)
dp[0] = 0
for i in range(1,N+1):
    for j in range(M):
        if i-f(A[j]) >= 0:
            dp[i] = max(dp[i],dp[i-f(A[j])]+1)
 
ans = ""
remain = dp[N]
match = N

while match > 0:
    for i in range(M):
        if match - f(A[i]) > 0 and dp[match - f(A[i])] == remain - 1:
            ans += str(A[i])
            match -= f(A[i])
            remain -= 1
            
            break
            
print(ans)



### FIXED CODE ###

import sys
input = sys.stdin.readline

#import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

N, M = map(int,input().split())
A = list(map(int, input().split()))
INF = 1e+10
def f(x):
    if x == 1:
        return 2
    if x == 2:
        return 5
    if x == 3:
        return 5
    if x == 4:
        return 4
    if x == 5:
        return 5
    if x == 6:
        return 6
    if x == 7:
        return 3
    if x == 8:
        return 7 
    if x == 9:
        return 6

A.sort(reverse=True)

dp=[-INF]*(N+1)
dp[0] = 0
for i in range(1,N+1):
    for j in range(M):
        if i-f(A[j]) >= 0:
            dp[i] = max(dp[i],dp[i-f(A[j])]+1)
 
ans = ""
remain = dp[N]
match = N

while match > 0:
    for i in range(M):
        if match - f(A[i]) >=0 and dp[match - f(A[i])] == remain - 1:
            ans += str(A[i])
            match -= f(A[i])
            remain -= 1
            
            break
            
print(ans)
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0] * n

    for i in range(1,n):
        a = (dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-k),i))        
        dp[i] = min(a)

    print(dp[-1])

main()


### FIXED CODE ###

# numpy version

import numpy as np

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n)

for i in range(1,n): 
    j = max(0, i-k)
    dp[i] = np.min(dp[j:i] + np.abs(h[i] - h[j:i]))

print(int(dp[-1]))
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

n = int(input())
A = list(int(x) for x in input().split())
A.sort()
used = [False] * n
ans = 0
for i in reversed(range(n)):
    if used[i]:
        continue
    m = A[i]
    used[i] = True
    t = m.bit_length()
    pair = 2**t - m
    l = bisect_left(A, pair)
    r = bisect_right(A, pair)
    if r - l > 0:
        for j in range(l, r):
            if used[j]:
                continue
            else:
                ans += 1
                used[j] = True
                break

print(ans)


### FIXED CODE ###

from collections import defaultdict

n = int(input())
A = list(int(x) for x in input().split())

count = defaultdict(int)
for a in A:
    count[a] += 1
A = sorted(set(A))

ans = 0
for a in reversed(A):
    t = a.bit_length()
    pair = 2**t - a
    if pair == a:
        ans += count[a] // 2
        count[a] -= count[a] // 2
    else:
        k = min(count[a], count[pair])
        ans += k
        count[a] -= k
        count[pair] -= k

print(ans)