Harryxun/stf_run huggingface dataset:
import bisect
n = int(input())
a = list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)

INF = float('inf')
dp = [INF]*(n+1)
ans = [1]*(n+1)
checked = [False]*(n+1)
checked[1] = True
changes = []

def search(x):
    ind = bisect.bisect_left(dp,a[x-1])
    changes.append((ind,dp[ind]))
    dp[ind] = a[x-1]
    ans[x] = bisect.bisect_left(dp,INF)
    
    for i in t[x]:
        if not checked[i]:
            checked[i] = True
            search(i)
    
    b,c = changes.pop()
    dp[b] = c
    
search(1)
for i in ans[1:]:
    print(i)

### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = [0]+list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)

m = 10**18
dp = [m]*(n+1)
ans = [1]*(n+1)
checked = [False]*(n+1)
checked[1] = True
changes = []

def search(x):
    ind = bisect.bisect_left(dp,a[x])
    changes.append((ind,dp[ind]))
    dp[ind] = a[x]
    ans[x] = bisect.bisect_left(dp,m)
    
    for i in t[x]:
        if not checked[i]:
            checked[i] = True
            search(i)
    
    b,c = changes.pop()
    dp[b] = c
    
search(1)
for i in ans[1:]:
    print(i)
import math
n, d= (int(c) for c in input().split())

x = []

for i in range(n): 
    x.append(input().split())

sum_ans = 0
count=0
for j in range(0.n-2):
    for k in range(j+1.n-1):
        for n in range(d):
            sum_ans = sum_ans+(x[j][n] - x[k][n]) **2
        if math.sqrt(sum_ans)%1==0:
            count=count+1
        sum_ans=0
print(sum_ans)


### FIXED CODE ###

import math
n, d= (int(c) for c in input().split())

x = []

for i in range(n): 
    x.append(input().split())

sum_ans = 0
count=0
print
for j in range(0,n-1):
    for k in range(j+1,n):
        for l in range(d):
            sum_ans = sum_ans+(int(x[j][l]) - int(x[k][l])) **2
        if math.sqrt(sum_ans)%1==0.0:
            count=count+1
        sum_ans=0
print(count)
a = int(input())
b = 1
while True:
	if b < a+1:
		x = map(int,input().split(' '))
		x.sort()
		if x[0]*2 + x[1]*2 = x[2]*2:
			print('YES')
		else:
			print('NO')
		b += 1
		continue
	else:
		break

### FIXED CODE ###

for val in range(input()):
	x = map(int,raw_input().split(' '))
	x.sort()
	if x[0]**2+x[1]**2==x[2]**2: print 'YES'
	else: print 'NO'
a,b = int(input())

print(a*b)

### FIXED CODE ###

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

print(a*b)
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())

for _ in range(min(K, 42)):
    acc = [0] * (N + 1)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N, i + a + 1)
        acc[l] += 1
        acc[r] -= 1
    acc[0] = min(N, acc[0])
    for i in range(N):
        acc[i + 1] = min(N, acc[i] + acc[i + 1])
    A = acc[:-1]
    if all(a == N for a in A):
        break
print(*A)


### FIXED CODE ###

#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())

for _ in range(min(K, 42)):
    acc = [0] * (N + 1)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N, i + a + 1)
        acc[l] += 1
        acc[r] -= 1
    acc[0] = min(N, acc[0])
    for i in range(N):
        acc[i + 1] = min(N, acc[i] + acc[i + 1])
    A = acc[:-1]
    if all(a == N for a in A):
        break
print(*A)
N, M = [int(x) for x in input().split(' ')]

as = [int(x) for x in input().split(' ')]
as.sort()

for _ in range(M):
  b, c = [int(x) for x in input().split(' ')]
  for i in range(b):
    if a[i] <= c:
      a[i] = c
    else:
      break
  as.sort()
  
print(sum(as))

### FIXED CODE ###

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

As = list(map(int, input().split()))
As.sort()

BCs = []
for _ in range(M):
  b, c = tuple(map(int, input().split()))
  BCs.append((b, c))
BCs.sort(key=lambda x: x[1], reverse=True)
  
num = 0
i = 0
for b, c in BCs:
  for j in range(b):
    a = As[i]
    
    if a >= c:
      break
    else:
      num += c
      i += 1
      
    if i == len(As):
      break
      
  if a >= c or i == len(As):
    break
num += sum(As[i: ])
    
print(num)
d,t,s = map(int,input()split(()))
if  t*s >= d:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

d,t,s = map(int,input().split())
if  t*s >= d:
    print("Yes")
else:
    print("No")
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
i = 0
while i < len(s):
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            i = j - 1
            break
    tmp //= 2
    ans += tmp
    i += 1
