Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from itertools import permutations

n,m,rnum = map(int,input().split())
inf = 10**18
shortest = [[inf for i in range(n)] for j in range(n)]
r = list(map(int,input().split()))
for i in range(len(r)):
    r[i]-= 1

for i in range(m):
    a,b,c = map(int,input().split())
    shortest[a-1][b-1] = c
    shortest[b-1][a-1] = c

for i in range(len(shortest)):
    for j in range(len(shortest)):
        for k in range(len(shortest)):
            shortest[j][k] = min(shortest[j][k],shortest[j][i]+shortest[i][k])

ans = inf
# print(shortest)
for p in permutations(r):
    temp = 0
    for i in range(rnum-1):
        temp+=shortest[p[i]][p[i+1]]
    if ans > temp:
        ans = temp
print(ans)

### FIXED CODE ###

from itertools import permutations

n,m,rnum = map(int,input().split())
inf = 10**18
shortest = [[inf for i in range(n)] for j in range(n)]
r = list(map(int,input().split()))
for i in range(len(r)):
    r[i]-= 1

for i in range(m):
    a,b,c = map(int,input().split())
    shortest[a-1][b-1] = c
    shortest[b-1][a-1] = c

for i in range(len(shortest)):
    for j in range(len(shortest)):
        for k in range(len(shortest)):
            shortest[j][k] = min(shortest[j][k],shortest[j][i]+shortest[i][k])

ans = inf
# print(shortest)
for p in permutations(r):
    temp = 0
    for i in range(rnum-1):
        temp+=shortest[p[i]][p[i+1]]
    if ans > temp:
        ans = temp
print(ans)
### BUGGY CODE ###

def main():
    from itertools import accumulate
    import numpy as np

    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())))
    A = np.append(A, 0)
    for _ in range(k):
        l = [0] * (n + 1)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.array(list(accumulate(l)))
    print(*A[:-1])


main()

### FIXED CODE ###

import numpy as np
from numba import jit


@jit("i8, i8, i8[:]")
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
Dic = {}
for n in range(N):
    S = input()
    if S in Dic.keys():
        Dic[S] = Dic[S] + 1
    else:
        Dic[S] = 1
        
max_k_list = [kv[0] for kv in Dic.items() if kv[1] == max(Dic.values())]
max_k_list = sorted(max_k_list)

print(*max_k_list, sep="\n")
#for t in max_k_list:
    #print(t)

### FIXED CODE ###

from collections import Counter
N = int(input())
L = [input() for _ in range(N)]
#for n in range(N):
    #S = input()
    #L.append(S)
Dic = Counter(L)
max_value = max(Dic.values())
max_k_list = [i for i, j in Dic.items() if j == max_value]
max_k_list = sorted(max_k_list)
for t in max_k_list:
    print(t)
### BUGGY CODE ###

# s1 = input()
# len_s = len(s1)
# s2 = s1
# while True:
#     len_1 = len(s2)
#     s2 = s2.replace("01", "").replace("10", "")
#     len_2 = len(s2)
#     if len_1 == len_2:
#         break
#
# print(len_s - len(s2))

s = input()
s2 = s
for i in range(len(s), 0, -1):
    # print("i", i)
    # print("s2", s2)
    m1 = "1" * i + "0" * i
    m2 = "0" * i + "1" * i
    s2 = s2.replace(m1, "").replace(m2, "")

while True:
    len_1 = len(s2)
    s2 = s2.replace("01", "").replace("10", "")
    len_2 = len(s2)
    if len_1 == len_2:
        break
print(len(s) - len(s2))


### FIXED CODE ###

s = input()
ans = min(s.count('0'), s.count('1'))
print(ans * 2)
### BUGGY CODE ###

def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)

MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = 1
for i in A:
    lcm = (lcm*i)//GCD(lcm,i)
ans = 0
for i in A:
    ans += lcm//i
    ans %= MOD
print(ans)


### FIXED CODE ###

def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)

