Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 数字kに対するマッチ必要本数を返す
def num(k):
    costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    return costs[k-1]

# 動的計画法
# dp(i) := i本の最大桁数(i = 0,1,...,N)
# constructor
inf = 1000
# -infに設定しないと数字の選択時にミスる
dp = [-inf for _ in range(N+1)]
dp[0] = 0

cost_list = [num(k) for k in A]
for i in range(1, N+1):
    for cost in cost_list:
        if i - cost < 0:
            pass
        else:
            temp = dp[i - cost] + 1
            dp[i] = max(dp[i], temp)

ans = ''
many = N
for d in range(dp[N]): # 各桁
    for k in sorted(A, reverse=True):
        if dp[many - num(k)] == dp[many] - 1:
            ans += str(k)
            many -= num(k)
            break
        else:
            pass

print(ans)


### FIXED CODE ###

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

# 数字kに対するマッチ必要本数を返す
def num(k):
    costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    return costs[k-1]

# 動的計画法
# dp(i) := i本の最大桁数(i = 0,1,...,N)
# constructor
inf = 1000
# -infに設定しないと数字の選択時にミスる
dp = [-inf for _ in range(N+1)]
dp[0] = 0

cost_list = [num(k) for k in A]
for i in range(1, N+1):
    for cost in cost_list:
        if i - cost < 0:
            pass
        else:
            temp = dp[i - cost] + 1
            dp[i] = max(dp[i], temp)

ans = ''
many = N
for d in range(dp[N]): # 各桁
    for k in sorted(A, reverse=True):
        if many - num(k) < 0:
            pass
        else:
            if dp[many - num(k)] == dp[many] - 1:
                ans += str(k)
                many -= num(k)
                break
            else:
                pass

print(int(ans))
def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def C(N):
  for i in range(99):
    if N < 26**i:
      ans = []
      for j in range(i):
        ans += chr(ord('a') + N % 26)
        N /= 26
      return ''.join(ans)
    else:
      N -= 26**i


def main():
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)

  # n, k = map(int, input().split())
  # p_list = map(int, input().split())
  # B(n, k, p_list)
  print(C(int(input())))
  # C(702)
  # C(703)
  # C(18279)
  # C(475254)


if __name__ == '__main__':
  main()


### FIXED CODE ###

def A(x):
  if ord(x) - ord('a') >= 0:
    print('a')
  else:
    print('A')


def B(n, k, p_list):
  p_list = sorted(p_list)
  print(sum(p_list[:k]))


def C(N):
  for i in range(99):
    if N < 26**i:
      ans = []
      for j in range(i):
        ans += chr(ord('a') + N % 26)
        N //= 26
      return ''.join(ans[::-1])
    else:
      N -= 26**i


def main():
  # letter = input()
  # A(letter)
  # for x in ['A', 'Z', 'a', 'z']:
  #   A(x)

  # n, k = map(int, input().split())
  # p_list = map(int, input().split())
  # B(n, k, p_list)
  print(C(int(input())))
  #for i in range(1, 27):
  #  print(C(26 + i))
  # C(703)
  # C(18279)
  # C(475254)


if __name__ == '__main__':
  main()
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]


def dfs_numbering(i, M, V, ANS, cnt, v):
    V[i] = v
    for x in M[i]:
        if V[x] == -1:
            cnt = dfs_numbering(x, M, V, ANS, cnt, v)
    ANS[i] = cnt
    return cnt + 1

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        for i in range(n):
            if V[i] == -1:
                dfs_numbering(i, self.M, V, ANS, 0, 0)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

S = scc(n)
for i in range(m):
    S.add_edge(C[i][0], C[i][1])
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(*([len(ANS[i])] + ANS[i]))

### FIXED CODE ###

import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6 + 5)

