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

from itertools import permutations

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

INF = float('inf')
graph = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C

for i in range(N):
    graph[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
            graph[j][i] = min(graph[j][i], graph[j][k] + graph[k][i])

ans = 10**9
for p in permutations(r, len(r)):
    dist = 0
    flag = 0
    for i in range(len(r) - 1):
        if graph[p[i]-1][p[i+1]-1] == INF:
            flag = 1
            continue
        dist += graph[p[i]-1][p[i+1]-1]
    if flag == 0:
        ans = min(ans, dist)

print(ans)

### FIXED CODE ###

from itertools import permutations

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

INF = float('inf')
graph = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C

for i in range(N):
    graph[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
            graph[j][i] = min(graph[j][i], graph[j][k] + graph[k][i])

ans = 10**9
for p in permutations(r, len(r)):
    dist = 0
    flag = 0
    for i in range(len(r) - 1):
        if graph[p[i]-1][p[i+1]-1] == INF:
            flag = 1
            continue
        dist += graph[p[i]-1][p[i+1]-1]
    if flag == 0:
        ans = min(ans, dist)

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

import fractions
A, B = map(int, input().split())
C = fractions.gcd(A, B)
ans = 1
primes = [2]

if C % 2 == 0:
  ans += 1
  while C % 2 == 0:
    C //= 2

p = 3
while C > 1:
  for prime in primes:
    if p % prime == 0:
      p += 2
      continue
  primes.append(p)
  if C % p == 0:
    ans += 1
  while C % p == 0:
    C //= p
  p += 2
print(ans)

### FIXED CODE ###

import fractions
import math

A, B = map(int, input().split())
C = fractions.gcd(A, B)
pfac = []

def get_primes(n):
  primes = [2]
  for i in range(3, (n+1), 2):
    for p in primes:
      if i % p == 0:
        break
      if i < p ** 2:
        primes.append(i)
        break
    else:
      primes.append(i)
  return primes

def get_primes2(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n == 1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

for q in get_primes2(min(C, 10**6)):
  if q ** 2 > C:
    break
  if C % q == 0:
    pfac.append(q)
    while C % q == 0:
      C //= q
if C != 1:
  pfac.append(C)


print(len(pfac) + 1)
### BUGGY CODE ###

N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dis_lis = {i:0 for i in range(1, N+1)}
for i in range(N):
    for j in range(N):
        if i==j: continue
        if abs(i-j)==1:
            dis_lis[1] += 1
        else:
            min1 = abs(i-j)
            min2 = abs(i-X)+abs(j-Y)+1
            min3 = abs(i-Y)+abs(j-X)+1
            dis_lis[min(min1, min2, min3)] += 1
for i in range(1, N):
    print(dis_lis[i]//2)

### FIXED CODE ###

from collections import deque
from collections import Counter
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
dis_lis = deque()
for i in range(N-1):
    for j in range(i+1, N):
        if abs(i-j)==1:
            dis_lis.append(1)
        else:
            min1 = abs(i-j)
            min2 = abs(i-X)+abs(j-Y)+1
            min3 = abs(i-Y)+abs(j-X)+1
            dis_lis.append(min(min1, min2, min3))
c = Counter(dis_lis)
for i in range(1, N):
    print(c[i])
### BUGGY CODE ###

from collections import defaultdict


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

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

arr = [x - k for x in arr]
arr.sort()

arr_minus = [-x for x in arr if x < 0]
arr_zero = sum(x==0 for x in arr)
arr_plus = [x for x in arr if x > 0]

minus_nums = defaultdict(int)

for i in range(1, 2 ** len(arr_minus)):
    bin_minus = "{:050b}".format(i)[::-1]
    item = sum(x for idx, x in enumerate(arr_minus) if bin_minus[idx] == "1")
    minus_nums[item] += 1

cnt = 0
for i in range(1, 2 ** len(arr_plus)):
    bin_plus = "{:050b}".format(i)[::-1]
    item = sum(x for idx, x in enumerate(arr_plus) if bin_plus[idx] == "1")
    cnt += minus_nums[item]

print((1 + cnt) * 2 ** arr_zero - 1)

### FIXED CODE ###

from collections import defaultdict

n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = [x - k for x in arr]

dct = defaultdict(int)
dct[0] = 1

for x in arr:
    for k, v in list(dct.items()):
        dct[k + x] += v

print(dct[0] - 1)
### BUGGY CODE ###

from collections import defaultdict


def mod_inv(a, m):
    return pow(a, m-2, m)


MOD = 10**9+7
MX = 10**6+5
N = int(input())
A = list(map(int, input().split()))


P = defaultdict(int)

for a in set(A):
    e = defaultdict(int)
    rest = a
    for i in range(2, a + 1):
        while rest % i == 0:
            e[i] += 1
            rest //= i
    for k, v in e.items():
        P[k] = max(P[k], v)

lcm = 1
for k, v in P.items():
    lcm *= k ** v
    lcm %= MOD

ans = 0
for a in A:
    ans += lcm * mod_inv(a, MOD)
    ans %= MOD

print(int(ans))


### FIXED CODE ###

from fractions import gcd

mod = 10 ** 9 + 7

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

lcm = 1
for s in A:
    lcm = s * lcm // gcd(lcm, s)

ans = lcm * sum([pow(s, mod - 2, mod) for s in A]) % mod

print(int(ans % mod))
### BUGGY CODE ###

S = list(input())
Q = int(input())
Flag = True
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        Flag = False if Flag else True
    else:
        if Flag:
            if q[1] == '1':
                S = [q[2]] + S
            else:
                S = S + [q[2]]
        else:
            if q[1] == '1':
                S = S + [q[2]]
            else:
                S = [q[2]] + S
if Flag:
    print(''.join(S))
else:
    print(''.join(reversed(S)))

### FIXED CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
Flag = True
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        Flag = False if Flag else True
    else:
        if Flag:
            if q[1] == '1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == '1':
                S.append(q[2])
            else:
                S.appendleft(q[2])

if Flag:
    print(''.join(S))
else:
    print(''.join(reversed(S)))
### BUGGY CODE ###

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
prev_char = ""

for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = 1

for i, item in enumerate(lr):
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A" and item[1] != n:
    if s[item[1]] == "C":
      ans -= 1
  print(ans)
         
  

### FIXED CODE ###

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
hb = n * (n - 1) // 2
result = [hb]
leder = [i for i in range(1, n + 1)]
size = [1 for i in range(n)]
for brk in ab[:0:-1]:
    if size[leder[brk[0] - 1] - 1] < size[leder[brk[1] - 1] - 1]:
        brk = brk[::-1]
    if leder[brk[0] - 1] != leder[brk[1] - 1]:
        hb -= size[leder[brk[0] - 1] - 1] * size[leder[brk[1] - 1] - 1]
        size[leder[brk[0] - 1] - 1] += size[leder[brk[1] - 1] - 1]
        size[leder[brk[1] - 1] - 1] = 0
    result.append(hb)
    leder = [i if i != leder[brk[1] - 1] else leder[brk[0] - 1] for i in leder]
for i in result[::-1]:
    print(i)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

# 辞書作成
s_list = list(set(s))
s_dict = {}
for i in range(len(s_list)):
    s_dict[s_list[i]] = 0

# カウント
for i in range(len(s)):
    s_dict[s[i]] += 1

# 最大値のkeyのみリスト化
max_s_list = [kv[0] for kv in s_dict.items() if kv[1] == max(s_dict.values())]
# ソート
max_s_list.sort(key=lambda x: x[0])
print(*max_s_list, sep="\n")

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

# 辞書作成
s_dict = dict()
for i in s:
    if i not in s_dict:
        s_dict[i] = 1
    else:
        s_dict[i] += 1

m = max(s_dict.values())
ans = []
for k, v in s_dict.items():
    if v == m:
        ans.append(k)
ans.sort()
# ソート
print(*ans, sep="\n")
### BUGGY CODE ###

s=input()
while("ST" in s):
  s=s.replace("ST","",1)
print(len(s))


### FIXED CODE ###

s=input()
n=len(s)
sta=[]
for i in range(n):
  if(s[i]=="S"):
    sta.append("S")
  else:
    if(len(sta)==0 or sta[-1]=="T"):sta.append("T")
    else:sta.pop()
print(len(sta))
### BUGGY CODE ###

s = list(input())
t = list(input())
pair = []
ans = "Yes"

def check(pair,i,s,t):
    for j in range(len(pair)):
        if s!=pair[j][0] and s!=pair[j][1] and t!=pair[j][0] and t!=pair[j][1]:
            pass
        elif s==pair[j][0] and t==pair[j][1]:
            pass
        elif s==pair[j][1] or t==pair[j][0]:
            pass
        else:
            return False
    return True

def check2(pair,i,s,t):
    for j in range(len(pair)):
        if (s==pair[j][0] and t!=pair[j][1])or(s!=pair[j][0] and t==pair[j][1]):
            return False
    return True

for i in range(len(s)):
    if check2(pair,i,s[i],t[i]):
        pair.append([s[i],t[i]])
    else:
        ans = "No"
        break

print(ans)


### FIXED CODE ###

s = list(input())
t = list(input())
pair = []
li =[]
ans = "Yes"

for i in range(len(s)):
    if [s[i],t[i]] in li:
        pass
    else:
        li.append([s[i],t[i]])

def check2(pair,i,li):
    for j in range(len(pair)):
        if (li[i][0]==pair[j][0] and li[i][1]!=pair[j][1])or(li[i][0]!=pair[j][0] and li[i][1]==pair[j][1]):
            return False
    return True

for i in range(len(li)):
    if check2(pair,i,li):
        pair.append([li[i][0],li[i][1]])
    else:
        ans = "No"
        break

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

N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
max_list=[]
max_tmp = 0
ans = 0
for i in range(N-K+1):
    tmp = sum(P[i:i+K])
    if tmp > max_tmp:
        max_list=P[i:i+K]
        max_tmp = tmp
for i in max_list:
    ans += (i+1)/2
print(ans)

### FIXED CODE ###

N,K=map(int,input().split(' '))
P=list(map(int,input().split(' ')))
tmp = sum([(i+1)/2 for i in P[:K]])
ans = tmp
for i,j in zip(P,P[K:]):
    tmp +=(j+1)/2-(i+1)/2
    ans = max(ans,tmp)
print(ans)
### BUGGY CODE ###

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = 0
mod = 10 ** 9 + 7
m=A[0]
for i in range(61):
    cnt0 = cnt1 = 0
    if m < 2 ** i:
        break
    for j, a in enumerate(A):
        if a < 2 ** i:
            cnt0 += n - j
            break
        if (a >> i) & 1:
            cnt1 += 1
        else:
            cnt0 += 1
    ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
    ans %= mod

print(ans)


### FIXED CODE ###

def main():
    n = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = 0
    mod = 10 ** 9 + 7
    m=A[0]
    for i in range(61):
        cnt0 = cnt1 = 0
        if m < 2 ** i:
            break
        for j, a in enumerate(A):
            if a < 2 ** i:
                cnt0 += n - j
                break
            if (a >> i) & 1:
                cnt1 += 1
            else:
                cnt0 += 1
        ans += (((2 ** i) % mod) * ((cnt1 * cnt0) % mod)) % mod
        ans %= mod

    print(ans)

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

N=int(input())
arr=[]
for i in range(N):
    arr.append(input())
s=sorted(set(arr))
max_s = max(arr.count(ele)for ele in s)
for ele in s:
    if arr.count(ele)==max_s:
        print(ele)

### FIXED CODE ###

from collections import Counter
N = int(input())
arr = []
arr_max = []
for i in range(N):
    arr.append(input())
dic = Counter(arr)
inverse = [(value, key) for key, value in dic.items()]
max_s = max(inverse)[0]
for key,value in dic.items():
    if value == max_s: 
        arr_max.append(key)
    else: continue
for j in sorted(arr_max): print (j)
### BUGGY CODE ###

import sys
import math
import statistics
import heapq

N, K = map(int, input().split())
Ai = list(map(int, input().split()))

def segfunc(x, y):
    # print("mult({}, {})".format(x, y))
    return x * y

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

seg = SegTree(Ai, segfunc, 1)
# print(seg.query(0, 1))

def score(i):
    return seg.query(i - K, i)

for i in range(K + 1, N + 1):
    sp = score(i - 1)
    s = score(i)

    if sp < s:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

N, K = map(int, input().split())
Ai = list(map(int, input().split()))

# class SegTree:
#     def __init__(self, init_val, f=lambda x,y : x*y, default=1):
#         size = len(init_val)
#         self.size = 2**(size-1).bit_length()
#         self.default = default
#         self.dat = [default]*(self.size*2)
#         self.f = f
#
#         for i in range(size):
#             self.dat[self.size + i] = init_val[i]
#         for i in range(self.size- 1, 0, -1):
#             self.dat[i] = self.f(self.dat[2 * i], self.dat[2 * i + 1])
#
#     def update(self, i, x):
#         i += self.size
#         self.dat[i] = x
#         while i > 0:
#             i >>= 1
#             self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
#
#     def query(self, l, r):
#         l += self.size
#         r += self.size
#         lres, rres = self.default, self.default
#         while l < r:
#             if l & 1:
#                 lres = self.f(lres, self.dat[l])
#                 l += 1
#
#             if r & 1:
#                 r -= 1
#                 rres = self.f(self.dat[r], rres)
#             l >>= 1
#             r >>= 1
#         res = self.f(lres, rres)
#         return res
#
# seg = SegTree(Ai)
# print(seg.query(0, 1))

# def score(i):
#     return seg.query(i - K, i)

for i in range(K + 1, N + 1):
    # sp = score(i - 1)
    # s = score(i)

    sp = Ai[i - K - 1]
    s = Ai[i - 1]

    if sp < s:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n = int(input())
s = input()

pins = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        pins.append(str('00')+i)
    elif len(i) == 2:
        pins.append(str('0')+i)
    else:
        pins.append(i)

ans = 0
for pin in pins:
    c = 0
    for i in s:
        if pin[c] == i:
            c += 1
        if c == 3:
            ans += 1
            break

print(ans)

### FIXED CODE ###

n = int(input())
s = input()

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

import numpy as np
import math
n, m = map(int, input().split())
sum = 0
a = np.array(list(map(int, input().split())))
for i in range(m):
    a[a.argmax()] /= 2
for j in range(n):
    sum += a[j] // 1
print(sum)

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)
for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))
### BUGGY CODE ###

import heapq
def main():
    N, Q = map(int, input().split())
    ls = []
    lt = []
    for _ in range(N):
        s, t, x = map(int, input().split())
        ls.append((s-x, x))
        lt.append((t-x, x))
    ls.sort(reverse=True)
    lt.sort(reverse=True)
    dh = []
    dl = []
    for i in range(Q):
        d = int(input())
        while ls and ls[-1][0] <= d:
            s, x = ls.pop()
            heapq.heappush(dl, x)
        while lt and lt[-1][0] <= d:
                t, x = lt.pop()
                heapq.heappush(dh, x)
        while dl and dh and dl[0] == dh[0]:
            heapq.heappop(dl)
            heapq.heappop(dh)
        if not dl:
            print('-1')
        else:
            print(dl[0])
main()


### FIXED CODE ###

import heapq
def main():
    N, Q = map(int, input().split())
    l = []
    for _ in range(N):
        s, t, x = map(int, input().split())
        l.append((s-x, 1, x))
        l.append((t-x, 0, x))
    for i in range(Q):
        d = int(input())
        l.append((d, 2, i))
    r = [-1] * Q
    l.sort()
    h = []
    se = set()
    for a, b, c in l:
        if b == 0:
            se.remove(c)
        elif b == 1:
            se.add(c)
            heapq.heappush(h, c)
        else:
            while h and h[0] not in se:
                heapq.heappop(h)
            r[c] = h[0] if h else -1
    print('\n'.join(map(str, r)))
            
main()
### BUGGY CODE ###

import bisect
import collections

n, m = map(int, input().split())
py_dict = collections.defaultdict(list)
cityi_by_year = []
for i in range(m):
  p, y = map(int, input().split())
  py_dict[p].insert(bisect.bisect_left(py_dict[p],y),y)
  cityi_by_year.append([p,y])
  
for p, y in cityi_by_year:
  idx = bisect.bisect_left(py_dict[p],y)
  print('0'*(6-len(str(p))) + str(p) + '0'*(6-len(str(idx+1))) + str(idx+1))


### FIXED CODE ###

import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))
### BUGGY CODE ###