def func(x):
    if x <= 1:
        return []
    for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            count = 0
            while x%i==0:
                x //= i
                count += 1
            return [[i,count]]+func(x)
    return [[x,1]]
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = [0]*(10**6)
for i in A:
    for a,b in func(i):
        lcm[a] = max(lcm[a],b)
L = 1
for i in range(2,10**6):
    L *= pow(i,lcm[i],MOD)
    L %= MOD
ans = 0
for i in A:
    ans += L*pow(i,MOD-2,MOD)
    ans %= MOD
print(ans)
### BUGGY CODE ###

from collections import deque

s = list(input())
q = int(input())
ans = deque(s)
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans.reverse()
    else:
        if arr[1] == '1':
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
print(*ans, sep='')

### FIXED CODE ###

from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')
### BUGGY CODE ###

# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    LR = [tuple(map(int, a.split())) for a in args[1:]]
    L, R = zip(*LR)

    ret = 0

    p, q = np.argmax(L), np.argmin(R)
    lp, rq = L[p], R[q]
    if p == q:
        ret = max(0, 1+rq-lp) + max(0, 1+max(R)-min(L))
    else:
        AB = [[max(0, 1+r-lp), max(0, 1+rq-l)] for l, r in LR]
        AB.sort(key=lambda x: (x[0], -x[1]))
        A, B = zip(*AB)
        for i in range(1, n):
            ret = max(ret, min(A[i:]) + min(B[:i]))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    LR = [tuple(map(int, a.split())) for a in args[1:]]
    L, R = zip(*LR)

    ret = 0

    p, q = np.argmax(L), np.argmin(R)
    lp, rq = L[p], R[q]

    ret = max(0, 1+rq-lp) + max(0, max(1+r-l for l, r in LR))

    AB = [[max(0, 1+r-lp), max(0, 1+rq-l)] for l, r in LR]
    AB.sort(key=lambda x: (x[0], -x[1]))
    A, B = map(list, zip(*AB))

    # for i in range(1, n):
    #     ret = max(ret, min(A[i:]) + min(B[:i]))
    b_min = 1+10**9
    for i in range(n-1):
        b_min = min(b_min, B[i])
        ret = max(ret, b_min + A[i+1])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

def unable():
    print(-1)
    exit()

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

if any(ai>bi for ai, bi in zip(a,b)):
    unable()

from heapq import heappop, heappush
heap = []
for i, bi in enumerate(b):
    heappush(heap, (-bi, i))

ans = 0
done = set()
while heap and len(done) != n:
    _, cur = heappop(heap)
    prv = (cur-1)%n
    nxt = (cur+1)%n
    base = b[prv]+b[nxt]
    cnt1, mod = divmod(b[cur], base)
    if cnt1 == 0:
        if b[cur] == a[cur]:
            done.add(cur)
        continue
    if mod > a[cur]:
        ans += cnt1
        b[cur] = mod
    else:
        cnt2, mod = divmod(b[cur]-a[cur], base)
        if mod != 0:
            unable()
        ans += cnt2
        done.add(cur)
        b[cur] = a[cur]
    heappush(heap, (-b[prv], prv))
    heappush(heap, (-b[nxt], nxt))

if len(done)==n:
    print(ans)
else:
    unable()


### FIXED CODE ###

import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def unable():
    print(-1)
    exit()

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

from heapq import heappush, heappop
h = []
base = 10**6
for i in range(n):
    if a[i]>b[i]:
        unable()
    else:
        heappush(h, -(b[i]*base+i))

ans = 0
while h:
    k = heappop(h)
    i = -k%base
    cnt, mod = divmod(b[i]-a[i],b[i-1]+b[(i+1)%n])
    if cnt == 0:
        if mod != 0:
            unable()
    else:
        ans += cnt
        b[i] = a[i]+mod
        heappush(h, -(b[i]*base+i))
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

#f = open("/Users/naoki/Documents/Atcoder/input.txt")
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

select_num = N//2


Dp = [[[-9999 for _ in range(2)] for _ in range(N+1)] for _ in range(N+1)]