def dfs_numbering(st, M, V, ANS, cnt, v):
    ST = [st]
    while len(ST) > 0:
        # print(ST,V)
        i = ST[-1]
        if ANS[i] == -1:
            V[i] = v
            end = 1
            for x in M[i]:
                if V[x] == -1:
                    ST.append(x)
                    end = 0
                    # cnt = dfs_numbering(x, M, V, ANS, cnt, v)
            if end == 1:
                ST.pop()
                ANS[i] = cnt
                cnt += 1
        else:
            ST.pop()
    return cnt

class scc():
    def __init__(self, n):
        self.n = n
        self.M = [[] for i in range(n)]
        self.IM = [[] for i in range(n)]

    def add_edge(self, frm, to):
        self.M[frm].append(to)
        self.IM[to].append(frm)

    def scc_list(self):
        n = self.n
        V = [-1] * n
        ANS = [-1] * n

        cnt = 0
        for i in range(n):
            if V[i] == -1:
                cnt = dfs_numbering(i, self.M, V, ANS, cnt, 0)

        # print(ANS)

        ANS1 = [[ANS[i], i] for i in range(n)]
        ANS1.sort(reverse=True)

        # print(ANS1)

        V = [-1] * n
        ANS = [-1] * n
        v = 0
        for i in range(n):
            if V[ANS1[i][1]] == -1:
                dfs_numbering(ANS1[i][1], self.IM, V, ANS, 0, v)
                v += 1

        FANS = [[] for i in range(v)]
        for i in range(n):
            FANS[V[i]].append(i)

        return FANS

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

S = scc(n)
for i in range(m):
    frm, to = map(int,input().split())
    S.add_edge(frm, to)
ANS = S.scc_list()

print(len(ANS))
for i in range(len(ANS)):
    print(len(ANS[i]), end=" ")
    print(*ANS[i])
A, B, C=map(int,input().split())
if A+B >= C:
  ptint('Yes')
else:
  print('No')

### FIXED CODE ###

A, B, C=map(int,input().split())
if A+B >= C:
  print('Yes')
else:
  print('No')
from collections import Counter as C
print(["No", "Yes"][C(C(input()).values()) == C(C(input()).values())])
#I understood

import collections
s = input()
t = input()

S = sorted(list(collections.Counter(s)))
T = sorted(list(collections.Counter(t)))

if S == T:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import collections
s = input()
t = input()

S = sorted(list(collections.Counter(s).values()))
T = sorted(list(collections.Counter(t).values()))

if S == T:
    print('Yes')
else:
    print('No')
a,b,c,d=list(map(int,input().split()))
if a>=0 and c>=0:
    one=b
    two=d

elif b<=0 and d<=0:
    one=a
    two=c

elif a>=0 and d<=0:
    one=a
    two=d
elif b<=0 and c>=0:
    one=b
    two=c


print(one*two)

### FIXED CODE ###

a,b,c,d=list(map(int, input().split()))

one=[a,b]
two=[c,d]
aha=a*c
ihi=a*d
uhu=b*c
ehe=b*d
print(max([aha,ihi,uhu,ehe]))
def make_time(l, k):
	r = []
	for i in range(k-1, len(l)):
		r.append(l[i] - l[i-k+1])
	for i in range(len(l)-1, k-2, -1):
		r.append(l[i] - l[i-k+1])
	return r

if __name__ == '__main__':
	N, K  = list(map(int, input().split()))
	x = list(map(int, input().split()))
	x_time = make_time(x, K)
	times = [(x_time[i] + abs(x[i])) for i in range(N)]
	print(min(times))

### FIXED CODE ###

def make_time(l, k):
	r = []
	for i in range(k-1, len(l)):
		r.append(l[i] - l[i-k+1])
	return r

if __name__ == '__main__':
	N, K  = list(map(int, input().split()))
	x = list(map(int, input().split()))
	x_time = make_time(x, K)
	times1 = [(x_time[i] + abs(x[i])) for i in range(N - K + 1)]
	x.reverse()
	x_time.reverse()
	times2 = [(x_time[i] + abs(x[i])) for i in range(N - K + 1)]
	times = times1 + times2
	print(min(times))
