Harryxun/stf_run huggingface dataset:
from math import pi


def solve():
    x1, y1, x2, y2 = map(int, input().split())
    if x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    is_down = y1 > y2
    if is_down:
        y1, y2 = -y1, -y2

    n = int(input())
    fountains = []
    for _ in range(n):
        x, y = map(int, input().split())
        if is_down:
            y = -y
        if x < x1 or x2 < x or y < y1 or y2 < y:
            continue
        fountains.append((y, x))
    fountains.sort()

    if x1 == x2:
        base = (y2 - y1) * 100
        for y, x in fountains:
            if x == x1:
                if y1 < y < y2:
                    return base + 10 * pi - 20
                else:
                    break
        return base
    if y1 == y2:
        base = (x2 - x1) * 100
        for y, x in fountains:
            if y == y1:
                if x1 < x < x2:
                    return base + 10 * pi - 20
                else:
                    break
        return base

    uncmp_x = sorted({x1, x2}.union(f[1] for f in fountains))
    uncmp_y = sorted({y1, y2}.union(f[0] for f in fountains))
    cmp_x = {x: i for i, x in enumerate(uncmp_x)}
    cmp_y = {y: i for i, y in enumerate(uncmp_y)}
    fountains = [(cmp_y[y], cmp_x[x]) for y, x in fountains]

    dp = [0] * len(uncmp_x)
    for y, x in fountains:
        cdp = dp.copy()
        for cx, cnt in enumerate(dp[:x]):
            cdp[cx] = max(dp[cx], cnt + 1)
        cdp[cx] = max(dp[cx], 1)
        dp = cdp

    mc = max(dp)
    return (x2 - x1 + y2 - y1) * 100 - mc * 20 + mc * 5 * pi


print(solve())


### FIXED CODE ###

import operator
from bisect import bisect_left
from math import pi
import decimal


def lis(A):
    L = [A[0]]
    for a in A[1:]:
        if a > L[-1]:
            L.append(a)
        else:
            L[bisect_left(L, a)] = a
    return len(L)


def solve():
    x1, y1, x2, y2 = map(int, input().split())
    if x1 > x2:
        x1, y1, x2, y2 = x2, y2, x1, y1
    is_down = y1 > y2
    if is_down:
        y1, y2 = -y1, -y2
    base = decimal.Decimal(100) * (x2 - x1 + y2 - y1)

    n = int(input())
    fountains = []
    for _ in range(n):
        x, y = map(int, input().split())
        if is_down:
            y = -y
        if x < x1 or x2 < x or y < y1 or y2 < y:
            continue
        fountains.append((x, y))

    if not fountains:
        return str(base)

    dpi = decimal.Decimal(pi)

    fountains.sort()
    fountains_y = list(map(operator.itemgetter(1), fountains))
    mc = lis(fountains_y)
    if mc == min(x2 - x1, y2 - y1) + 1:
        dist = base + (dpi * 5 - 20) * (mc - 1) + dpi * 10 - 20
    else:
        dist = base + (dpi * 5 - 20) * mc
    return str(dist)


print(solve())
n, m, x, y = map(int, input().split())
areaX = list(map(int, input().split()))
areaY = list(map(int, input().split()))

areaX.append(x)
areaY.append(y)

if maxX < minY:
    print("No War")
else:
    print("War")


### FIXED CODE ###

n, m, x, y = map(int, input().split())
areaX = list(map(int, input().split()))
areaY = list(map(int, input().split()))

areaX.append(x)
areaY.append(y)

if max(areaX) < min(areaY):
    print("No War")
else:
    print("War")
