Harryxun/stf_run huggingface dataset:
a,b = map(int,input().split())
if a%3==0 or b%==0 or(a+b)%3==0:
  print("Possible")
else:
  print("Impossible")

### FIXED CODE ###

a,b=map(int,input().split())
if a*b*(a+b)%3==0:
  print("Possible")
else:
  print("Impossible")
n, k = map(int, input().split())
x = list(map(int, input().split()))


def check(now, k, t, logs, ans):
    if now in logs:
        return ans
    logs.append(now)
    if k == 0:
        return min(ans, t)
    if len(x) > now + 1:
        ans = min(ans, check(now + 1, k - 1, t +
                             abs(x[now + 1] - x[now]), logs[::], ans))
    if now - 1 >= 0:
        ans = min(ans, check(now - 1, k - 1, t +
                             abs(x[now - 1] - x[now]), logs[::], ans))
    return ans


def main():
    ans = abs(sum(x))
    for i, v in enumerate(x):
        ans = min(ans, check(i, k - 1, abs(v), [], ans))
    print(ans)


main()


### FIXED CODE ###

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

    i = 0
    ans = 10 ** 8 * n
    while i < n - k + 1:
        lr = abs(x[i]) + abs(x[i] - x[i + k - 1])
        rl = abs(x[i + k - 1]) + abs(x[i] - x[i + k - 1])
        i += 1
        ans = min(ans, lr, rl)
    print(ans)


main()
N,M=map(int,input().split())
a=[int(input()) for i in range(N)]
a=sorted(a) reversed=True
if sum(a)/(4*M)<=a[M-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N,M=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a, reverse=True)
if sum(a)/(4*M)<=a[M-1]:
  print("Yes")
else:
  print("No")
a,b,k=map(int,input().split())
arr=list(range(a,b+1))
for i in range(b-a+1):
  if i <= k or len(arr)-i >= k:
    print(arr[i])

### FIXED CODE ###

a,b,k=map(int,input().split())
if 2*k >= b-a+1:
  print(*list(range(a,b+1)),sep='\n')
else:
  print(*list(range(a,a+k)),sep='\n')
  print(*list(range(b-k+1,b+1)),sep='\n')
#ACB-136-B1

N = int(input())

str_N= str(N)

for i in range(1,N+1):
	if len(str(i)) % 2 ==1:
		ans +=1
print(ans)

### FIXED CODE ###

#ACB-136-B1

N = int(input())

str_N= str(N)
ans = 0
for i in range(1,N+1):
	if len(str(i)) % 2 ==1:
		ans +=1
print(ans)
from sys import stdin,exit
import collections

input = stdin.readline

Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
    cx[x] += 1
    cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
    for y in candidateY:
        if (y,x) not in bomb:
            print(res + 1)
            exit(1)

print(res)

### FIXED CODE ###

from sys import stdin
import collections

input = stdin.readline

Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
    cx[x] += 1
    cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
    for y in candidateY:
        if (y,x) not in bomb:
            res += 1
            break
    else:
        continue
    break
print(res)
n = int(input())
li = [list(map(int,list(input().split()))) for i in range(n)]

for i in range(len(li)):
    if li[i][0] >= li[i][1] + li[i][2]:
        if (li[i][0] - (li[i][1] + li[i][2]))%2 == 0:
        flag = True
    else:
        flag = False
        break
if flag == True:
    print("Yes")
elif flag == False:
    print("No")

### FIXED CODE ###

n = int(input())
t,x,y = 0,0,0

for i in range(n):
    T,X,Y = map(int,input().split())
    dt,dx,dy = T-t,abs(X-x),abs(Y-y)
    if dt - (dx + dy) < 0 or (dt - (dx + dy))%2 == 1:
        print("No")
        exit()
    t,x,y = T,X,Y

print("Yes")
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [i for i in a if i > 0], [j for j in a if j < 0]

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
        p = []
        p_append = p.append
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p_append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p_append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
    print(ans % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [], []
    for i in range(n):
        if a[i] < 0:
            t.append(a[i])
        else:
            s.append(a[i])
    # s, t = [i for i in a if i > 0], [j for j in a if j < 0]

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
            ans %= mod
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
            ans %= mod
        p = []
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p.append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p.append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
            ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

u = [-1] * (n + 1)

def find(v):
    if u[v] < 0:
        return v
    else:
        return find(u[v])

total = n * (n - 1) // 2
ans = [total]

for a, b in reversed(ab):
    af = find(a)
    bf = find(b)
    if af != bf:
        total -= u[af] * u[bf]
        u[af] += u[bf]
        u[bf] = af
    ans.append(total)

for a in reversed(ans[:-1]):
  print(a)

### FIXED CODE ###

n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

u = [-1] * (n + 1)

def find(v):
    if u[v] < 0:
        return v
    else:
        return find(u[v])

total = n * (n - 1) // 2
ans = [total]

for a, b in reversed(ab[1:]):
    af = find(a)
    bf = find(b)
    af, bf =sorted([af, bf])
    if af != bf:
        total -= u[af] * u[bf]
        u[af] += u[bf]
        u[bf] = af
    ans.append(total)

for a in reversed(ans):
    print(a)
import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



H, W, N = acinput()

initp= np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction,cs,flg,seq1,seq2):

    N=len(seq1)
    for i in range(len(seq1)):
        s1=seq1[i]
        s2=seq2[i]
        if s1==direction:
            cs += flg
            
        if cs<=0 or cs>N:
            return False
        if s2!=direction:
            cs-=flg
        
        if cs < 0 or cs > N:
            return False
            
    return cs