r, g, b = map(int , input(),split())
rgb = r*100 + g*10 + b
if rgb % 4 == 0:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

r, g, b = map(int , input().split())
rgb = r*100 + g*10 + b
if rgb % 4 == 0:
    print('YES')
else:
    print('NO')
N=input()
if N='ABC':
  print('ARC')
else:
  print('ABC')

### FIXED CODE ###

N=input()
if N=='ABC':
  print('ARC')
else:
  print('ABC')
n = int(input())
s = input()
ts = ['.' * i + '#' * (n - i) for i in range(n+1)]
print(min(sum(s[i] != t[i] for i in range(n)) for t in ts))

### FIXED CODE ###

n = int(input())
s = input()
m = s.count('.')
c = (0, m)
for i in range(n):
    if s[i] == '#':
        c = (c[0]+1, c[1])
    else:
        c = (c[0], max(c[1]-1, 0))
    m = min(c[0] + c[1], m)
print(m)
print(sum(int(input())))

### FIXED CODE ###

print(input().count("1"))
n = int(input()
s = dict()
for i in range(n):
    si = input()
    if si in s:
        s[si] +=1
    else:
        s[si] = 0
l = max(s.values())
ans = []
for i in s:
    if s[i] == l:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

### FIXED CODE ###

from collections import  Counter
n = int(input())
a  = [input() for i in range(n)]
cnt = Counter(a)
l = max(cnt.values())
ans = [s for s,c in cnt.items()if c ==l]
ans.sort()
print('\n'.join(ans))
[a0,b0,k]=input().split()
if a0>k:
	ak=a0-k
    bk=b0
else: 
	ak=0
  	bk=b0-(k-a0)

if bk<0:
  bk=0

print(ak,bk)
  
  
    
  


### FIXED CODE ###

[a0,b0,k]=input().split()
a0=int(a0)
b0=int(b0)
k =int(k)
if a0>k:
    ak=a0-k
    bk=b0
else:
    ak=0
    bk=b0-(k-a0)

if bk<0:
    bk=0
    
print(ak,bk)
N = int(input())
a = [int(input) for _ in range(5)]

print(N // min(a) + 5)


### FIXED CODE ###

from math import ceil

N = int(input())
a = [int(input()) for _ in range(5)]

print(ceil(N / min(a)) + (5-1))
k = int(input())
ans = 0
for a in range(k):
  for b in range(k):
    for c in range(k):
      ans += gcd(gcd(a,b),c)
print(ans)

def gcd(p,q):
  if p % q == 0:
    return q
  return gcd(q, p%q)

### FIXED CODE ###

from math import gcd

k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    x = gcd(a,b)
    for c in range(1,k+1):
        ans += gcd(x,c)
print(ans)
A, B = map(int,input().split())

one = A/0.08
two = (A+1)/0.08
three = B/0.1
four = (B+1)/0.1


if two <= three or one >= four:
    kai = -1
if three <= one and four > one:
    kai = one
if one <= three and four <= two:
    kai = three

print(kai)
    

### FIXED CODE ###

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

count = 0

for n in range(10000):
    za = n*0.08
    zb = n*0.1
    count += 1
    if A == math.floor(za) and B == math.floor(zb):
        print(n)
        break


if count == 10000:
    print(-1)
x1,x2,y1,y2 = map(int,input())
x3 = x2 + (y1 - y2)
y3 = y2 + (x2 - x1)
x4 = y1 + (x2 - x1)
y4 = x1 + (y1 - y2)
print(x3,y3,x4,y4)

### FIXED CODE ###

x1,y1,x2,y2 = map(int,input().split())
x3 = x2 + (y1 - y2)
y3 = y2 + (x2 - x1)
x4 = x1 + (y1 - y2)
y4 = y1 + (x2 - x1)
print(x3,y3,x4,y4)
N,A,B=map(input().split())
print(max(N*A,B))

### FIXED CODE ###

N,A,B=map(int,input().split())
print(min(N*A,B))
from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    count = n//2
else:
    odd = defaultdict(lambda: 0)
    even = defaultdict(lambda: 0)
    for i in v[0::2]:
        odd[i] += 1
    for i in v[1::2]:
        even[i] += 1
    o1, o2, *_ = sorted(odd.items(), key=lambda x: x[1], reverse=True)
    e1, e2, *_ = sorted(even.items(), key=lambda x: x[1], reverse=True)
    if o1[0] != e1[0]:
        count = n - o1[1] - e1[1]
    elif o1[1] >= e1[1]:
        count = n - o1[1] - e2[1]
    elif o1[1] < e1[1]:
        count = n - o2[1] - e1[1]

print(count)

### FIXED CODE ###

from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))