s = int(input())
print(0,0,10**9,1,s%(10**9),s//(10**9)

### FIXED CODE ###

s = int(input())
print(0,0,10**9,1,10**9-(s-1)%(10**9)-1,(s-1)//(10**9)+1)
n,m=map(int,input().split())
def gcd(x, y):
    if x>y:
        if y==0:
            return x
        return gcd(y,x%y)
    else:
        if x==0:
            return y
        return gcd(x,y%_)
if (n%m==0):
    print(0)
else:
    print(gcd(n,m)) 

### FIXED CODE ###

x,y=map(int,input().split())

if x>=y:
    x=x%y
a=y-x
b=x

print(min(a,b))
a,b,c = [int(i) for i in input().split()]
i=0
for i in list(range(a,b+1,1):
    if c % i == 0:
        i = i+1
    else:
        
print(i)


### FIXED CODE ###

a,b,c = [int(i) for i in input().split()]
i=0
for num in range(a,b+1,1):
    if c % num == 0:
        i = i+1
    else:
        pass
print(i)
N, M = map(int, input().split())

AB = []

for _ in range(M):
    A_i, B_i = map(int, input().split())
    AB.append([A_i, B_i])
    
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)] # 親なら -1 * サイズ
        
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    def size(self, x):
        x = self.root(x)
        return -1 * self.parent[x]
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        x_size = self.parent[x]
        y_size = self.parent[y]
        if x_size < y_size:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True
        
max_inconvenience = N * (N - 1) // 2 
ans = [max_inconvenience]
uf = UnionFind(N)
for bridge in reversed(AB):
    x = uf.root(bridge[0] - 1)
    y = uf.root(bridge[1] - 1)

    if x != y:
        x_size = uf.size(x)
        y_size = uf.size(y)
        ans_tmp = max_inconvenience - x_size * y_size
        max_inconvenience = ans_tmp
        uf.union(x, y)
    else:
        ans_tmp = max_inconvenience
    ans.append(ans_tmp)
    
for a in reversed(ans[:-1]):
    print(a)

### FIXED CODE ###

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

AB = []

for _ in range(M):
    A_i, B_i = map(int, input().split())
    AB.append([A_i, B_i])

class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)] # 親なら -1 * サイズ
        
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    def size(self, x):
        x = self.root(x)
        return -1 * self.parent[x]
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        x_size = self.size(x)
        y_size = self.size(y)
        if x_size < y_size:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True
        
max_inconvenience = N * (N - 1) // 2 
ans = [max_inconvenience]
uf = UnionFind(N)
for bridge in reversed(AB):
    x = uf.root(bridge[0] - 1)
    y = uf.root(bridge[1] - 1)

    if x != y:
        x_size = uf.size(x)
        y_size = uf.size(y)
        ans_tmp = max_inconvenience - x_size * y_size
        max_inconvenience = ans_tmp
        uf.union(x, y)
    else:
        ans_tmp = max_inconvenience
    ans.append(ans_tmp)
    
for a in reversed(ans[:-1]):
    print(a)
n = int(input())
x = input().split(' ')

p = 0
ans = []
while p <= int(x[n-1]):
  e = 0
  for i in range(n):
    e += (int(x[i])-p)**2
  ans.append(e)
  p+=1
print(min(ans))

### FIXED CODE ###

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

if n >= 10:
  print(r)
else:
  print(r+ 100*(10 - n))
