Harryxun/stf_run huggingface dataset:
from math import log10
from collections import Counter
S = int(input())
l = int(log10(S)) + 1
print(sum(n * (n - 1) // 2 for n in Counter((S := S % 10 ** (l - i)) % 2019 for i in range(l + 1)).values()))


### FIXED CODE ###

from collections import Counter
S = list(reversed(input()))
l = len(S)
N = 0
counts = Counter([(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0])
print(sum(n * (n - 1) // 2 for n in counts.values()))
a,b = int(input().split())
a*=b
if a%2:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a,b = map(int,input().split())
a*=b
if a%2==0:
  print("Even")
else:
  print("Odd")
from collections import deque
n,m = map(int,input().split())
visited = [False for _ in range(n)]
label = [-1 for _ in range(n)]
g = [[] for _ in range(m)]
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

pos = 0
que = deque([])
for nx in g[0]:
    que.append((nx, pos))
while que:
    to, now = que.popleft()
    if visited[to] == True:
        continue
    else:
        visited[to] = True
        label[to] = now
        for nx in g[to]:
            que.append((nx, to))
if -1 in label[1:]:
    print('No')
else:
    print('Yes')
    for l in label[1:]:
        print(l+1)

### FIXED CODE ###

from collections import deque
n,m = map(int,input().split())
visited = [-1 for _ in range(n)]
g = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
pos = 0
que = deque([])
if g[0]:
    visited[0] = 0
    for nx in g[0]:
        que.append((nx, 0))
while que:
    to, now = que.popleft()
    if visited[to] != -1:
        continue
    else:
        visited[to] = now
        for nx in g[to]:
            que.append((nx, to))
visited = visited[1:]
if -1 in visited:
    print('No')
else:
    print('Yes')
    for k in visited:
        print(k+1)
ans = int(input())-int(input())
print(ans if ans>0 else 0)


### FIXED CODE ###

x,t=map(int,input().split())
ans = x - t
print(ans if ans>0 else 0)
n, c = map(int, input().split())
print((n-1)//(c-1))


### FIXED CODE ###

s = input()
n, m  = s.count('+'), s.count('-')
print(n-m)
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()
K=int(input())
A,B=map(int,input().split())
a=0
if i in range(A,B+1):
  if i%k==0:
    a+=1
if a==1:
  print("OK")
else:
  print("NG")

### FIXED CODE ###

k=int(input())
a,b=map(int,input().split())
s=""
for i in range(a,b+1):
  if i%k==0:
    s="OK"
    print(s)
    break
if s!="OK":
  print("NG")
import collections


class unionFind:
    parent = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            return


N, M = map(int, input().split())
G = unionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    G.unite(a, b)

for i in range(N):
    G.root(i)
print(1)
# C = collections.Counter(G.parent).most_common()

# print(C[0][1])


### FIXED CODE ###

import collections
import sys
sys.setrecursionlimit(10**6)
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]


class unionFind:
    parent = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            return


G = unionFind(N)

for a, b in AB:
    G.unite(a, b)

for i in range(N):
    G.root(i)

C = collections.Counter(G.parent).most_common()

print(C[0][1])
S = input()
T = input()

S = list(S)
T = list(T)


def check(S,T):
    len_S = len(S)
    len_T = len(T)

    if len_T - len_S != 1:
        return "No"
    else:
        for i in range(len_S):
            if S[i] != T[i]:
                print(No)
                return "No"

        if i == len_S-1:
            return "Yes"

result = check(S,T)
print(result)


### FIXED CODE ###

S = input()
T = input()


S = list(S)
T = list(T)


def check(S,T):
    len_S = len(S)
    len_T = len(T)

    for i in range(len_S):
        if S[i] != T[i]:
            return "No"

    return "Yes"

result = check(S,T)
print(result)
a=int(input())
b,c=map(int,input().split())
d=0
while d<a:
  e=int(input())
  if e>0: 
    f=b//e+1
  else:
    f=b//e
  c+=f
print(c)
    
  
  
  


  
  


### FIXED CODE ###

a=int(input())
b,c=map(int,input().split())
d=0
while d<a:
  e=((b-1)//int(input()))+1
  c+=e
  d+=1
print(c)
Q = int(input())

mod = 10 ** 6 + 3
table = [1]
for i in range(1, mod):
    table.append(table[-1]*i % mod)

for i in range(Q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, mod))
    else:
        print(pow(d, n, mod) * table[y + n - 1] * pow(table[y - 1], mod - 2, mod) % mod)

### FIXED CODE ###

Q = int(input())

mod = 10 ** 6 + 3
table = [1]
for i in range(1, mod):
    table.append(table[-1]*i % mod)

for i in range(Q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, mod))
    else:
        y = x * pow(d, mod - 2, mod) % mod
        if y + n - 1 >= mod:
            print(0)
        else:
            print(pow(d, n, mod) * table[y + n - 1] * pow(table[y - 1], mod - 2, mod) % mod)
n = int(input())
str = input()
char_list = list(str)
del_num = []

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
ans =0
for i in range(len(char_list)-1):
    if char_list[i] == char_list[i+1]:
        del_num.append(i+1)

print(len(dellist(char_list,del_num)))


### FIXED CODE ###

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

if a-2*b>0:
    print(a-2*b)
else:
    print(0)
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [set(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    if len(p) == 2:
        res = -1
    elif 0 in p:
        res = '20\n' + ' '.join('1' for _ in range(20))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(20-abs(x)-abs(y))]
            res += '\n'+w
    else:
        res = '21\n' + ' '.join('1' for _ in range(21))
        for x,y in Z:
            w = ('R'*x if x > 0 else 'L'*-x) + ('U'*y if y > 0 else 'D'*-y) + ('LR'*10)[:(21-abs(x)-abs(y))]
            res += '\n'+w

    return str(res)

if __name__ == '__main__':
    print(solve())





### FIXED CODE ###

# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = [tuple(map(int, input().split())) for _ in [None]*N]
    p = set(z%2 for z in map(sum,Z))
    if len(p) == 2:
        res = '-1'
    else:
        res = ''
        mode, *_ = p
        mode = 1-mode
        D = [2**i for i in range(30,-1,-1)]
        res += str(31+mode)
        res += '\n' + ' '.join(str(d) for d in D+[1]*mode)
        wdict = {(True, True):('R', (1,0)), (True, False):('U', (0,1)), (False, False):('L',(-1,0)), (False, True):('D',(0,-1))}
        for x, y in Z:
            x -= mode
            W = '\n'
            for d in D:
                w, (a, b) = wdict[x+y>0, x-y>0]
                W += w
                x -= a*d
                y -= b*d
            W += 'R'*mode
            res += W
    return str(res)

if __name__ == '__main__':
    print(solve())
from Math import gcd

K = int(input())

result = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      result += gcd(c, gcd(a, b))
      
print(result)

### FIXED CODE ###

from math import gcd
 
K = int(input())
 
result = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      result += gcd(c, gcd(a, b))
      
print(result)
S=input()
l=len(S)
if l%2==1:
    m=S[l//2]
    c=1
    for i in range l//2:
        if S[l//2-i-1]==m and S[l//2+i+1]==m:
            c+=2
        else:
            break
    ans=c+(l-c)//2
else:
    m1=S[l//2-1]
    m2=S[l//2]
    c=0
    if m1==m2:
        c=2
        for i in range l//2-1:
        if S[l//2-i-2]==m1 and S[l//2+i+1]==m1:
            c+=2
        else:
            break
    ans=c+(l-c)//2
print(ans)

### FIXED CODE ###

S=input()
l=len(S)
if l%2==1:
    m=S[l//2]
    c=1
    for i in range(l//2):
        if S[l//2-i-1]==m and S[l//2+i+1]==m:
            c+=2
        else:
            break
    ans=c+(l-c)//2
else:
    m1=S[l//2-1]
    m2=S[l//2]
    c=0
    if m1==m2:
        c=2
        for i in range(l//2-1):
            if S[l//2-i-2]==m1 and S[l//2+i+1]==m1:
                c+=2
            else:
                break
    ans=c+(l-c)//2
print(ans)
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
lst = [-1] * n
for i in range(n + 1):
    if lst[a[i] - 1] != -1:
        first = lst[a[i] - 1]
        second = i
        break
    lst[a[i] - 1] = i

# print (first, second)    
left = first
right = n - second
# print (left, right)

left_lst = [1] * (left + 1) 
for i in range(1, left + 1):
    left_lst[i] = (left_lst[i - 1] * (left + 1 - i)) // i
# print (left_lst)

right_lst = [1] * (right + 1)
for i in range(1, right + 1):
    right_lst[i] = (right_lst[i - 1] * (right + 1 - i)) // i
# print (right_lst)


def calc(i): #1を含めてトータルi個選ぶ
    if i == 1:
        return 1
    count = 0
    #左側からl個、右側からr個選ぶ
    start = max((i - 1) - right, 0) #左側から最低限選ばないといけない個数
    for l in range(start, left + 1):
        count += left_lst[l] * right_lst[i - 1 - l]
    return count



N = n + 1
tmp = 1
for i in range(1, n + 2):
    tmp = (tmp * (N + 1 - i))//i
    if left + right < i - 1:
        print (tmp % MOD)
        continue
    print ((tmp - calc(i)) % MOD)

### FIXED CODE ###

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
lst = [-1] * n

# O(N)
for i in range(n + 1):
    if lst[a[i] - 1] != -1:
        first = lst[a[i] - 1]
        second = i
        break
    lst[a[i] - 1] = i

# print (first, second)    
left = first
right = n - second

U = 10 ** 5 + 1
def power_mod(a, n):
    if n == 0:
        return 1
    x = power_mod(a//2)

def make_fact(fact, fact_inv):
    for i in range(1, U + 1):
        fact[i] = (fact[i - 1] * i) % MOD
    fact_inv[U] = pow(fact[U], MOD - 2, MOD)
    for i in range(U, 0, -1):
        fact_inv[i - 1] = (fact_inv[i] * i) % MOD

def comb(n, k):
    if k < 0 or n < k:
        return 0
    x = fact[n]
    x *= fact_inv[k]
    x %= MOD
    x *= fact_inv[n - k]
    x %= MOD
    return x

fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
make_fact(fact, fact_inv)

for i in range(1, n + 2):
    ans = comb(n + 1, i) - comb(left + right, i - 1)
    print (ans % MOD)
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(int(m))+" "+str(int(t)))

### FIXED CODE ###

a,b,c= map(int, input().split())
p = list(map(int, input().split()))
k = 0
for i in range(b):
    if p[i] < c:
        k+=1
print(min(k,b-k))
s=input()
print(s[0]+len(s)-2+s[-1])

### FIXED CODE ###

s=input()
print(s[0]+str(len(s)-2)+s[-1])
string = ''
while True:
    string_l = raw_input()
    if string_l:
        string += string_l
    else:
        break
string = string.lower()
a = ord('a')
for i in range(a, a+26):
    print chr(i), ':', string.count(chr(i))

### FIXED CODE ###

string = ''
while True:
    try:
        string += raw_input()
    except EOFError:
        break
string = string.lower()
a = ord('a')
for i in range(a, a+26):
    print chr(i), ':', string.count(chr(i))
def distance(a, b):
    s = 0
    for i in range(len(a)):
        s += (a[i] - b[i]) ** 2

    return s ** 0.5

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

X = []

for i in range(D):
    X.append([int(x) for x in input().split()])

count = 0

for i in range(D):
    for j in range(i+1, D):
        if distance(X[i], X[j]).is_integer():
            count += 1

print(count)

### FIXED CODE ###

def distance(a, b):
    s = 0
    for i in range(len(a)):
        s += (a[i] - b[i]) ** 2

    return s ** 0.5

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

X = []

for i in range(N):
    X.append([int(x) for x in input().split()])

count = 0

for i in range(N):
    for j in range(i+1, N):
        if distance(X[i], X[j]).is_integer():
            count += 1

print(count)
from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*m
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            status = dfs(status, al[i]):
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*m
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            for k in range(m):
                status[k] += al[i][k]
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
else:
    print(ans)
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
ap,an=[],[]
zeronum=0
for i in range(n):
  if a[i]>0:
    ap.append(a[i])
  elif a[i]<0:
    an.append(-a[i])
  else:
    zeronum+=1
np,nn=len(ap),len(an)
def fminus(x):
  j=0
  cnt=0
  for i in range(np):
    cnt*=2
    while j<np and an[j]*ap[i]>=x:
      j+=1
      cnt+=1
  return cnt
def fplus(x,length,lis):
  r=length-1
  cnt=0
  for l in range(length):
    while lis[r]*lis[l]>x:
      if r==l:
        break
      r-=1
    if r==l:
      break
    elif lis[r]*lis[l]<=x:
      cnt+=r-l
  return cnt
if np*nn<k<=np*nn+zeronum*(zeronum-1)//2+zeronum*(np+nn):
  print(0)
else:
  an.sort(reverse=True)
  ap.sort(reverse=True)
  #print(ap)
  #print(an)
  if k<=np*nn:
    ng=10**18
    ok=0
    while ng-ok>1:
      mid=(ok+ng)//2
      if fminus(mid)>=k:
        ok=mid
      else:
        ng=mid
    print(-ok)
  else:
    an.sort()
    ap.sort()
    k-=np*nn+zeronum*(zeronum-1)//2+zeronum*(np+nn)
    #print(k)
    ok=10**18
    ng=0
    #print(ok,ng)
    while ok-ng>1:
      mid=(ok+ng)//2
      if fplus(mid,nn,an)+fplus(mid,np,ap)>=k:
        ok=mid
      else:
        ng=mid
    print(ok)

### FIXED CODE ###

a=list(map(int,input().split()))
if len(set(a))==2:
  print('Yes')
else:
  print('No')
a, b, k = (int(i) for i in input().split())
cdiv = []
ans = []
a,b = min(a,b),max(a,b)
for i in range(1, a + 1):
    if a % i == 0:
        cdiv.append(i)
for i in cdiv:
    if b % i != 0:
        ans.append(i)


print(ans[len(ans) - k])


### FIXED CODE ###

a,b,th = (int(i) for i in input().split())
lst = []
c = max(a,b)
for i in range(c+1,0,-1):
    if a % i == 0 and b % i == 0:
        lst.append(i)
print(lst[th-1])
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)


### FIXED CODE ###

import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
mod = 10**9 + 7
max_a = a.max()
sieve = [True] * (max_a // 2)
prime = [2]
p = 3
while p * p <= max_a:
  if sieve[p // 2 - 1]:
    prime.append(p)
    for i in range(p * p, max_a + 1, 2 * p):
      sieve[i // 2 - 1] = False
  p += 2
prime.extend([i for i in range(p, max_a + 1, 2) if sieve[i // 2 - 1]])
len_prime = len(prime)

pf = np.zeros((n, len_prime), dtype=np.int)
for i in range(n):
  j = 0
  while prime[j] * prime[j] <= a[i]:
    while a[i] % prime[j] == 0:
      a[i] //= prime[j]
      pf[i, j] += 1
    j += 1
  if a[i] > 1:
    pf[i, prime.index(a[i])] += 1
    
b_pf = pf.max(axis=0) - pf
b_sum = 0
for i in range(n):
  b = 1
  for j in range(len_prime):
    b = b * prime[j] ** b_pf[i, j] % mod
  b_sum = (b_sum + b) % mod
print(b_sum)

### FIXED CODE ###

from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

lcm = 1
for i in range(n):
  lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod

sum_b = 0
for i in range(n):
  sum_b = (sum_b + lcm * pow(a[i], mod - 2, mod)) % mod
print(sum_b)
import fractions
n=int(input())
lists=[]
for s in range(n):
    s=int(input())
    lists.append(s)
    
lists.append(1)

glm=lists[0]

cnt=0

while cnt<n:
	gcd=fractions.gcd(glm,lists[cnt+1])
    glm=int(glm*lists[cnt+1]/gcd)
    cnt+=1
    
print(glm)   

### FIXED CODE ###

#早くmathを導入してほしい
from fractions import gcd
n=int(input())
glm=1
for i in range(n):
    nums=int(input())
    glm=int(glm*nums//gcd(nums,glm))
print(glm)
a,b,k = map(int,input().split())
if a+b-k =< 0;
	print(0)
else ;
	print(a+b-k)

### FIXED CODE ###

a,b,k = map(int,input().split())
if a+b-k <= 0:
  print(0,0)
elif a-k <= 0:
  print(0,b+a-k)
else:
  print(a-k,b)
import collections
n = int(input())
li = list(map(int,input().split()))
q = int(input())
num_li=[list(map(int,input().split())) for i in range(q)]

c = collections.Counter(li)

li_sum = sum(li)

for i,j in num_li:
    s = 0
    if i in c:
        cnt = c.pop(i)
        c[j] += cnt
    
    li_sum = li_sum - (i*cnt) + (j*cnt)
    print(li_sum)

### FIXED CODE ###

import collections
n = int(input())
li = list(map(int,input().split()))
q = int(input())
num_li=[list(map(int,input().split())) for i in range(q)]

c = collections.Counter(li)

li_sum = sum(li)

for i,j in num_li:
    s = 0
    if i in c:
        cnt = c.pop(i)
        c[j] += cnt
        li_sum = li_sum - (i*cnt) + (j*cnt)
    print(li_sum)
S = input()
lis = list(S)


for i in range(len(lis)):
    if i % 2 == 0:
        if lis[i] == 'R' or lis[i] == 'U' or lis[i] == 'D':
            flag_o = 1
        else:
            flag_o = 0
            break
    if i % 2 != 0:
        if lis[i] == 'L' or lis[i] == 'U' or lis[i] == 'D':
            flag_e = 1
        else:
            flag_e = 0
            break
        
if flag_o == 1 and flag_e == 1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

S = input()
lis = list(S)
count = 0

for i in range(len(lis)):
    if i % 2 == 0:
        if lis[i] == 'R':
            count += 1
    if i % 2 != 0:
        if lis[i] == 'L':
            count += 1

    if lis[i] == 'U' or lis[i] == 'D':
        count += 1

if count == len(lis):
    print('Yes')
else:
    print('No')
a,b,c=(int(x) for x in input().split())

if (a+b+c>=22:
    print('bust')
else:
    print('win')



### FIXED CODE ###

a,b,c=(int(x) for x in input().split())

if (a+b+c)>=22:
    print('bust')
else:
    print('win')
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
A = list(map(int, input().split()))

recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6]
strategy = []

for i in A:
	strategy.append((recipe[i - 1], -i))
	
strategy.sort()
l = []

def dfs(cost):
	if cost > N:
		return False
	elif cost == N:
		return True
		
	for j in range(M):
		res = dfs(cost + strategy[j][0])
		if res:
			l.append(-strategy[j][1])
			return True

	return False
	
dfs(0)
l.sort(reverse=True)
c = map(str, l)
print(''.join(c))

### FIXED CODE ###

import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
A = list(map(int, input().split()))

recipe = [2, 5, 5, 4, 5, 6, 3, 7, 6]
available =[]
dp = [-1] * (N + 1)

for i in range(M):
	available.append((A[i], recipe[A[i] - 1]))
	
available.sort(reverse = True)
dp[0] = 0

for i in range(1, N + 1):
	for j in range(M):
		k = i - available[j][1]
		if k >= 0 and dp[k] >= 0:
			if dp[k] + 1 > dp[i]:
				dp[i] = dp[k] + 1

cost = 0
ans = ''

for i in range(dp[N]):
	for j in range(M):
		if N - cost - available[j][1] >= 0 and dp[N - cost - available[j][1]] == dp[N - cost] - 1:
			cost += available[j][1]
			ans += str(available[j][0])
			break
	
print(ans)
x = int(input())

ng = np.array([2,4,5,6,8])

import numpy as np

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(x)

if len(set(a) & set(ng))>0:
    print(-1)
elif len(set(a))== 1 and len(str(x))>3:
    nana = "7"*(x)
    while True:
        nana = nana[:len(nana)-1]
        if int(nana)%x ==0:
            break
    print(len(nana))
else:
    nana = "7"*(len(str(x)))
    while True:
        nana += "7"
        if int(nana)%x ==0:
            break
    print(len(nana))

### FIXED CODE ###

k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)
n = import math
m = math.sqrt(n)
print(math.floor(m))

### FIXED CODE ###

import math
n = int(input())
m = math.sqrt(n)
x = int(math.floor(m))
print(x**2)
N = int(input())
W = map(int, input().split())

l = [0] * N
r = [0] * N

for i in range(N):
  if i == 0:
    r[i] = W[0]
    l[i] = W[N-1]
  else:
    r[i] = r[i-1] + W[i]
    l[i] = l[i-1] + W[N-i-1]

ans = 100000
for i in range(N):
  ans = min([abs(r[i] - l[N-i-1]), ans])
print(ans)

### FIXED CODE ###

N = int(input())
W = list(map(int, input().split()))
 
l = [0] * N
r = [0] * N
 
for i in range(N):
  if i == 0:
    r[i] = W[0]
    l[i] = W[N-1]
  else:
    r[i] = r[i-1] + W[i]
    l[i] = l[i-1] + W[N-i-1]
 
ans = 100000
for i in range(N-1):
  ans = min([abs(r[i] - l[N-i-2]), ans])
print(ans)
N, A, B = map(int(input().split()))
sum = 0
for num in range(N + 1):
    if A <= sum([int(x) for x in str(num)]) <= B:
        sum += 1
print(sum)

### FIXED CODE ###

N, A, B = map(int, input().split())
res = 0
for num in range(N + 1):
    if A <= sum([int(x) for x in str(num)]) <= B:
        res += num
print(res)
a = list(map(int,input()))

if a[0]%a[1]==0:
  print(0)
else:
  print(1)

### FIXED CODE ###

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

if a[0]%a[1]==0:
  print(0)
else:
  print(1)