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

is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x):
    res = {}
    for prime in primes:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    ys = [do_prime_fact(x[i+1] - x[i]) for i in range(len(x)-1)]
    d = 1
    for k in ys[0].keys():
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

### FIXED CODE ###

is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x, ps):
    res = {}
    for prime in ps:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    y = do_prime_fact(x[1] - x[0], primes)
    ps = y.keys()
    ys = [do_prime_fact(x[i+1] - x[i], ps) for i in range(len(x)-1)]
    d = 1
    for k in ps:
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict, deque

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, M: int, L: "List[int]", R: "List[int]", D: "List[int]"):
    visited = 0
    pos = [None] * N
    adj = [set() for _ in range(N)]

    for l, r, d in zip(L, R, D):
        adj[l].add((r, d))
        adj[r].add((l, -d))
    
    for i in range(N):
        if (visited >> i) % 2 == 1:
            continue
        pos[i] = 0
        Q = deque([i], M)
        while len(Q) > 0:
            u = Q.popleft()
            visited |= 1 << u
            for v, d in adj[u]:
                if pos[v] is None:
                    pos[v] = pos[u] + d
                elif pos[v] != pos[u] + d:
                    print(NO)
                    return

                if (visited >> v) % 2 == 1:
                    continue
                Q.append(v)
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]" 
    R = [int()] * (M)  # type: "List[int]" 
    D = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        L[i] = int(next(tokens)) - 1
        R[i] = int(next(tokens)) - 1
        D[i] = int(next(tokens))
    solve(N, M, L, R, D)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict, deque

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, M: int, adj):
    visited = [False] * N
    pos = [None] * N

    for i, vis in enumerate(visited):
        if vis:
            continue
        pos[i] = 0
        visited[i] = True
        Q = deque([i], M)
        while len(Q) > 0:
            u = Q.popleft()
            for v, d in adj[u]:
                if pos[v] is None:
                    pos[v] = pos[u] + d
                elif pos[v] != pos[u] + d:
                    print(NO)
                    return

                if visited[v]:
                    continue
                Q.append(v)
                visited[v] = True
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    adj = [set() for _ in range(N)]
    for i in range(M):
        l = int(next(tokens)) - 1
        r = int(next(tokens)) - 1
        d = int(next(tokens))
        adj[l].add((r, d))
        adj[r].add((l, -d))
    solve(N, M, adj)

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

from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# print(N, M, K)
# print(A)
# print(B)

num_books = 0
remaining_time = K

A_ = ['A'] * len(A)
B_ = ['B'] * len(B)
AB_ = A_ + B_
# print(AB_)

import itertools
patterns = []
for v in itertools.permutations(AB_, len(AB_)):
    patterns.append(''.join(v))
patterns = list(set(patterns))
# print(patterns, len(patterns))

answer = 0
for pattern in patterns:
    remaining_time = K
    num_books = 0

    table = {
        'A': deque(A),
        'B': deque(B),
    }
    for book in pattern:
        if len(table[book]) <= 0: break

        remaining_time -= table[book].popleft()
        if remaining_time < 0: break
        
        num_books += 1
    # print(pattern, num_books)
    
    answer = max(answer, num_books)

print(answer)


### FIXED CODE ###

from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# print(N, M, K)
# print(A)
# print(B)


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
f, g, ans = [0], [0], 0
for i in range(1, N + 1):
    f.append(f[i-1] ^ A[i-1])
    g.append(g[i-1] + A[i-1])
for r in range(1, N + 1):
    for l in range(1, r + 1):
        ans += f[r] ^ f[l-1] == g[r] - g[l-1]
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
l, r, fl, fr, gl, gr, ans= 0, 0, 0, A[0], 0, A[0], 0
while l < N:
    while r+1 < N and fr-fl+A[r+1] == gr^gl^A[r+1]:
        r += 1
        fr += A[r]
        gr ^= A[r]
    ans += r-l+1
    fl += A[l]
    gl ^= A[l]
    l += 1
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
f=[0]*n
for i,a in enumerate(zip(s,s[1:])):
  if a==("A","C"):f[i]=1
for i in range(q):
  l,r=map(int,input().split())
  print(sum(f[l-1:r-1]))

### FIXED CODE ###

n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-1])
### BUGGY CODE ###

import sys
#sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

