Harryxun/stf_run huggingface dataset:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
x.sort()
print(math.gcd(x[0],x[1]))


### FIXED CODE ###

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2,N):
    ans=gcd(x[i],ans)
print(ans)
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = raw_input().split()
  u = int(str[0])
  k = int(str[1])
  for j in range(k):
    v = int(str[2+j])
    c = int(str[3+j])
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]

d[0] = 0
color[0] = 1

while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
    print minv
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '-1'

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
A = int(input())
B = int(input())


if A > B:
    print(A + A - 1)

elif A == B:
    print(A + B)

else:
    print(B + B -1)

### FIXED CODE ###

button = input().split()
A = int(button[0])
B = int(button[1])


if A > B:
    print(A + A - 1)

elif A == B:
    print(A + B)

else:
    print(B + B -1)
A, B = map(int, input().split())
list = [300000,200000,100000,0]
if(A>3):
    A = 4
elif(B>3):
    B = 4
money = list[A-1]+list[B-1]
if(A==1 and B==1):
    money = 1000000
print(money)


### FIXED CODE ###

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

list = [500000,300000,200000,100000,0]

if(A>3):
    A = 4
if(B>3):
    B = 4
elif(A==1 and B==1):
    A=B=0
money = list[A]+list[B]
print(money)
S, T = list(map(str, input().split()))

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

S = list(map(str, input().split()))[0]
T = list(map(str, input().split()))[0]

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")
n = ii()
m = int(((n-1)*n)/2)
print(m)

### FIXED CODE ###

n = int(input())
m = int(((n-1)*n)//2)
print(m)
import bisect

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]


for i in range(Q):

    insert_index = bisect.bisect_left(s,x[i])
    if insert_index >= A:
        insert_index = insert_index -1
        tmp1 = s[insert_index]
        tmp2 = s[insert_index]
        
    elif insert_index == 0:
        tmp1 = s[insert_index]
        tmp2 = s[insert_index]
    else:   
        tmp1 = s[insert_index]
        tmp2 = s[insert_index-1]
    
    insert_index = bisect.bisect_left(t,x[i])
    if insert_index >= B or insert_index == 0:
        insert_index = insert_index -1
        tmp3 = t[insert_index]
        tmp4 = t[insert_index]
        
    elif:
        tmp1 = t[insert_index]
        tmp2 = t[insert_index]
        
    else:
        tmp3 = t[insert_index]
        tmp4 = t[insert_index-1]
    
    result = 10 ** 11
    for j, k in ([0,1], [0,0], [1,0], [1,1]):
        tmp = 0
        if j == 0:
            tmp += abs(tmp1 - x[i])
            now = tmp1
        else:
            tmp += abs(tmp2 - x[i])
            now = tmp2
                
        if k == 0:
            tmp += abs(now - tmp3)
        else:
            tmp += abs(now - tmp4)
                
        result = min(tmp, result)
                
    print(result)



### FIXED CODE ###

import bisect
import itertools

#n桁のm値のbitを生成
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]


for i in range(Q):

    insert_index = bisect.bisect_left(s,x[i])
    if insert_index >= A:
        insert_index = insert_index -1
        tmp1 = s[insert_index]
        tmp2 = s[insert_index]
        
    else:   
        tmp1 = s[insert_index]
        tmp2 = s[insert_index-1]
    
    insert_index = bisect.bisect_left(t,x[i])
    if insert_index >= B:
        insert_index = insert_index -1
        tmp3 = t[insert_index]
        tmp4 = t[insert_index]
        
    else:
        tmp3 = t[insert_index]
        tmp4 = t[insert_index-1]
    
    result = 10 ** 11
    for j, k in ([0,1], [0,0], [1,0], [1,1]):
        tmp = 0
        if j == 0:
            tmp += abs(tmp1 - x[i])
            now = tmp1
        else:
            tmp += abs(tmp2 - x[i])
            now = tmp2
                
        if k == 0:
            tmp += abs(now - tmp3)
        else:
            tmp += abs(now - tmp4)
                
        result = min(tmp, result)
        
    for j, k in ([0,1], [0,0], [1,0], [1,1]):
        tmp = 0
        
        if k == 0:
            tmp += abs(x[i] - tmp3)
            now = tmp3
        else:
            tmp += abs(x[i]- tmp4)
            now = tmp4
            
        if j == 0:
            tmp += abs(now - tmp1)
        else:
            tmp += abs(now - tmp2)
                
        result = min(tmp, result)
                
    print(result)