for i in range(1,N+1):
    Start = (i-1)//2
    End = (i+1)//2
    
    for j in range(Start,End+1):
        Dp[i][j][0] = max(Dp[i-1][j][1], Dp[i-1][j][0])   
        # [0] in 3rd dimension  not chosen at last num
        # must be transfered from [i-1]
    for j in range(Start,End+1):
        if Dp[i-1][j-1][0] == -9999 and j == 1:
            Dp[i][j][1] = 0 + A[i]
        else:
            Dp[i][j][1] = Dp[i-1][j-1][0]+A[i]

print(max(Dp[-1][select_num][0], Dp[-1][select_num][1]))


### FIXED CODE ###


#f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

select_num = N//2
inf = -10e+100

Dp_f = [[inf] * (3) for _ in range(N+1)]
Dp_s = [[inf] * (3) for _ in range(N+1)]
# 3　次元はそれぞれStart~3つに該当

pre_margin = 0
for i in range(1,N+1):
    Start = (i-1)//2
    End = (i+1)//2
    
    cur_margin = Start
    
    for j in range(Start,End+1):
        Dp_f[i][j-cur_margin] = max(Dp_s[i-1][j-pre_margin], Dp_f[i-1][j-pre_margin])   
        # [0] in 3rd dimension  not chosen at last num
        # must be transfered from [i-1]
    for j in range(Start,End+1):
        if j-1 == 0:
            Dp_s[i][j-cur_margin] = 0 + A[i]
        else:
            Dp_s[i][j-cur_margin] = Dp_f[i-1][j-1-pre_margin]+A[i]
    
    pre_margin = cur_margin
print(max(Dp_f[-1][select_num - cur_margin], Dp_s[-1][select_num - cur_margin]))
### BUGGY CODE ###

def f(n):
    count = 0
    for x in range(1,n):
        for y in range(1,n-x):
            for z in range(1,n-x-y):
                if x**2 + y ** 2 + z**2 + x*y + y*z + z*x == n:
                    count = count + 1
    return count

N = int(input())
for x in range(0,N):
    print(f(x+1))


### FIXED CODE ###

N = int(input())
ans = [0]*(N+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            num = x*x + y*y + z*z + x*y + y*z + z*x
            if num>N:
                break
            ans[num] = ans[num] + 1
for m in ans[1:]:
    print(m)
### BUGGY CODE ###

import itertools

A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []

for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]
    ans.append(a[x[i] - 1] + b[y[i] - 1] - c[i])

a = set(a)
b = set(b)
temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)

print(min(ans))

### FIXED CODE ###

A, B, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = [0] * M
y = [0] * M
c = [0] * M

ans = []
ans.append(min(a) + min(b))
for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

for i in range(M):
    ans.append(a[x[i] - 1] + b[y[i] - 1] - c[i])

print(min(ans))
### BUGGY CODE ###

def d_lucky_pin():
    N = int(input())
    S = input()

    # 暗証番号を全探索
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_searching = 0

        for ch in S:
            if ch == pin[current_searching]:
                current_searching += 1
            if current_searching == 3:
                ans += 1
                break
    return ans

print(d_lucky_pin())

### FIXED CODE ###

def d_lucky_pin():
    N = int(input())
    S = input()

    # 暗証番号を全探索
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_searching = 0

        for ch in S:
            if ch == pin[current_searching]:
                current_searching += 1
            if current_searching == 3:
                ans += 1
                break
    return ans

print(d_lucky_pin())
### BUGGY CODE ###

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

data = []
for i in range(M):
  a,b = list(map(int,input().split()))
  if a == 1:
    if b in data:
      print("POSSIBLE")
      break
    else:
      data.append(b)
  if b == N:
    if a in data:
      print("POSSIBLE")
      break
    else:
      data.append(a)
else:
  print("IMPOSSIBLE")


### FIXED CODE ###

import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()

data = [0]*N
for i in range(M):
  a,b = IL()
  if a == 1:
    if data[b]==1:
      print("POSSIBLE")
      break
    else:
      data[b]=1
  if b == N:
    if data[a]==1:
      print("POSSIBLE")
      break
    else:
      data[a]=1
else:
  print("IMPOSSIBLE")
### BUGGY CODE ###