import bisect
def ok(x):
    # x以下になる組み合わせがk個以上
    cnt = 0
    for a in A:
        if a > 0:
            c = x//a
            cnt += bisect.bisect_right(A, c)
        elif a < 0:
            c = (-x-1)//(-a)
            cnt += n - bisect.bisect_right(A, c)
        else:
            if x >= 0:
                cnt += n
    for a in A:
        if a*a <= x:
            cnt -= 1
    cnt = cnt//2
    if cnt >= k:
        return True
    else:
        return False

l = -10**18-1
r = 10**18+1
while l+1 < r:
    m = (l+r)//2
    if ok(m):
        r = m
    else:
        l = m
print(r)


### FIXED CODE ###

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

import numpy as np

n, k = map(int, input().split())
A = np.array(input().split(), np.int64)
A = np.sort(A)

P = A[A>0]
Z = A[A==0]
N = A[A<0]

#t = n*(n-1)//2

def ok(x):
    # x以下になる組み合わせがk個以上
    cnt = 0
    #cnt += np.searchsorted(A, np.ceil(x/P), side='right').sum()
    cnt += np.searchsorted(A, x//P, side='right').sum()
    #cnt += n-np.searchsorted(A, np.floor(x/N), side='left').sum()
    cnt += (n-np.searchsorted(A, (-x-1)//(-N), side='right')).sum()
    if x >= 0:
        cnt += len(Z)*n
    cnt -= np.count_nonzero(A*A <= x)
    cnt = cnt//2
    if cnt >= k:
        return True
    else:
        return False

l = -10**18-1
r = 10**18+1
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)
### BUGGY CODE ###

MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]

sum = 0
num = len(ary)
for diff in range(num - 1):
  for i in range(num - diff - 1):
    # print(i, i + diff + 1)
    sum += ary[i] * ary[i + diff + 1]

print(sum % MOD)

### FIXED CODE ###

MOD = 1000000007

n = int(input())
str_ary = input().split()
ary = [int(c) for c in str_ary]
# ary = []
# queue = [0 for i in range(n)]
# for i int range(n):
#   num = int(str_ary[i])
#   ary.append(num)
#   for j int range(i):
#     pre_queue = []
#     queue.append(pre_queue)

result = 0
sum = sum(ary[i] for i in range(n))
# for diff in range(1, n):
#   for i in range(n - diff):
#     # print(diff, i, i + diff)
#     sum += ary[i] * ary[i + diff] % MOD
for i in range(n):
  sum -= ary[i]
  result += ary[i] * sum

print(result % MOD)
### BUGGY CODE ###

words = ("dreamer", "eraser", "dream", "erase")

s = input()

pos = 0
while pos < len(s):
    for w in words:
        if s.startswith(w, pos):
            pos += len(w)
            break
if pos == len(s):
    print("YES")
else:
    print("NO")


### FIXED CODE ###

words = ("dream", "erase", "eraser", "dreamer")

s = input()

while len(s) > 0:
    match = False
    for w in words:
        if s.endswith(w):
            s = s[:-len(w)]
            match = True
            break
    if match is False:
        print("NO")
        exit()
print("YES")
### BUGGY CODE ###

S = list(input())
q = int(input())
procedure = [list(input().split()) for i in range(q)]

for i in range(q):
    if procedure[i][0] == '1':
        S.reverse()
    if procedure[i][0] == '2':
        if procedure[i][1] == '1':
            S.insert(0,procedure[i][2])
        else:
            S.append(procedure[i][2])

print(''.join(S))


### FIXED CODE ###

S = list(input())
q = int(input())
procedure = [list(input().split()) for i in range(q)]

cnt = 0
S2 = []

for i in range(q):
    if procedure[i][0] == '1':
        cnt += 1
    if procedure[i][0] == '2':
        if (procedure[i][1] == '1' and cnt%2 == 0) or (procedure[i][1] == '2' and cnt%2 == 1):
            S2.append(procedure[i][2])
        else:
            S.append(procedure[i][2])

S2.reverse()
S = S2 + S
if cnt%2 == 1:
    S.reverse()

print(''.join(S))
### BUGGY CODE ###

## ABC 048 b
a,b,x = (int(_) for _ in input().split())

c = 0
for i in range(a, b+1):
    if(i%x == 0):
        c += 1
        
print(c)

### FIXED CODE ###

## ABC 048 b
a,b,x = (int(_) for _ in input().split())

if(a != 0):
    print(b//x - (a-1)//x)
else:
    print(b//x + 1 )
### BUGGY CODE ###

import sys

n, k = map(int, input().split())
c = list(map(int, input().split()))

maxNum = sys.maxsize

dp = [maxNum] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if (0 <= i+j) & (i+j <= n-1):
            dp[i+j] = min(dp[i+j], dp[i] + abs(c[i] - c[i+j]))

print(dp[n-1])

### FIXED CODE ###

import sys
 
n, k = map(int, input().split())
c = list(map(int, input().split()))
 
maxNum = sys.maxsize
 
dp = [maxNum] * n
dp[0] = 0
 
for i in range(n):
    for j in range(1, k+1):
        if (0 <= i+j) & (i+j <= n-1):
            dp[i+j] = min(dp[i+j], dp[i] + abs(c[i] - c[i+j]))
 
print(dp[n-1])
### BUGGY CODE ###

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

S = [None] * N
T = [None] * N
X = [None] * N
for i in range(N):
    S[i], T[i], X[i] = map(int, input().split())

D = [None] * Q
for i in range(Q):
    D[i] = int(input())
    
# X S T
roadworks = [(x, s, t) for x, s, t in zip(X, S, T)]
roadworks = sorted(roadworks, key=lambda x: x[0])
#print(roadworks)

# Dは入力時点でソート済み
walkers = D[:]
ans = [-1] * Q
skip = [-1] * Q

import bisect
for x, s, t in roadworks:
    left = bisect.bisect_left(walkers, s - x)
    right = bisect.bisect_left(walkers, t - x)
    
    i = left
    while i < right:
        if skip[i] == -1:
            ans[i] = x
            skip[i] = right
            i += 1
        else:
            i = skip[i]

    
#print(walkers)
for a in ans:
    print(a)
    




    
    


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

S = [None] * N
T = [None] * N
X = [None] * N
for i in range(N):
    S[i], T[i], X[i] = map(int, input().split())

D = [None] * Q
for i in range(Q):
    D[i] = int(input())
    
# X S T
roadworks = [(x, s, t) for x, s, t in zip(X, S, T)]
roadworks = sorted(roadworks, key=lambda x: x[0])
#print(roadworks)

# Dは入力時点でソート済み
walkers = D[:]
ans = [-1] * Q
skip = [-1] * Q

import bisect
for x, s, t in roadworks:
    left = bisect.bisect_left(walkers, s - x)
    right = bisect.bisect_left(walkers, t - x)
    
    i = left
    while i < right:
        if skip[i] == -1:
            ans[i] = x
            skip[i] = right
            i += 1
        else:
            i = skip[i]

    
#print(walkers)
for a in ans:
    print(a)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

def root(x):
    if pair[x]<0:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:return False
    if pair[x]>pair[y]:
        x,y=y,x
    pair[x]+=pair[y]    
    pair[y]=x
    return True

def size(x):
    return -pair[root(x)]

icase=0
if icase==0:
    n,m,k=map(int,input().split())
    g=[[] for i in range(n)]
    x=[[] for i in range(n)]
    a=[0]*m
    b=[0]*m
    pair=[-1]*n
    for i in range(m):
        ai,bi=map(int,input().split())
        g[ai-1].append(bi-1)
        g[bi-1].append(ai-1)
        a[i]=ai-1
        b[i]=bi-1
        unite(a[i],b[i])
    for i in range(k):
        ci,di=map(int,input().split())
        x[ci-1].append(di-1)
        x[di-1].append(ci-1)

ii=0        
ss=size(ii)-len(g[ii])-len(x[ii])-1
strs=""
for i in range(n):
    ss=size(i)-1
    rooti=root(i)
    for gi in g[i]:
        if root(gi)==rooti:
            ss-=1
    for xi in x[i]:
        if root(xi)==rooti:
            ss-=1
    strs=strs+" "+str(ss)
print(strs[1:])
    


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
#input = sys.stdin.readline
    
n,m,k=map(int,input().split())
pair=[-1]*n

def main():
#    n,m,k=map(int,input().split())
    g=[[] for i in range(n)]
    x=[[] for i in range(n)]
    a=[0]*m
    b=[0]*m
#    pair=[-1]*n
    for i in range(m):
        ai,bi=map(int,input().split())
        g[ai-1].append(bi-1)
        g[bi-1].append(ai-1)
        a[i]=ai-1
        b[i]=bi-1
        unite(a[i],b[i])
    for i in range(k):
        ci,di=map(int,input().split())
        x[ci-1].append(di-1)
        x[di-1].append(ci-1)

#    strs=""
#    sss=[]
    for i in range(n):
        ss=size(i)-1
        rooti=root(i)
        for gi in g[i]:
            if root(gi)==rooti:
                ss-=1
        for xi in x[i]:
            if root(xi)==rooti:
                ss-=1
#        strs=strs+" "+str(ss)
#        sss.append(ss)
        print(ss,end=" ")
    print(" ")
    
def root(x):
    if pair[x]<0:
        return x
    else:
        tmp=root(pair[x])
        pair[x]=tmp
        return tmp

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:return False
    if pair[x]>pair[y]:
        x,y=y,x
    pair[x]+=pair[y]    
    pair[y]=x
    return True

def size(x):
    return -pair[root(x)]


main()
### BUGGY CODE ###

n, m = map(int, input().split())
a = [int(s) for s in input().split()]
# m回だけ最も大きい数字を2で割る
for i in range(m):
    a[a.index(max(a))] //= 2
print(sum(a[i] for i in range(n)))


### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1

heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))

print(-sum(a))
### BUGGY CODE ###

_,a=open(0);*a,=map(int,a.split());t=sum(a)-2*sum(a[1::2]);x=t,
for i in a:t=i*2-t;x+=t,
print(*x[:-1])

### FIXED CODE ###

_,a=open(0)
*a,=map(int,a.split())
t=sum(a)-2*sum(a[1::2])
x=[t]
for i in a:
  t=i*2-t
  x+=t,
print(*x[:-1])
### BUGGY CODE ###

#%%
n = int(input())
a, b, c = [0] * n, [0] * n, [0] * n
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())