sr=position_relative("R",initp[0],S,T)
sl = position_relative("L",initp[0],S,T)

su = position_relative("U",initp[1],S, T)
sd = position_relative("D", initp[1], S, T)

#print(sr,sl,su,sd)

if sr or sl or su or sd:
    print("YES")
else:
    print("NO")



### FIXED CODE ###


import numpy as np
from functools import *

import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


H, W, NN = acinput()

initp = np.array(acinput())

S = list(input())[:-1]
T = list(input())[:-1]
#S = list(input().split(""))
#T = list(input().split(""))


def position_relative(direction, direction_op, cs, flg, seq1, seq2, N):
    global H, W
    # N=len(seq1)
    for i in range(len(seq1)):
        s1 = seq1[i]
        s2 = seq2[i]

        #print(cs,flg)
        if s1 == direction:
            cs += flg

        if flg > 0:
            if cs > N:
                return False

        else:
            if cs <= 0:
                return False
            # elif cs>N:
            #    cs=N
        #print(cs)
        if s2 == direction_op:
            #print("op",N)
            cs -= flg
    
    
        if cs > N:
           cs = N
        
        if cs <= 0:
            cs = 1

    return cs


sr = position_relative("R", "L", initp[1], 1, S, T, W)
sl = position_relative("L", "R", initp[1], -1, S, T, W)
su = position_relative("U", "D", initp[0], -1, S, T, H)
sd = position_relative("D", "U", initp[0], 1, S, T, H)

#print(sr, sl, su, sd)

# su=0
# if sr or sl or su or sd:
if sr*sl*su*sd == 0:
    print("NO")
else:
    print("YES")
from fractions import gcd

class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

mod = 998244353
n,a,b,k = map(int, input().split())
if k % gcd(a,b) != 0:
    print(0)
    exit()
hoge = PERM_COMB_MOD(n=n+10, mod=mod)
ans = 0
for i in range(n+1):
    tmp = k-a*i
    if tmp % b:
        continue
    j = tmp//b
    if j < 0 or n < j:
        continue
    ans += hoge.comb(n, i)*hoge.comb(n, j)
    ans %= mod
print(ans)

### FIXED CODE ###

from fractions import gcd

class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

mod = 998244353
hoge = PERM_COMB_MOD(mod=mod)
n,a,b,k = map(int, input().split())
if k % gcd(a,b) != 0:
    print(0)
    exit()
ans = 0
for i in range(n+1):
    tmp = k-a*i
    if tmp % b:
        continue
    j = tmp//b
    if j < 0 or n < j:
        continue
    ans += hoge.comb(n, i)*hoge.comb(n, j)
    ans %= mod
print(ans)
import math
A,B = map(int,input().split())
gcd = math.gcd(A,B)
ans = (A*B)//gcd
print(ans)

### FIXED CODE ###

import fractions
A,B = map(int,input().split())
gcd = fractions.gcd(A,B)
ans = (A*B)//gcd
print(ans)
a=print()
b=print()
c=print()
d=print()
e=print()
k=print()

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>=k:
  print('Yay!')
else:
  print(':(')

### FIXED CODE ###

a=[int(input()) for i in range(5)]
k=int(input())
x=max(a)-min(a)
if x<=k:
  print('Yay!')
else:
  print(':(')
l = int(input())

for p in range(19, 0, -1):
    if 2**p < l:
        n = p+1
        break

p = n-1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**i])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))


### FIXED CODE ###

l = int(input())

p = 0
while True:
    if 2**p > l:
        p -= 1
        break
    else:
        p += 1
        
n = p+1
m = 2*p
ans = []
for i in range(1, n):
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])
    
while l > 2**p:
    for i in range(n-1, 0, -1):
        if l-2**(i-1) >= 2**p:
            ans.append([i, n, l-2**(i-1)])
            l = l-2**(i-1)
            m += 1
            break