#ABC164d
s = str(input())
S = int(s)
s = list(s)

for i in range(len(s)):
    s[i] = int(s[i])

ans = 0
T = 0

for i in range(len(s)):
    for j in range(i+4,len(s)):
        t = s[i:j+1]
        for i2 in range(len(t)):
            T += t[i2] * 10**(len(t)-1-i2)
        if T%2019==0 and T != 0:
            ans += 1
        T = 0
print(ans)


### FIXED CODE ###

#ABC164d
def main():
    s = input()
    MOD = 2019
    d = [ 0 for i in range(MOD)]
    # print(d)
    ans = 0
    k = 0
    d[0] = 1
    s = s[::-1]
    # print(s)
    p = 1
    for i in s:
        # print(p,i,k)
        # print('pnosiki')
        # print(p * int(i) + k)
        k = (p * int(i) + k) % MOD
        # print('k:')
        # print(k)
        ans += d[k]
        d[k] += 1
        p = (p * 10) % MOD
    print(ans)
    return

if __name__ == "__main__":
    main()
### BUGGY CODE ###

p = int(input())
a = list(map(int,input().split()))
b = [0]*p
fact = [1]*(p+1)
for i in range(p):
    fact[i+1] = (i+1)*fact[i]
    fact[i+1] %= p
factinv = [1]*p
for i in range(p):
    factinv[i] = pow(fact[i],p-2,p)

for i in range(1,p):
    if a[i]==1:
        for j in range(1,p):
            b[j] += pow(i,(p-2)*j,p)*pow(p-1,p-1-i,p)*factinv[i]*factinv[p-1-i]
            b[j] %= p

if a[0]==1:
    b[0] += 1
    b[0] %= p
    b[p-1] += p-1
    b[p-1] %= p

print(*b)

### FIXED CODE ###

p = int(input())
A = [[1]*p for _ in range(p)]
a = list(map(int,input().split()))
for n in range(p):
    for m in range(p-1):
        A[n][m+1] = n*A[n][m]%p

c = [0]*p
f = [1]*p

for n in range(1,p):
    f[n] = n*f[n-1]%p

for m in range(p):
    c[m] = f[p-1]*pow(f[m],p-2,p)*pow(f[p-1-m],p-2,p)%p

b = [0]*p

for n in range(p):
    if a[n] == 0:
        continue
    b[0] += 1
    b[0] %= p
    for m in range(p):
        b[m] -= A[n][p-1-m]*c[m]*(1-(m%2)*2)
        b[m] %= p

print(' '.join([str(x) for x in b]))
### BUGGY CODE ###

k=int(input())

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            ni=math.gcd(n, i)
            res+=math.gcd(ni,j)

print(res)

### FIXED CODE ###

k=int(input())

from math import gcd
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=gcd(gcd(n,i),j)

print(res)
### BUGGY CODE ###

def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(1, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.append(lst[0])
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = quicksort(drinklist)

sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

### FIXED CODE ###

from operator import itemgetter

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = sorted(drinklist, key=itemgetter(0))
sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum
### BUGGY CODE ###

N = int(input())

for n in range(1, N + 1)[::-1]:
    if n * n <= N:
        print(str(n * n))
        break
    else:
        pass


### FIXED CODE ###

import numpy as np
N = int(input())

ans = int(np.sqrt(N))
print(ans ** 2)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)

n=int(input())
L=list(map(int,input().split()))
A = L.count(1)
B = L.count(2)
C = L.count(3)
dp=[[[-1] * (301) for i in range(301)] for i in range(301)]


def rec (a,b,c):
  if not (a >= 0 and b >= 0 and c >= 0):
    return 0
  if a == b == c == 0:
    return 0
  if dp[a][b][c] != -1:
    return dp[a][b][c]
  result = n
  result += rec(a-1,b,c) * a
  result += rec(a+1,b-1,c) * b
  result += rec(a,b+1,c-1) * c
  dp[a][b][c] = result / (a+b+c)
  return dp[a][b][c]

print(rec(A,B,C))



### FIXED CODE ###

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