from itertools import combinations
N,K = map(int,input().split())
x = list(map(int,input().split()))
cand = list(combinations(x, K))
ans = float('inf')
for i in range(len(cand)):
  l = cand[i][0]
  r = cand[i][-1]
  temp = min(abs(l)+abs(r-l),abs(r)+abs(l-r))
  ans = min(temp,ans)

print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = float('inf')
for i in range(N-K+1):
  l = x[i]
  r = x[i+K-1]
  temp = min(abs(l)+abs(r-l),abs(r)+abs(l-r))
  ans = min(temp,ans)

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

import sys
sys.setrecursionlimit(10 ** 6)


def dfs(x, y, memo, A, N, Z, W):
    X = Z if x == 0 else A[x - 1]
    Y = W if y == 0 else A[y - 1]

    if memo[x][y] >= 0:
        return memo[x][y]
    else:
        if x == N or y == N:
            rst = abs(X - Y)
        else:
            if x <= y:
                rst = 0
                for i in range(y + 1, N + 1):
                    rst = max(rst, dfs(i, y, memo, A, N, Z, W))
            else:
                rst = 10 ** 10
                for i in range(x + 1, N + 1):
                    rst = min(rst, dfs(x, i, memo, A, N, Z, W))
        memo[x][y] = rst
        return rst