def main():
  import sys
  input = sys.stdin.readline
  n,w=map(int,input().split())
  wv=[tuple(map(int,input().split())) for _ in range(n)]
  dp=[[0]*(w+1) for _ in range(n+1)]
  for i in range(n):
    for j in range(w+1):
      dp[i+1][j]=max(dp[i][j-wv[i][0]]+wv[i][1],dp[i][j]) if j-wv[i][0]>=0 else dp[i][j]
  print(dp[n][w])
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  import sys
  input = sys.stdin.readline
  n,W=map(int,input().split())
  w,v=[0]*n,[0]*n
  for i in range(n):
    w[i],v[i]=map(int,input().split())
  v_sum=sum(v)
  dp=[[float('inf')]*(v_sum+1) for _ in range(n+1)]
  dp[0][0]=0
  for i in range(n):
    for j in range(v_sum+1):
      dp[i+1][j]=dp[i][j - v[i]] + w[i] if j - v[i]>=0 else dp[i+1][j]
      dp[i+1][j]=min(dp[i+1][j],dp[i][j])
  ans=0
  for j in range(v_sum+1):
    if dp[n][j] <= W:
      ans = j
  print(ans)
if __name__=='__main__':
  main()
N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)



### FIXED CODE ###

N = input().split()

N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])

if(N[0] == 1):
    if(N[1] == N[2]):
        print("1")
        exit()
    print("0")
    exit()

if(N[1] > N[2]):
    print("0")
    exit()

print((N[2] * (N[0] -1) + N[1]) - (N[1] * (N[0] - 1) + N[2]) + 1)
import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


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


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


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


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)


nums_cs = np.cumsum(nums)

if len(nums_cs) != 1:
       res = nums_cs[2*K-1]
else:
    res=nums_cs[0]

#print(res)
if s[0]==1:

    for i in range(1,len(nums_cs)-2*K-1):
        if i%2==0:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i-1])
else:    

    for i in range(1,len(nums_cs)-2*K-1):
        if i%2==1:
            res=max(res,nums_cs[i+2*K+1]-nums_cs[i])


print(res)


### FIXED CODE ###


import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


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


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


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


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[min(len(nums_cs)-1,2*K)]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K+1):
    if i % 2 == 0:
        #print(i)
        res = max(res, nums_cs[min(i+2*K,len(nums_cs)-1)]-nums_cs[i-1])


print(res)
n=int(input())
a=list(map(int,input().split())
print(max(a)-min(a))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
def GCDonBlack(N,A):
    #count = 0
    rem=[a%min(A) for a in A]
    if sum(rem) == 0:
        return min(A)
    else:
        for i in reversed(range(1,max(rem)+1)):
            count += 1
            bar = N-1
            for ele in A:
                if ele % i == 0:
                    bar -= 1
                if bar == 0:
                    #print("count:{}".format(count))
                    return i
N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))

### FIXED CODE ###