S = [0] * 3
for a in A:
  S[a-1] += 1
I, J, K = S

dp = [[[0.0] * (N+1) for j in range(N+1)] for i in range(N+1)]

for k in range(S[2] + 1):
  for j in range(S[1] + S[2] - k + 1):
    for i in range(S[0] + S[1] + S[2] - j - k + 1):
      if i == j == k == 0: continue
      dp[i][j][k] = (i * (dp[i-1][j][k] if i > 0 else 0) + j * (dp[i+1][j-1][k] if j > 0 else 0) + k * (dp[i][j+1][k-1] if k > 0 else 0) + N) / (i + j + k)

print(dp[I][J][K])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n, m = [int(i) for i in input().split()]
fibo_l = [1] + [0] * n
a = [int(input()) for i in range(m)]
for i in a:
    fibo_l[i] = None

def fibo(x):
    if x >= 0 and fibo_l[x] is not None:
        if fibo_l[x] == 0:
            fibo_l[x] = fibo(x-1) % 1000000007 + fibo(x-2) % 1000000007
        return fibo_l[x]
    else: return 0

print(fibo(n) % 1000000007)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n, m = [int(i) for i in input().split()]
fibo_l = [1] + [None] * n
a = set([int(input()) for i in range(m)])

def fibo(x):
    if x not in a and x >= 0:
            if fibo_l[x] is None:
                fibo_l[x] = fibo(x-1) % 1000000007 + fibo(x-2) % 1000000007
            return fibo_l[x]
    else: return 0
    
print(fibo(n) % 1000000007)
### BUGGY CODE ###

import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
	
k, s = [int(x) for x in input().split()]

count=0
for x in range(k+1):
	for y in range(k+1):
		for z in range(k+1):
			if x+y+z == s:
				count+=1
print(count)

### FIXED CODE ###

k, s = [int(x) for x in input().split()]

count=0
for x in range(k+1):
    for y in range(k+1):
        if (s-(x+y) <= k and s-(x+y) >=0):
            count+=1
print(count)
### BUGGY CODE ###

import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    # right = 10**9
    right = max(dams) * 2
    while True:
        center = (left + right) // 2
        if center % 2 == 1:
            center -= 1
        mountains[0] = center
        for i in range(1, n):
            mountains[i] = 2 * dams[i-1] - mountains[i-1]
        temp_dam = (mountains[0] + mountains[-1]) / 2
        if dams[-1] == temp_dam:
            break
        elif dams[-1] < temp_dam:
            right = center
        else:
            left = center
    ans = ' '.join(map(str, mountains))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math

def main():
    n = int(input())
    dams = list(map(int, input().split()))
    mountains = [0] * n
    left = 0
    # right = 10**9
    right = (max(dams)+1) * 2
    while True:
        center = (left + right) // 2
        if center % 2 == 1:
            center -= 1
        mountains[0] = center
        for i in range(1, n):
            mountains[i] = 2 * dams[i-1] - mountains[i-1]
        temp_dam = (mountains[0] + mountains[-1]) // 2
        if dams[-1] == temp_dam:
            break
        elif dams[-1] < temp_dam:
            right = center
        else:
            left = center
    ans = ' '.join(map(str, mountains))
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

def binaryinsertion(A,x):
    left=0;right=len(A)-1
    while(True):
        if (len(A)==0) :
            A.append(x)
            break
        centre = left + (right-left)//2 - 1
        if(right - left < 2):
            if(x[0]<A[left][0]):A.insert(left,x)
            else :
                if(x[0]<A[right][0]):A.insert(right,x)
                else:A.insert(right+1,x)
            break
        else:
            if(x[0] < A[centre][0]) :
                right = centre - 1
            elif(A[centre][0] < x[0]) :
                left = centre + 1
            else : 
                A.insert(centre,x)
                break

[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
sweep = A[:L]
sweep = sorted(sweep)
ans = [str(sweep[0][0])]
for i in range(L,N) :
    sweep.remove(A[i-L])
    binaryinsertion(sweep,A[i])
    ans.append(str(sweep[0][0]))
print(" ".join(ans))

### 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])