print(n, m)
for a in ans:
    print(' '.join(list(map(str, a))))
# A - A+...+B Problem

N, A, B = map(int, input())

if A>B or (N==1 and A!=B):
    print(0)
else:
    print((N-1)*B+A - (N-1)*A+B + 1)

### FIXED CODE ###

# A - A+...+B Problem

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

if A>B or (N==1 and A!=B):
    print(0)
else:
    print((N-2)*(B-A)+1)
N = int(input())

if N >= 400 and N <= 599:
    pirint(8)
elif N >= 600 and N <= 799:
    print(7)
elif N >= 800 and N <= 999:
    print(6)
elif N >= 1000 and N <= 1199:
    print(5)
elif N >= 1200 and N <= 1399:
    print(4)
elif N >= 1400 and N <= 1599:
    print(3)
elif N >= 1600 and N <= 1799:
    print(2)
else:
    print(1)

### FIXED CODE ###

N = int(input())

if N >= 400 and N <= 599:
    print(8)
elif N >= 600 and N <= 799:
    print(7)
elif N >= 800 and N <= 999:
    print(6)
elif N >= 1000 and N <= 1199:
    print(5)
elif N >= 1200 and N <= 1399:
    print(4)
elif N >= 1400 and N <= 1599:
    print(3)
elif N >= 1600 and N <= 1799:
    print(2)
else:
    print(1)
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
min_a = a.copy()
ans = 10 ** 18
for i in range(N):
    s = x * i
    for j in range(N):
        min_a[j] = min(min_a[j], a[(i + j) % N])
        s += min_a[j]
    ans = min(ans, s)
print(ans)

### FIXED CODE ###

N, x = map(int, input().split())
a = list(map(int, input().split()))
min_a = []
for i in a:
    min_a.append(i)
ans = 10 ** 18
for i in range(N):
    s = x * i
    for j in range(N):
        min_a[j] = min(min_a[j], a[(i + j) % N])
        s += min_a[j]
    ans = min(ans, s)
print(ans)
a=int(input())
a>=30:
  print('Yes')
 else:
  print('No')

### FIXED CODE ###

a=int(input())
if a>=30:
  print('Yes')
else:
  print('No')
S = input()
K = int(input())

for (i, s) in enumerate(S):
    if s != '1':
        one_length = i
        next_num = s
        break

if one_length < K:
    print(str(next_num))
else:
    print('1')

# 1 or 一つ目の1以外

### FIXED CODE ###

S = input()
K = int(input())
one_length = 0
next_num = '1'
for (i, s) in enumerate(S):
    if s != '1':
        one_length = i
        next_num = s
        break

if one_length < K:
    print(str(next_num))
else:
    print('1')

# 1 or 一つ目の1以外
input()
s = input()

def f(i):
  return s[0:i].count('W') + s[i:].count('E')

x = len(s)

for i in range(len(s)):
  x = min(x, f(i))

print(min(arr))

### FIXED CODE ###

input()
s = input()

l = 0
r = s[1:].count('E')
x = l + r

for i in range(1, len(s)):
  if s[i - 1] == 'W':
    l += 1

  if s[i] == 'E':
    r -= 1
  x = min(x, l + r)

print(x)
a, b, c, x = map(int, [input() fot i in range(4)])

ans = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500 + j*100 + k*50 == x:
        ans += 1
print(ans)

### FIXED CODE ###

a, b, c, x = map(int, [input() for z in range(4)])
 
ans = 0
 
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500 + j*100 + k*50 == x:
        ans += 1
print(ans)
# -*- coding: utf-8 -*-
from itertools import combinations
import numpy as np

def solve():
    N = int(input())
    E = np.array([[0,1],[0,0]])
    for i in range((N-1).bit_length()-1):
        E_ = E+(E>0)
        E = np.block([[E_,np.ones_like(E)],[np.zeros_like(E), E_]])
    res = '\n'.join(' '.join(map(str,e[i+1:N+1])) for i, e in enumerate(E[:N+1]))
    return str(res)

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

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N = int(input())
    E = np.array([[0,1],[0,0]])
    for i in range((N-1).bit_length()-1):
        E_ = E+(E>0)
        E = np.vstack([np.hstack([E_,np.ones_like(E)]),np.hstack([np.zeros_like(E), E_])])
    res = '\n'.join(' '.join(map(str,e[i+1:N])) for i, e in enumerate(E[:N]))
    return str(res)

if __name__ == '__main__':
    print(solve())
from collections import deque
import numpy as np