W, H, x, y = map(int, input().split())
print(W*H//2, 1 int(x == y == W/2))


### FIXED CODE ###

W, H, x, y = map(int, input().split())
print(W*H/2, int(2*x == W and 2*y == H))
s,w = map(int,input().split())

if s >= w:
  print(safe)
else:
  print(unsafe)

### FIXED CODE ###

s,w = map(int,input().split())
 
if s > w:
  print("safe")
else:
  print("unsafe")
import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**5:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**5:
        return
    if len(A)==0:
        for i in range(1, 10, 1):
            A.append(str(i))
            dfs(A)
            A.pop()
        return

    for i in range(0, 10, 1):
        if abs(int(A[-1])-i)<=1:
            A.append(str(i))
            dfs(A)
            A.pop()
    return
dfs([])
ans_list.sort()
print(ans_list[K-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []

def dfs(l):
    if len(l)==1 and l[0]!="0":
        ans_list.append(int("".join(l)))
    if l!=[] and l[0]=="0":
        return
    if l!=[] and int("".join(l))>3234566667:
        return
    for i in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        l.append(i)
        #ここで絶対値1以下になるものだけdfs
        if len(l)==1:
            dfs(l)
            l.pop()
        elif abs(int(l[len(l)-2])-int(l[len(l)-1]))<=1:
            dfs(l)
            ans_list.append(int("".join(l)))
            l.pop()
        else:
            l.pop()

    return

dfs([])
ans_list.sort()
print(ans_list[K-1])
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    ok = []
    for i in range(n):
        x, y = graph[i]
        bl = (comb[:, i] ^ 1) | np.all(comb[:, x-1] == y, axis=1)
        ok.append(bl)
    ok = np.all(ok, axis=0)
    print(np.amax(comb[ok].sum(axis=1)))

if __name__ ==  '__main__':
    main()


### FIXED CODE ###

import sys
# import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for j in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x-1, y))

# xy = np.array(xy)
# x, y = xy[:, :].T
# x = x.T 
# y = y.T

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        ok = True
        for i in range(n):
            if not comb >> i & 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    ok = False
                    break
            if ok:
                cnt += 1
            else:
                break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)
n=int(input())
s=int(input())
a="-1"
def f(b,n):
    if n<b:
        return n
    else:
        return f(b,n//b)+n%b
if n==s:
    a=n+1
i=2
while 0<=i<=n**(1/2):
    if f(i,n)==s:
        a=i
        break
    i+=1
if a=="-1":
    for p in range(1,int(n**(1/2))):
        b=(n-s)/p+1
        if f(b,n)==s:
            a=b
            break
print(int(a))

### FIXED CODE ###

n=int(input())
s=int(input())
ans="-1"
def f(b,n):
    if n<b:
        return n
    else:
        return f(b,n//b)+n%b
if n==s:
    ans=n+1
for b in range(2,int(n**(1/2)+1)):
    if f(b,n)==s:
        ans=b
        break
if ans=="-1":
    for p in range(int(n**(1/2)+1),0,-1):
        b=int((n-s)/p)+1
        if b>=2:
            if f(b,n)==s:
                ans=b
                break
print(ans)
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(n + 1)] for i in range(m + 1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
  
print((dp[n][m]+1)%mod)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
s = na()
t = na()
mod = 10**9+7

dp = [[0 for i in range(m + 1)] for j in range(n + 1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if (s[i-1] == t[j-1]):
            dp[i][j] = (1 + dp[i][j-1] + dp[i-1][j])%mod
        else:
            dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1])%mod
  
print((dp[n][m]+1)%mod)
A = int(input())
B = int(input())

result = A + B
if A - B > result:
  result = A - B
if A * B > result:
  result = A * B
print(result)

### FIXED CODE ###

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

print(max([A+B, A-B, A*B]))
#!/usr/bin/env python3
N, *a = map(int, open(0))
n = N//2 - 1
a.sort()
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - [0, min(a[n]+a[n+2], 2*a[n+1])][N%2])

### FIXED CODE ###

#!/usr/bin/env python3
N, *a = map(int, open(0))
n = N//2 - 1
a.sort()
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - (min(a[n]+a[n+2], 2*a[n+1]) if N%2 else 0))
def method(input()):
    l = input().split(' ')
    square = int.l[0] * int.l[1]
    length = 2 * int.l[0] + 2* int.l[1]
    print(square length)

method(input(3 5))


### FIXED CODE ###

string = input()
a,b = map(int,string.split(' '))
print(a*b, 2*(a+b))
from itertools import permutations
from copy import deepcopy
from collections import Counter

n,a,b,c = map(int,input().split())
take = []
for _ in range(n):
	take.append(int(input()))
tmp = deepcopy(take)
ans_list = []

for abc in permutations([a,b,c],3):
	take = deepcopy(tmp)
	sum_take = sum(take)
	ans = 0
	l = []
	l2 = []
	s = Counter(take)
	#print(s)
	for x in abc:
		res = []
		l2 = []
		take = []
		for i,num in s.items():
			for j in range(num):
				take.append(i)
		#take = list(s)
		for i in range(2**n):
			l = []
			for j in range(len(take)):
					if i & (1<<j):
						l.append(take[j])
			if len(l) == 0:
				continue
			res.append(10*(len(l)-1) + abs(sum(l) - x))
			l2.append(l)
		minimum = sum_take
		for i in range(len(res)):
			if minimum > res[i]:
				minimum = res[i]
				s2 = l2[i]
		for i in range(len(s2)):
			s[s2[i]] -= 1
			if s[s2[i]] == 0:
				s.pop(s2[i])
		#s = s - s2
		ans += minimum
		#print(res,s,minimum)
	ans_list.append(ans)

print(min(ans_list))


### FIXED CODE ###

from itertools import permutations
from copy import deepcopy
from collections import Counter

n,a,b,c = map(int,input().split())
take = []
for _ in range(n):
	take.append(int(input()))
tmp = deepcopy(take)
ans_list = []

sum_abc = 10 ** 5
for abc in permutations([a,b,c],3):
	take = deepcopy(tmp)
	ans = 0
	l = []
	l2 = []
	s = Counter(take)
	#print(s)
	for x in abc:
		res = []
		l2 = []
		take = []
		for i,num in s.items():
			for j in range(num):
				take.append(i)
		#take = list(s)
		for i in range(2**n):
			l = []
			for j in range(len(take)):
					if i & (1<<j):
						l.append(take[j])
			if len(l) == 0:
				continue
			res.append(10*(len(l)-1) + abs(sum(l) - x))
			l2.append(l)
		minimum = sum_abc
		for i in range(len(res)):
			if minimum > res[i]:
				minimum = res[i]
				s2 = l2[i]
		for i in range(len(s2)):
			s[s2[i]] -= 1
			if s[s2[i]] == 0:
				s.pop(s2[i])
		#s = s - s2
		ans += minimum
		#print(res,s,minimum)
	ans_list.append(ans)

print(min(ans_list))
S = input()
if S == 'abc':
    return Yes
elif S == 'acb':
    return Yes
elif S == 'acb':
    return Yes
elif S == 'bac':
    return Yes
elif S == 'bca':
    return Yes
elif S == 'cab':
    return Yes
elif S == 'cba':
    return Yes
else:
    return NO

### FIXED CODE ###

S = input()
if S == 'abc':
    print('Yes')
elif S == 'acb':
    print('Yes')
elif S == 'acb':
    print('Yes')
elif S == 'bac':
    print('Yes')
elif S == 'bca':
    print('Yes')
elif S == 'cab':
    print('Yes')
elif S == 'cba':
    print('Yes')
else:
    print('No')
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n):
  if p[i]==i+1:
    ans=ans+1
    if p!=n-1:
      if p[i+1]==i+2:
        ans=ans-1
print(ans)

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))
ans=0
i=0
while i<n:
  if p[i]==i+1:
    ans=ans+1
    i=i+1
  i=i+1