import fractions
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(fractions.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [fractions.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

N = int(input())
A = list(map(int, input().split()))
print(GCDonBlack(N,A))
k,n=map(int,input().split())
x=list(map(int,input().split()))

if n==1:
	res=0
else:
	y=sorted(x)
	z=[0]*(n-1)
	for i in range(n-1):
		z[i]=y[i+1]-y[i]
	v=sorted(z,reverse=True)
	w=0
	if k>1:
		for i in range(k-1):
			w+=v[i]
		res=y[n-1]-y[0]-w
	else:
		res=y[n-1]-y[0] 

print(res)

### FIXED CODE ###

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

if k>=n or n==1:
	res=0
else:
	y=sorted(x)
	z=[0]*(n-1)
	for i in range(n-1):
		z[i]=y[i+1]-y[i]
	v=sorted(z,reverse=True)
	w=0
	if k>1:
		for i in range(k-1):
			w+=v[i]
		res=y[n-1]-y[0]-w
	else:
		res=y[n-1]-y[0] 

print(res)
n = int(input())
h = list(map(int, input().split()))

dp = [10**18] * n

def rec(i):
    if dp[i] < 10**18:
        return dp[i]
    
    if i == 0:
        return 0
        
    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

print(rec(n-1))


### FIXED CODE ###

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

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(li[i] - li[i-1])
    else:
        dp[i] = min(abs(li[i] - li[i-1]) + dp[i-1], abs(li[i] - li[i-2]) + dp[i-2])

print(dp[-1])
while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break

    mf = m + f
    
    if m == -1 or f == -1 of mf < 30:
        print('F')
    elif mf < 50 and r < 50:
        print('D')
    elif mf < 65:
        print('C')
    elif mf < 80:
        print('B')
    else:
        print('A')

### FIXED CODE ###

while True:
    m, f, r = map(int, input().strip().split())
    if m == f == r == -1: break

    if m == -1 or f == -1 or m + f < 30:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50:
        print('C')
    elif m + f >= 30:
        print('C' if r >= 50 else 'D')
x=int(input())
print(x//3600,x//60%60,x%60)


### FIXED CODE ###

x=int(input())


print(x//3600,x//60%60,x%60,sep=':')
import itertools
N, K = list(map(int, input().split()))
d = []
A = [[0]]*N
for i in range(K):
    d.append(int(input()))
    A[i] = list(map(int, input().split()))

s = list(set((list(itertools.chain.from_iterable(A)))))
#print(s)
#s.pop(0)
#print(s)

S = list(range(1,N+1))
#print(S)

for i in range(len(s)):
    if s[i] == 0:
        s.remove(0)
        break

diff = list(set(S) - set(s))
#print(diff)
print(len(diff))

### FIXED CODE ###

import itertools
N, K = list(map(int, input().split()))
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))
#print(A) 
s = list(set((list(itertools.chain.from_iterable(A)))))
print(N - len(s))
#include<iostream>
using namespace std;
int main(){
    int r,c,t;
    t=0;
    cin>>r>>c;
    int R[c+1]={};
    int S[c+1]={};
    for (int i=0;i<r;i++){
        for(int x=0;x<c;x++){
            cin>>R[x];
            cout<<R[x]<<" ";
        }
        for(int x=0;x<c;x++){
            t+=R[x];
        }
    cout<<t<<endl;
    for(int b=0;b<c;b++){
        S[b]+=R[b];
    }
    R[c+1]={};
    t=0;
    }
    for(int x=0;x<c;x++){
        cout<<S[x]<<" ";
        S[c]+=S[x];
    }
    cout<<S[c]<<endl;    
}


### FIXED CODE ###

i,j=map(int,input().split())
listA=[]
for n in range(i):
    listA.append(list(map(int,input().split())))
    listA[n].append(sum(listA[n]))
listA.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=listA[m][n]
    listA[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,listA[n])))
def count_word(words, word):
    count = 0

    for w in words:
        if w == word:
            count += 1

    return count

n = int(input())

words = []
for i in range(n):
    words.append(input())

bind_letter = ""
for word in words:
    matches = count_word(words, word)
    if matches >= 2:
        print("No")
        exit()

    if bind_letter != "":
        if word[0] != bind_letter:
            print("No")
            exit()
    bind_letter = word[len(word) - 1]
    
p

### FIXED CODE ###

def count_word(words, word):
    count = 0

    for w in words:
        if w == word:
            count += 1

    return count

n = int(input())

words = []
for i in range(n):
    words.append(input())

bind_letter = ""
for word in words:
    matches = count_word(words, word)
    if matches >= 2:
        print("No")
        exit()

    if bind_letter != "":
        if word[0] != bind_letter:
            print("No")
            exit()
    bind_letter = word[len(word) - 1]
    
print("Yes")
from fractions import gcd
from functools import reduce
# from collections import deque
# from math import factorial
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
n, m, x = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
a = []
for i in range(n):
    b = list(map(int, input().split()))
    t = sum(b)-b[0]
    # print(t)
    b.append(b[0]/t)
    a.append(b)

a_sorted = sorted(a, key=lambda x: x[-1])
# print(a_sorted)