def main():
    # import sys
    # readline = sys.stdin.readline
    # readlines = sys.stdin.readlines

    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    memo = [[-1] * (N + 1) for _ in range(N + 1)]
    ans = dfs(0, 0, memo, A, N, Z, W)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
dp = [[-1] * (N + 1) for _ in range(N + 1)]

for x in range(N, -1, -1):
    for y in range(N, -1, -1):
        if x == y:
            continue
        X = Z if x == 0 else A[x - 1]
        Y = W if y == 0 else A[y - 1]
        if x == N or y == N:
            rst = abs(X - Y)
        elif x - y == 1:
            rst = 10 ** 10
            for j in range(N, x, -1):
                rst = min(rst, dp[x][j])
        elif x - y > 1:
            rst = dp[x][y + 1]
        elif y - x == 1:
            rst = 0
            for i in range(N, y, -1):
                rst = max(rst, dp[i][y])
        elif y - x > 1:
            rst = dp[x + 1][y]
        else:
            raise Exception
        dp[x][y] = rst

ans = 0
for i in range(N):
    ans = max(ans, dp[i + 1][0])
print(ans)
### BUGGY CODE ###

import heapq
def SME(start,end):
    if end > N : end = N
    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]
                    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 not in ANS[i:i+50] :
            i += 50
            continue
        if ANS[i] : continue
        else: ANS[i] = min(Whole[i+1-L:i+1])
        i+=1
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.999
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])