print(ans)
total=s=i=0
try:
 while True:
  a,b = map(int,input().split(','))
  total += a*b
  s+=b
  i+=1
except:
 print(total)
 print(round(s/i+0.5 ))

### FIXED CODE ###

while True:
 try:
   a,b,c=map(float,input().split(','))
   bmi=b/c**2
   if bmi>=25:
     print(int(a))
 except:
  break
A, B = map(int, input().split())
if A + b >= 10:
    print("error")
else:
    print(A+B)

### FIXED CODE ###

A, B = map(int, input().split())
print(A+B if A+B < 10 else 'error')
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [0] * (2 * 10 ** 5 + 1)
M = max(A)

for a in A:
	B[a] += 1

if max(B) == N:
	print(0)
else:
	for a in A:
		if B[a] > 0:
			i = 2
			b = a * i
			while b <= M:
				B[b] = 0
				i += 1
				b = a * i

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
M = max(A)
B = [0] * (M + 1)

for a in A:
    B[a] += 1

for a in A:
    if B[a] > 0:
        i = 2
        b = a * i
        while b <= M:
            B[b] = 0
            i += 1
            b = a * i
for i in range(M + 1):
    if B[i] > 1:
        B[i] = 0
print(sum(B))
tmp = input().split(" ")

HP = int(tmp[0])
attack = int(tmp[1])