odd = defaultdict(lambda: 0)
even = defaultdict(lambda: 0)
odd[None] = 0
even[None] = 0
for i in v[0::2]:
    odd[i] += 1
for i in v[1::2]:
    even[i] += 1

odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
even = sorted(even.items(), key=lambda x: x[1], reverse=True)
if odd[0][0] != even[0][0]:
    count = n - odd[0][1] - even[0][1]
else:
    count = n - max(odd[0][1]+even[1][1], odd[1][1]+even[0][1])

print(count)
s = input()

s[:4] = '2018'
print(s)

### FIXED CODE ###

s = input()
modify = '2018'+ s[4:]

print(modify)
a, b = map(int, input().split())
ans = 0
for i in range(1,10):
  for j in range(0,10):
    for k in range(0,10):
  x = 10000*i + 1000*j + 100*k + 10*j + i
  if a <= x <= b:
    ans += 1
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
ans = 0
import itertools
for i,j,k in itertools.product(range(0,10), repeat=3):
  if i == 0:
    continue
  x = 10000*i + 1000*j + 100*k + 10*j + i
  if a <= x <= b:
    ans += 1
print(ans)
n = int(input())

ans = 0
for i in range(1, n+1):
    cnt = 0
    for j in range(1, i+1):
        if i % 2 != 0 and i % j == 0:
            cnt += 1
            if cnt == 8:
                ans += 1
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
print((a-1) * (b-1))
#C問題
mod = 10**9+7
N,M = map(int,input().split())

step = []
for i in range(N+1):
    if i <= 1:
        step.append(1)
    elif i == 2:
        step.append(1)
    else:
        step.append(step[i-1]+step[i-2])
    
A = []
for j in range(M):
    A.append(int(input()))

stairs = []
nowlen = 1
flag = 0
for i in range(N):
    I = i+1
    if I in A:
        if nowlen == 0:
            flag = 1
            break
        stairs.append(nowlen)
        nowlen = 0
    else:
        nowlen+=1
stairs.append(nowlen)
if flag == 1:
    print(0)
else:
    ans = 1
    for s in stairs:
        ans*=step[s]
        
    print(ans%mod)
    
    
    

### FIXED CODE ###

#C問題
mod = 10**9+7
N,M = map(int,input().split())

step = []
for i in range(N+2):
    if i <= 1:
        step.append(1)
    elif i == 2:
        step.append(1)
    else:
        step.append(step[i-1]+step[i-2])
    
A = []
for j in range(M):
    A.append(int(input()))

stairs = []
flag = 0
old = -1
for a in A:
    if a-old == 1:
        flag = 1
        break
    else:
        stairs.append(a-old-1)
        old = a
stairs.append(N-old)

if flag == 1:
    print(0)
else:
    #print(stairs)
    ans = 1
    for s in stairs:
        ans*=step[s]
        
    print(ans%mod)
import math
print(math.factorial(int(input))%(10**9 + 7))

### FIXED CODE ###