q, k = map(int, input().split())
x, y = [0] * q, [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())

l = [[] for _ in range(n+1)]
for i in range(n-1):
    l[a[i]].append((b[i],c[i]))
    l[b[i]].append((a[i],c[i]))

d = [0] * (n+1)
check = [0] * (n+1)
check[k] = 1
que = [k]

while len(que) > 0:
    tmp = que.pop(0)
    for i in l[tmp]:
        if check[i[0]] == 0:
            que.append(i[0])
            check[i[0]] = 1
            d[i[0]] = d[tmp] + i[1]
        else:
            pass

for i in range(q):
    ans = d[x[i]] + d[y[i]]
    print(ans)

### FIXED CODE ###

#%%
n = int(input())
a, b, c = [0] * n, [0] * n, [0] * n
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())

q, k = map(int, input().split())

l = [[] for _ in range(n+1)]
for i in range(n-1):
    l[a[i]].append([b[i],c[i]])
    l[b[i]].append([a[i],c[i]])

d = [0] * (n+1)
check = [0] * (n+1)
check[k] = 1
que = [k]
count = 1

while len(que) > 0:
    tmp = que.pop(0)
    for i in l[tmp]:
        if check[i[0]] == 0:
            que.append(i[0])
            check[i[0]] = 1
            d[i[0]] = d[tmp] + i[1]
            count += 1
        else:
            pass
    if count >= n:
        break