ans *= k
if s[0] == s[-1] and s[-1] != s[-2]:
    ans += k - 1
print(ans)

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) // 2 * (k - 1)
i = a
ans2 = 0
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp
print(ans + ans2 * k)
from collections import defaultdict

n = int(input())
counts = defaultdict(int)

for _ in range(n):
    counts[input().strip()] += 1

vec = sorted([(-value, key) in counts.items()], reverse=True)
best = vec[0][0]
for v, s in vec:
    if v != best:
        break
    print(s)


### FIXED CODE ###

from collections import defaultdict

n = int(input())
counts = defaultdict(int)

for _ in range(n):
    counts[input().strip()] += 1

vec = sorted([(value, key) for key, value in counts.items()])
best = vec[-1][0]
keys = sorted([key for value, key in vec if value == best])
for key in keys:
    print(key)
a,b=map(int,input(),split())
n=int((a*3+b)/2)

print(n)

### FIXED CODE ###

a,b=map(int,input().split())
n=int((a*3+b)/2)
 
print(n)
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
a = {i for i in range(10)}
N_hate = a.difference(D)
for j in range(10001):
    if N <= j:
        L = {int(result) for result in str(j)}
        if N_hate == L:
            N_love = j
            break
print(N_love)


### FIXED CODE ###

N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
for j in range(N,N*10):
    if N <= j:
        L = {int(result) for result in str(j)}
        if D.isdisjoint(L):
            D_love = j
            break    
print(D_love)
from collections import defaultdict
import sys
from math import gcd
count = defaultdict(int)
N = int(sys.stdin.readline())

zeros = 0
for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A == B == 0:
        zeros += 1
        continue
    if A == 0:
        angle = (0, 1)
    elif B == 0:
        angle = (1, 0)
    else:
        sgn = A / abs(A)
        g = gcd(A, B)
        angle = (A / sgn / g, B / sgn / g)

    count[angle] += 1
# print(count)

pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    if k1 == (0, 1):
        if (1, 0) in count:
            pairs[(1, 0)] = k1
        else:
            solos.append(k1)
        continue

    A, B = k1
    sgn = -B / abs(B)
    k2 = (-B / sgn, A / sgn)
    if k2 in count:
        pairs[k2] = k1
    else:
        solos.append(k1)
# print(pairs, solos)

P = 1000000007


def pow2(n):
    # if n < 30:
    #     return 2 ** n

    # p = pow2(n // 2)
    # pp = (p * p) % P
    # if n % 2 == 1:
    #     return (2 * pp) % P
    # else:
    #     return pp
    return pow(2, n, P)


result = 1
for p in pairs:
    # print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result = result * ((pow2(n) - 1) + (pow2(m) - 1) + 1) % P
for k in solos:
    # print("solo", k, count[k])
    result = result * pow2(count[k]) % P

print(result + zeros - 1)


### FIXED CODE ###

from collections import defaultdict
import sys
from math import gcd
count = defaultdict(int)
N = int(sys.stdin.readline())