import math
print(math.factorial(int(input()))%(10**9+7))
H,W,A,B=map(int,input().split())
a=[ [-1 for _ in range(W)] for _ in range(H) ]

L=0
for i in range(H):
  R=min(L+A,W)
  for j in range(L,R):
    a[i][j]=0
  for j in range(R,W):
    a[i][j]=1
  if L+A>W:
    p =L+A
    for j in range(0,p):
      a[i][j]=1
    L=p
  else:
    for j in range(0,L):
      a[i][j]=1
    L =L+A

for j in range(W):
  cnt=0
  for i in range(H):
    cnt += a[i][j]
  if min(cnt,H-cnt)>B:
    ans="No"
    print(ans)
    break
else:
  for gyou in a:
    st = list( map(str,gyou) )
    print("".join(st))

### FIXED CODE ###

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

for i in range(B):
  print("0" * A+ "1" * (W-A))
for i in range(B,H):
  print("1" * A+ "0" * (W-A))
def rec(i):

  if dp[i] < inf:
    return dp[i]

  if i == 0:
    return 0

  res = inf
  res = min(res, rec(i-1) + abs(h[i] - h[i-1]))
  if i > 1:
    res = min(res, rec(i-2) + abs(h[i] - h[i-2]))

  dp[i] = res

  return res


n = int(input())
h = [int(hi) for hi in input().split()]

inf = float('inf')

dp = [inf] * n

print(rec(n-1))

### FIXED CODE ###

n = int(input())
h = [int(hi) for hi in input().split()]

inf = float('inf')

dp = [inf] * n

dp[0] = 0

for i in range(n):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
  dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
for i in range(n):
    result=s.count(s[i])-t.count(s[i])
print(max(o,result))


### FIXED CODE ###

n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
result=0
for i in set(s):
    result=max(result,s.count(i)-t.count(i))
print(result)
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]


acc = [0]
for ai in a:
    acc.append((acc[-1]+ai)%k)

#print(acc)
ans = 0
d = {}
for num,i in enumerate(acc):
    #print(d,num)
    if num >= k-1:
        d[acc[num-k+1]] -= 1
    #print(d,num)
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
    #print(ans)

print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]


acc = [0]
for ai in a:
    acc.append((acc[-1]+ai)%k)

#print(acc)
ans = 0
d = {}
for num,i in enumerate(acc):
    #print(d,num)
    if num >= k:
        d[acc[num-k]] -= 1
    #print(d,num)
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
    #print(ans)

print(ans)
answers = []
while True:
    head = input()
    if head == "0 0 0":
        break
    nums = head.split(" ")
    num = int(nums[0])
    mini = int(nums[1])
    maxi = int(nums[2]) 

    scores = []

    gaps = []

    for _ in range(int(head[0])):
        scores.append(int(input()))
    
    for i in range(mini, maxi + 1):
        oks = scores[:i]
        ngs = scores[i:]
        if len(oks) and len(ngs): 
            gap = oks[-1] - ngs[0]
            gaps.append((i,gap))

    filtered = list(filter(lambda x: x[1] == max(map(lambda x: x[1], gaps)), gaps))
    sorted(filtered,key=lambda x: x[0])
    answers.append(filtered[-1][0])

for i in answers:
    print(i)


### FIXED CODE ###

while True:
    num, mini, maxi = map(int, input().split())
    if num == 0: break
    scores = [ int(input()) for i in range(num) ]
    gap = 0
    ans = 0
    for i in range(mini, maxi + 1):
        gap = scores[i-1] - scores[i] if scores[i-1] - scores[i] >= gap else gap
        ans = i if scores[i - 1] - scores[i] >= gap else ans

    print(ans)
import Math