x, y = [0] * q, [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())
    print(d[x[i]] + d[y[i]])
### BUGGY CODE ###

n=input()
m=0
MOD = 10**9 + 7
from itertools import combinations
a=combinations(map(int,input().split()),2)
for i,j in a:
    k=i*j
    m+=k
if m<=MOD:
    print(m)
else:
    v=m%MOD
    print(v)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
MOD = 10 ** 9 + 7

cumsum = [A[0]]
for i in range(1, N):
    cumsum.append(A[i] + cumsum[i - 1])

ans = 0
for i in range(N):
    ans += (A[i] * (cumsum[-1] - cumsum[i])) % MOD
    ans %= MOD

print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())

root = [[pow(10,9)]*n for _ in range(n)]

from collections import deque

root=[0]*n
r=[[]for i in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    r[a].append(b)
    r[b].append(a)

dist =[-1]*n
dist[0] = 0

q = deque([0])
prev=[-1] * n

while q:
    v = q.popleft()

    for j in r[v]:
        if prev[j]!=-1:
            continue
        else:
            # dist[j] = dist[v] + 1
            prev[j] = v
            q.append(j)


for i in range(n):
    if i==0:
        print('Yes')
    else:
        print(prev[i]+1)


### FIXED CODE ###

n,m = map(int,input().split())
from collections import deque
r=[[] for i in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    r[a].append(b)
    r[b].append(a)

# dist =[-1]*n
# dist[0] = 0

q = deque([0])
prev=[-1] * n

while q:
    v = q.popleft()

    for j in r[v]:
        if prev[j]==-1:
            prev[j] = v
            q.append(j)
            # dist[j] = dist[v] + 1
            

for i in range(n):
    if i==0:
        print('Yes')
    else:
        print(prev[i]+1)
### BUGGY CODE ###

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

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])

### FIXED CODE ###

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

if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit()

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])