print(math.ceil(HP/attack))

### FIXED CODE ###

import math
tmp = input().split(" ")
 
HP = int(tmp[0])
attack = int(tmp[1])
 
print(math.ceil(HP/attack))
s1, s2, s3 = input().split(" ")

print(s1[0].upper()+s2[0].upper()s3[0].upper())

### FIXED CODE ###

s1, s2, s3 = input().split(" ")
    
print(s1[0].upper()+s2[0].upper()+s3[0].upper())
S,T=map(int,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
  A=A-1
else:
  B=B-1
print('{} {}'.format(A,B))


### FIXED CODE ###

S,T=input().split()
A,B=map(int,input().split())
U=input()
if U==S:
  A=A-1
else:
  B=B-1
print('{} {}'.format(A,B))
X=int(input())
Y=int(input())

if Y%2==0 and Y-2*X>=0 and 4*X-Y>=0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

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

if Y%2==0 and Y-2*X>=0 and 4*X-Y>=0:
  print("Yes")
else:
  print("No")
n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = sum(ac)
no_wa = sum(wa)

print('{} {}'.format(no_acc, no_wa))

### FIXED CODE ###

n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = 0
no_wa = 0

for i in range(n):
    if ac[i] == 1:
        no_ac += 1
        no_wa += wa[i]

print(str(no_ac) + ' ' + str(no_wa))
n=int(input())
p=list(map(int,input().split(())))
count=0
for i in range(n);
    if p[i] != i+1:
        count+=1
if count==0 or count==2:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

N = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(N):
  if p[i] != i + 1:
    count += 1
    
if count <= 2:
  print('YES')
else:
  print('NO')
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
d={}
w=[]
q=[]
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
        w.append(i)
for i in w: heapq.heappush(q, i)
for i in range(m):
    b,c=map(int,input().split())
    while b:
        if c>q[0]:
            x=min(b,d[q[0]])
            if c in d:
                d[c]+=x
                b-=x
                d[q[0]]-=x
                if d[q[0]]==0:
                    heapq.heappop(q)
            else:
                d[c]=x
                b-=x
                d[q[0]]-=x
                heapq.heappush(q,c)
                if d[q[0]]==0:
                    heapq.heappop(q)
        else:
            break
ans=chk=0
for i in d:
    ans+=i*d[i]
print(ans)

### FIXED CODE ###

import heapq
def sol():
    n,m=map(int,input().split())
    a=[int(i) for i in input().split()]
    d={}
    w=[]
    q=[]
    for i in a:
        if i in d:
            d[i]+=1
        else:
            d[i]=1
            w.append(i)
    for i in w: heapq.heappush(q, i)
    for i in range(m):
        b,c=map(int,input().split())
        while b:
            if c>q[0]:
                x=min(b,d[q[0]])
                if c in d:
                    d[c]+=x
                    b-=x
                    d[q[0]]-=x
                    if d[q[0]]==0:
                        heapq.heappop(q)
                else:
                    d[c]=x
                    b-=x
                    d[q[0]]-=x
                    heapq.heappush(q,c)
                    if d[q[0]]==0:
                        heapq.heappop(q)
            else:
                break
    ans=chk=0
    for i in d:
        ans+=i*d[i]
    print(ans)

if __name__=="__main__":
    sol()
##Prime Numbers
##16D8101008G Kojima Masayoshi 小嶋真義　2018.4.18

import numpy as np
import math
n=int(input())
A=np.empty((n))
B=np.zeros((n))
count=0

##print(B)検査

for i in range(n):
    A[i]=int(input())


for i in range(n):
    if A[i]==1:
        B[i]=1
    elif A[i]==2:
        B[i]=0
    elif A[i]==5:
        B[i]=0
    elif A[i]%2==0 :
        B[i]=1
    elif A[i]%5==0:
        B[i]=1
    else:
        for j in range(2,int(math.sqrt(A[i]))):
            if A[i]%j==0:
                B[i]=1 ##素数でないなら1を入力
                break

##print(B)

for i in range(n):
    if B[i]==0:
        count=count+1

print(count)



### FIXED CODE ###

from math import sqrt

n=int(input())

count=0

for i in range(n):
    x=int(input())
    if x==1:
        count=count+1
    elif x!=2 and x%2==0:
        count=count+1
    elif x==2 or x==3 or x==5:
        count=count
    else:
        for j in range(2,int(sqrt(x))+1): 
            if x%j==0:
                count=count+1
                break


print(n-count)
N=int(Input())
if N%2=0:
    print(N/2)
else:
    print((N-1)/2)

### FIXED CODE ###

N=int(input())

if N%2==0:
    print(N//2)

else:
    print((N+1)//2)
"""
Match Matching
提出 #4299735 を参考に作成
"""


def solve():
    # 初期値の設定
    num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    # 丁度n本で作成できる最大桁数を格納する.
    # 初期値は -inf (丁度使い切ることは不可能) としておく
    dp = [-1 * float("inf")] * (N + 1)

    # 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する
    for n in range(1, N + 1):
        for a in A:
            if n - num[a] >= 0:
                # マッチがnum[a]本あるときにaが作れるなら,
                # n - num[a]本の時よりも1桁多く作れるはず.
                # これをすべてのAに対して行い、その中で最大となった桁数を求める.
                dp[n] = max(dp[n], dp[n - num[a]] + 1)
    # print('各本数丁度で作れる最大桁数')
    # print(dp)

    # 回答となる数値を算出
    ans = ''
    for i in range(dp[N]):  # dp[N]桁の数を上位の桁から決定していく
        for a in A:
            # num[a]本使って数を作ったとき,
            # N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合,
            # numを作っても最終的に作れる数の桁数は変わらない.
            # そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り,
            # 作成する数の上位桁に使用すればよい.
            # 同じ本数のマッチを使用する場合はより大きい数を採用する.
            # そのためAはあらかじめ降順にソートしておく.
            # 最初の条件で配列外アクセスを防ぐ
            if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]:
                ans += str(a)
                N -= num[a]
                break
        # print('現在の残本数', N, '採用された数', a)

    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

"""
Match Matching
提出 #4299735 を参考に作成
"""


def solve():
    # 初期値の設定
    num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    # 丁度n本で作成できる最大桁数を格納する.
    # 初期値は -inf (丁度使い切ることは不可能) としておく
    dp = [-1 * float("inf")] * (N + 1)

    # 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する
    dp[0] = 0
    for n in range(1, N + 1):
        for a in A:
            if n - num[a] >= 0:
                # マッチがnum[a]本あるときにaが作れるなら,
                # n - num[a]本の時よりも1桁多く作れるはず.
                # これをすべてのAに対して行い、その中で最大となった桁数を求める.
                dp[n] = max(dp[n], dp[n - num[a]] + 1)
    # print('各本数丁度で作れる最大桁数')
    # print(dp)

    # 回答となる数値を算出
    ans = ''
    for i in range(dp[N]):  # dp[N]桁の数を上位の桁から決定していく
        for a in A:
            # num[a]本使って数を作ったとき,
            # N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合,
            # numを作っても最終的に作れる数の桁数は変わらない.
            # そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り,
            # 作成する数の上位桁に使用すればよい.
            # 同じ本数のマッチを使用する場合はより大きい数を採用する.
            # そのためAはあらかじめ降順にソートしておく.
            # 最初の条件で配列外アクセスを防ぐ
            if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]:
                ans += str(a)
                N -= num[a]
                break
        # print('現在の残本数', N, '採用された数', a)

    print(ans)


if __name__ == '__main__':
    solve()