h, a = map(int, input().split())
print(math.ceil(h//a + 1))


### FIXED CODE ###

import math

h, a = map(int, input().split())
print(math.ceil(h/a))
import fractions
a, b = map(int, input().split(' '))

print(int(a * b / fractions.gcd(a, b)))


### FIXED CODE ###

a = int(input())
b = int(input())
for i in range(3):
    if a != i+1 and b != i+1:
        print(i+1)
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = map(int, input().split())
cmb_val = cmb(N-1,2)
ma = (N-1)*(N-2)/2

if ma < K:
  print('-1')
else:
  a =[(1, i) for i in range(2, N+1)]
  
  b = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]
  a.extend(b[:cmb_val-K])
      
  print(len(a))
  for i in range(len(a)):
    print(a[i][0], a[i][1])
  
  

### FIXED CODE ###

from operator import mul
from functools import reduce

def cmb(n,r):
  if n < r:
    return 0
  else:
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

N, K = map(int, input().split())
ma = (N-1)*(N-2)/2

if ma < K:
  print('-1')
else:
  cmb_val = cmb(N-1,2)
  a =[(1, i) for i in range(2, N+1)]
  b = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]
  a.extend(b[:cmb_val-K])
      
  print(len(a))
  for i in range(len(a)):
    print(a[i][0], a[i][1])
N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
  ans+=len(set(A[i],B[i],C[i]))-1
print(ans) 

### FIXED CODE ###

N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
  ans+=len(set([A[i],B[i],C[i]]))-1
print(ans)
n=int(input())
array=[]
for i in range(n):
  k=int(input())
  array.append(k)
array.sorted()
sum=0
for i in range(n-1):
  sum+=array[i]
if array[n-1]<sum:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n=int(input())
array=list(map(int,input().split()))
array.sort()
sum=0
for i in range(n-1):
  sum+=array[i]
if array[n-1]<sum:
  print('Yes')
else:
  print('No')
import math
def cal(n ,r):
    if n == r:
        return 1
    return math.factorial(n)/(math.factorial(r) * math.factorial(n-r))

def bin_search(in_list, val):
    cnt = len(in_list)
    mid = round(cnt/2)
    if cnt == 1:
        return in_list[0]
    if in_list[mid] > val:
        return bin_search(in_list[:mid], val)
    if in_list[mid] < val:
        return bin_search(in_list[mid:], val)
    if in_list[mid] == val:
        return val

n = int(input())
A = sorted(list(map(int, input().split())))

m_combo = 0
ai = 0
aj = 0

for i in range(1,n):
    a = A[i]
    val = bin_search(A[:i], round(a/2))
    upper = A[A.index(val) + 1]
    if abs(val - round(a/2)) > abs(upper - round(a/2)):
      val = upper
    combo = cal(a, val)
    if combo > m_combo:
        m_combo = combo
        ai = a
        aj = val

print('{} {}'.format(ai, aj))

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))

ai = max(A)
A.remove(ai)

Asub = [abs(ai/2 -a) for a in A]
aj = A[Asub.index(min(Asub))]

print('{} {}'.format(ai, aj))
#python3.4
import math
def inpul(): return list(map(int, input().split()))

N, M = inpul()
A = inpul()

c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010

f[0] = 0
for i in range(1, N+1):
	for x in a:
		if i-c[x] >= 0:
			f[i] = max(f[i], f[i-c[x]]*10+x)
print(f[n])

### FIXED CODE ###

#python3.4
import math
def inpul(): return list(map(int, input().split()))

N, M = inpul()
A = inpul()

c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010

f[0] = 0
for i in range(1, N+1):
	for x in A:
		if i-c[x] >= 0:
			f[i] = max(f[i], f[i-c[x]]*10+x)
print(f[N])
import heapq
def SME(start,end):
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.Add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None in ANS[i:i+L] :
            while True:
                if ANS[i] :
                    i += 1
                    continue
                else : 
                    ANS[i] = min(Whole[i+1-L:i+1])
                    i += 1
                    break
        else :
            i += L
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
C = [i for i in range(N)]
D = set([])
parameter = 0.99
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])