def bfs(h, w, board, visited):
    queue = deque([])
    for i in range(h):
        for j in range(w):
            if board[i][j] == "#":
                queue.append([i, j])
                visited[i][j] = 0
    while queue:
        y, x = queue.popleft()
        for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            yn, xn = y+i, x+j
            if yn >= h or xn >= w or yn < 0 or xn < 0:
                continue
            if visited[yn][xn] == -1 and board[yn][xn] == ".":
                visited[yn][xn] = visited[y][x] + 1
                queue.append([yn, xn])

    return np.max(np.array(visited))


def main():
    h, w = map(int, input().split())
    board = [input() for _ in range(h)]
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    print(bfs(h, w, board, visited))


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def bfs(h, w, board, visited):
    queue = deque([])
    for i in range(h):
        for j in range(w):
            if board[i][j] == "#":
                queue.append([i, j])
                visited[i][j] = 0
    ans = 0
    while queue:
        y, x = queue.popleft()
        for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            yn, xn = y+i, x+j
            if yn >= h or xn >= w or yn < 0 or xn < 0:
                continue
            if visited[yn][xn] == -1 and board[yn][xn] == ".":
                visited[yn][xn] = visited[y][x] + 1
                queue.append([yn, xn])
                ans = max(ans, visited[yn][xn])

    return ans


def main():
    h, w = map(int, input().split())
    board = [input() for _ in range(h)]
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    print(bfs(h, w, board, visited))


if __name__ == "__main__":
    main()
K=int(input())
x=0
if k%2==0:
  print(-1)
  exit
for i in range(1000000):
  x=(10*x+7)%K
  if x==0:
    print(i+1)
    break
if x!=0:
  print(-1)

### FIXED CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')
a = [0]*m
b = [0]*m
t = []
y = []
for i in range(m):
    a[i],b[i] = map(int,input().split())
    c = str(a[i])+" "+str(b[i])
    y.append(c)
t.extend(a)
t.extend(b)
s = [0]*m
count = 0
sw = [0]*n
ab = list(y)
for i in range(m):
    a[i],b[i] = ab[i].split()
    a[i] = int(a[i])
    b[i] = int(b[i])
    if  h[a[i]-1] >= h[b[i]-1] and sw[a[i]-1] == 0:
        if sw[b[i]-1] == 1 or sw[a[i]-1] == 1:
            count -= 1
        count += 1
        sw[a[i]-1] = 1
    elif h[a[i]-1] < h[b[i]-1] and sw[b[i]-1] == 0:
        if sw[a[i]-1] == 1 or sw[b[i]-1] == 1:
            count -= 1
        count += 1
        sw[b[i]-1] = 1
print(count+n-len(set(t)))

### FIXED CODE ###

n,m = map(int,input().split())
h = list(map(int,input().split()))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i],b[i] = map(int,input().split())
sw = [1]*n
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        sw[b[i]-1] = 0
    elif h[a[i]-1] < h[b[i]-1]:
        sw[a[i]-1] = 0
    else:
        sw[a[i]-1] = 0
        sw[b[i]-1] = 0
print(sw.count(1))
N, M = map( int, input().split())
A = list( map( int, input().split()))
C = [0,2,5,5,4,5,6,3,7,6]
dp = [(0,0)]*(N+1)
for a in A:
    dp[C[a]] = (1,0)
Z = sorted( list( set( C[a] for a in A)))
for i in range(2,N+1):
    for z in Z:
        if i > z:
            if dp[i-z][0] == 1:
                dp[i] = (1, i-z)
                break
s = N
ANS = [0]*10
while s != 0:
    _, b = dp[s]
    ANS[s-b] += 1
    if s == b:
        break
    s = b
ans = ""
for i in range(9,0,-1):
    if ANS[C[i]] > 0:
        if i in A:
            ans += str(i)*ANS[C[i]]
            ANS[C[i]] = 0
print( ans)

### FIXED CODE ###

N, M = map( int, input().split())
A = list( map( int, input().split()))
Needs = [0,2,5,5,4,5,6,3,7,6]
A.sort(reverse = True)
V = [0]*10
Check = []
for a in A:
    if V[Needs[a]] == 0:
        Check.append(Needs[a])
        V[Needs[a]] = a
Check.sort()
dp = [-100000]*(N+1)
dp[0] = 0

for x in Check:
    if x <= N:
        dp[x] = 1
for i in range(1,N):
    t = dp[i]
    for x in Check:
        if x + i <= N:
            if dp[x+i] < t + 1:
                dp[x+i] = t+1
ans = ""
t = N
W = [0]*10
while t > 0:
    for a in A:
        x = Needs[a]
        if t-x>=0:
            if dp[t-x]+1 == dp[t]:
                W[V[x]] += 1
                t -= x
                break
for i in range(9,0,-1):
    ans += str(i)*W[i]
print(ans)