zeros = 0
for i in range(N):
    A, B = [int(x) for x in input().split()]
    if A == B == 0:
        zeros += 1
        continue
    if A == 0:
        angle = (0, 1)
    elif B == 0:
        angle = (1, 0)
    else:
        sgn = A // abs(A)
        g = gcd(A, B)
        angle = (A // sgn // g, B // sgn // g)

    count[angle] += 1
# print(count)

pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    if k1 == (0, 1):
        if (1, 0) in count:
            pairs[(1, 0)] = k1
        else:
            solos.append(k1)
        continue

    A, B = k1
    if B:
        sgn = -B // abs(B)
        k2 = (-B // sgn, A // sgn)
    else:
        k2 = (0, 1)
    if k2 in count:
        pairs[k2] = k1
    else:
        solos.append(k1)
#print(pairs, solos)

P = 1000000007


def pow2(n):
    # if n < 30:
    #     return 2 ** n

    # p = pow2(n // 2)
    # pp = (p * p) % P
    # if n % 2 == 1:
    #     return (2 * pp) % P
    # else:
    #     return pp
    return pow(2, n, P)


result = 1
for p in pairs:
    # print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result = result * ((pow2(n) - 1) + (pow2(m) - 1) + 1) % P
for k in solos:
    # print("solo", k, count[k])
    result = result * pow2(count[k]) % P

print((result + zeros - 1) % P)
s = input()
t = input()

print(t+s)

### FIXED CODE ###

S,T=input().split()
print(T+S)
N=int(input())
H=[int(x) for x in input().split()]
cnt=1
tall=H[0]
for i in range(1,N):
    if tall<=H[i]:
        tall=H[i]
        cnt+=1
print(cnt)


### FIXED CODE ###

A,B=map(int,input().split())
if A>=B:
    a=A-1
    if a>=B:
        print(A+a)
    else :
        print(A+B)
elif B>A:
    b=B-1
    if b>=A:
        print(b+B)
    else :
        print(B+A)
#!usr/bin/env python3
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [LI() for i in range(n)]

def solve():
    def add(i,x):
        while i < len(bit):
            bit[i] += x
            i += i&-i
    def sum_(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res
    n,Q = LI()
    c = LI()
    c = [0]+c
    q = LIR(Q)
    q = [[i,LI()] for i in range(Q)]
    q.sort(key = lambda x:x[1][1])
    bit = [0]*(n+2)
    i = 1
    p = [None]*(n+1)
    ans = [0]*Q
    s = 0
    for ind,(l, r) in q:
        l -= 1
        while i <= r:
            ci = c[i]
            j = p[ci]
            if j is not None:
                add(j,1)
            else:
                s += 1
            p[ci] = i
            i += 1
        ans[ind] = s-l+sum_(l)
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def LIR(n):
    res = [None] * n
    for i in range(n):
        l, r = map(int, input().split())
        res[i] = (l-1, r-1, i)
    return res

#solve
def solve():
    n, q = LI()
    c = LI()
    lr = LIR(q)
    ans = [None] * q
    lr.sort(key=lambda x: x[1])
    dp = [-1] * (max(c) + 1)
    bit = [0] * (n + 1)
    def add(i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= n:
            bit[x - 1] += w
            x += x & -x
        return
    def sum(i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += bit[x - 1]
            x -= x & -x
        return res
    t = 0
    def f(t):
        l, r, j = lr[t]
        xr = sum(r)
        xl = sum(l-1)
        tmp = xr - xl
        ans[j] = tmp
        
    for i in range(n):
        ci = c[i]
        l = dp[ci]
        add(i, 1)
        dp[ci] = i
        if l != -1:
            add(l, -1)
        while t < q and lr[t][1]<= i:
            f(t)
            t += 1
        if t == q:
            break
    for ai in ans:
        print(ai) 
    return


#main
if __name__ == '__main__':
    solve()
from collections import deque
def bfs():
    d=[[float("inf")]*w for i in range(h)]
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    que=deque([])
    que.append((0,0))
    d[0][0]=0
    while que:
        p=que.popleft()
        if p[0]==h-1 and p[1]==w-1:
            break
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                que.append((nx,ny))
                d[nx][ny]=d[p[0]][p[1]]+1
    return d[h][w]

h,w=map(int,input().split())

if d[h][w]!=inf:
    ans=h*w-d[h][w]-1-maze.count("#")
else:
    ans=-1

print(ans)

### FIXED CODE ###

from collections import deque
def bfs():
    d=[[float("inf")]*w for i in range(h)]
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    que=deque([])
    que.append((0,0))
    d[0][0]=0
    cnt=0
    while que:
        p=que.popleft()
        if p[0]==h-1 and p[1]==w-1:
            break
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx and nx<h and 0<=ny and ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
                que.append((nx,ny))
                d[nx][ny]=d[p[0]][p[1]]+1
    for i in range(h):
        for j in range(w):
            if maze[i][j]=="#":
                cnt+=1
    if d[h-1][w-1]!=float("inf"):
        return h*w-d[h-1][w-1]-1-cnt
    else:
        return -1

h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]

print(bfs())
N=int(input())
X=[int(i) for _ in input().split()]

Y=sorted(X)

a1=Y[N//2]
a2=Y[N//2-1]

for i in range(N):
    if X[i]<=a1:
        print(a1)
    else:
        print(a2)

### FIXED CODE ###

N=int(input())
X=[int(i) for i in input().split()]

Y=sorted(X)

a1=Y[N//2-1]
a2=Y[N//2]

for i in range(N):
    if X[i]<=a1:
        print(a2)
    else:
        print(a1)
#入力受け取り
N, K=map(int, input().split())

#N=aK+bとした時のbを求める
B=N%K

#bとK-bの小さい方を出力
print(min(b, K-b))


### FIXED CODE ###

N, K=map(int, input().split())
tmp=N%K
print(min(tmp, K-tmp))
import sys, collections
sys.setrecursionlimit(10000000)

def comb(n, r, fact, revfact, mod):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

def dfs(now, edge, visited, mod, N, fact, revfact):
    visited[now] = True
    son = 0
    ans = 1
    for next in edge[now]:
        if not visited[next]:
            son += 1
            ans *= dfs(next, edge, visited, mod, N, fact, revfact)
            ans %= mod
    if son == 0: return 1
    else:
        ans *= comb(N-2, son, fact, revfact, mod)
        ans %= mod
        return ans

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    edge = [[] for i in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    mod = 7 + 10 ** 9

    fact = [1] * (K + 1)
    for i in range(2, K+1):
        fact[i] = (i * fact[i-1]) % mod
    revfact = [1] * (K+1)
    revfact[K] = pow(fact[K], mod - 2, mod)
    for i in reversed(range(1, K)):
        revfact[i] = ((i+1) * revfact[i+1]) % mod

    visited = [False] * N
    visited[0] = True
    ans = 1
    son = 0
    for next in edge[0]:
        son += 1
        ans *= dfs(next, edge, visited, mod, K, fact, revfact)
        ans %= mod
    ans *= (comb(K-1, son, fact, revfact, mod) * K) % mod
    ans %= mod

    print(ans)

    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys, collections
sys.setrecursionlimit(10000000)

def permutation(k, r, fact, revfact, mod):
    return (fact[k] * revfact[k-r]) % mod

def dfs(now, parent, edge, mod, K, fact, revfact):
    son = 0
    ans = 1
    for next in edge[now]:
        if next != parent:
            son += 1
            ans *= dfs(next, now, edge, mod, K, fact, revfact)
            ans %= mod
    if K-2 < son: ans = 0
    elif son > 0:
        ans *= permutation(K-2, son, fact, revfact, mod)
        ans %= mod
    return ans
    

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    edge = [[] for i in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    mod = 7 + 10 ** 9

    fact = [1] * (K + 1)
    for i in range(2, K+1):
        fact[i] = (i * fact[i-1]) % mod
    revfact = [1] * (K+1)
    revfact[K] = pow(fact[K], mod - 2, mod)
    for i in reversed(range(1, K)):
        revfact[i] = ((i+1) * revfact[i+1]) % mod

    ans = K
    son = 0
    for next in edge[0]:
        son += 1
        ans *= dfs(next, 0, edge, mod, K, fact, revfact)
        ans %= mod
    ans *= permutation(K-1, son, fact, revfact, mod)
    ans %= mod

    print(ans)
    return 0

if __name__ == "__main__":
    solve()
import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdeghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdefghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()
N = int(input())

if n == 3:
  print("YES")
elif n == 5:
  print("YES")
elif n == 7:
  print("YES")

### FIXED CODE ###

N = int(input())

if N == 3:
    print("YES")
elif N == 5:
    print("YES")
elif N == 7:
    print("YES")
else:
    print("NO")
num = int(input())
string = input()

if num>=3200:
  print(string):
else:
  print("red")

### FIXED CODE ###

num = int(input())
string = input()

if num>=3200:
  print(string)
else:
  print("red")
N,M=map(int,input().split())

X=list(map(int,input().split()))
X.sort()
di=[]


for i in range(M-1):
    di.append(X[i+1]-X[i])
if N==1:
    print(sum[di])
di.sort()
print(sum(di[:M-N]))

### FIXED CODE ###

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

X=list(map(int,input().split()))
X.sort()
di=[]

for i in range(M-1):
    di.append(X[i+1]-X[i])

di.sort(reverse=True)
print(sum(di[N-1:]))
import os, sys, re, math

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

match = [10000000,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = max(str(a) + tmp, tmp + str(a))
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))


### FIXED CODE ###

import os, sys, re, math
sys.setrecursionlimit(100000)
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))

match = [100,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = str(a) + tmp
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))
n, k = map(int, input().split())
l = list(map(int, input().split())).sort(reverse=True)
print(sum(l[0:k]))

### FIXED CODE ###

n, k = map(int, input().split())
l = sorted(list(map(int, input().split())),reverse=True)
print(sum(l[0:k]))
a = int(input())
b = int(input())
c = int(input())
if(a + b + c)==17:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a,b,c = list(map(int,input().split()))
if(a + b + c)==17:
  print("YES")
else:
  print("NO")
n,k=map(int,input().split())
xlist =list(map(int,input().split()))
count = 0
for i in range(n):
  if x[i]>=k:
    count+=1
print(count)

### FIXED CODE ###

n,k=map(int,input().split())
xlist =list(map(int,input().split()))
count = 0
for i in range(n):
  if xlist[i]>=k:
    count+=1
print(count)
k = int(input())
a, b = map(int, input())
flag = False
for i in range(a, b+1):
    if i % k == 0:
        flag = True
        break
if flag:
    print('OK')
else:
    print('NG')


### FIXED CODE ###

k = int(input())
a, b = map(int, input().split())
flag = False
for i in range(a, b+1):
    if i % k == 0:
        flag = True
        break
if flag:
    print('OK')
else:
    print('NG')