money = 0
point = [0]*m
over = [0]*m
for i in range(n):
    fin = True
    money += a_sorted[i][0]
    for j in range(m):
        point[j] += a_sorted[i][j+1]
    for j in range(m):
        if point[j] < x:
            fin = False
        else:
            over[j] = point[j]-x
    if fin:
        k = []
        for i in range(n):
            kouho = True
            for j in range(m):
                if a_sorted[i][j+1] > over[j]:
                    kouho = False
            if kouho:
                k.append(i)
        k.sort(reverse=True)
        if len(k) != 0:
            for i in range(len(k)):
                for j in range(m):
                    point[j] -= a_sorted[i][j+1]
                    if point[j] < x:
                        print(money)
                        exit()
                money -= a_sorted[i][0]
        # print(over)
        for j in range(m):
            print(money)
            exit()
    # print(check)
print(-1)


### FIXED CODE ###

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

a = []
for i in range(n):
    b = list(map(int, input().split()))
    a.append(b)


def calcPoint(point, n):
    for i in range(m):
        point[i] += a[n][i+1]
    return point


def judgePoint(point):
    for i in range(m):
        if point[i] < x:
            return False
    return True


ans = []
for i in range(2**n):  # patarn数
    buy = []
    for j in range(n):  # n bit
        if((i >> j) & 1):  # iをj bit 右にずらして1ならば
            buy.append(1)
        else:
            buy.append(0)
    price = 0
    point = [0]*m
    for i in range(n):
        if buy[i] == 1:
            calcPoint(point, i)
            price += a[i][0]
    if judgePoint(point):
        ans.append(price)
if len(ans) == 0:
    print(-1)
else:
    print(min(ans))
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

o = sorted(o.values(), reverse=True)
e = sorted(e.values(), reverse=True)

e1 = sum(e[1:])
e2 = sum(e[0] + e[2:])
o1 = sum(o[1:])
o2 = sum(o[2:])
ret = min(e1+o2, e2+o1)
print(ret)


### FIXED CODE ###

from collections import Counter
N = int(input())
v = list(map(int, input().split()))
e = []
o = []
for idx, i in enumerate(v):
    if idx % 2 == 0:
        o.append(i)
    else:
        e.append(i)

e = Counter(e).most_common()
o = Counter(o).most_common()
e1 = e[0][1]
e2 = e[1][1] if len(e) > 1 else 0
o1 = o[0][1]
o2 = o[1][1] if len(o) > 1 else 0
cnt = 0
if e[0][0] != o[0][0]:
    cnt = N - e1 - o1
else:
    o = N - e1 - o2
    e = N - e2 - o1
    cnt = min(o, e)
print(cnt)
import sys
from heapq import heappush, heappop

inf = 1<<30

def solve():
    N, M, s = map(int, sys.stdin.readline().split())
    Adj = [[] for i in range(N)]

    for i in range(M):
        ui, vi, ci = map(int, sys.stdin.readline().split())
        Adj[ui].append((vi, ci))

    d = dijkstra(N, Adj, s)

    for di in d:
        print(di if di < inf else 'INF')

def dijkstra(N, Adj, s):
    d = [inf] * N
    d[s] = 0
    pq = [(0, s)]

    for i in range(N - 1):
        while 1:
            di, v = heappop(pq)

            if di == d[v]:
                break

        for u, c in Adj[v]:
            if d[v] + c < d[u]:
                d[u] = d[v] + c
                heappush(pq, (d[u], u))

    return d

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
from heapq import heappush, heappop

inf = 1<<30

def solve():
    N, M, s = map(int, sys.stdin.readline().split())
    Adj = [[] for i in range(N)]

    for i in range(M):
        ui, vi, ci = map(int, sys.stdin.readline().split())
        Adj[ui].append((vi, ci))

    d = dijkstra(N, Adj, s)

    for di in d:
        print(di if di < inf else 'INF')

def dijkstra(N, Adj, s):
    d = [inf] * N
    d[s] = 0
    pq = [(0, s)]
    fixed = 0

    while pq:
        di, v = heappop(pq)

        if di > d[v]:
            continue

        for u, c in Adj[v]:
            if d[v] + c < d[u]:
                d[u] = d[v] + c
                heappush(pq, (d[u], u))

        fixed += 1

        if fixed == N - 1:
            break

    return d

if __name__ == '__main__':
    solve()
def binaryinsertion(A,x):
    left=0;right=len(A)-1;centre = len(A)//2
    while(True):
        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
            centre = left + (right-left)//2

[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))def binaryinsertion(A,x):
    left=0;right=len(A)-1;centre = len(A)//2
    while(True):
        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
            centre = left + (right-left)//2

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