#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define sf scanf
#define pf printf
#define nl printf("\n")
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define chk cerr<<"CAME HERE"<<endl
#define dbug(x) cerr<<"value of "<<#x<<" = "<<x<<endl
mt19937_64 rng((uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
inline ll rand(ll l, ll r){uniform_int_distribution<ll> RNG(l,r);return RNG(rng);}
template<typename T>inline void togglebit(T &x, int pos){x^=(T(1)<<pos);}
template<typename T>inline bool chkbit(T x, int pos){return bool(x&(T(1)<<pos));}
template<typename T>inline void setbit(T &x, int pos){x|=(T(1)<<pos);}
template<typename T>inline void resetbit(T &x, int pos){if(chkbit(x,pos))togglebit(x,pos);}
const int N = 1e5+5;
void work(vector<int>& arr, int k) {
vector<int>ans;
multiset<int>R,L;
auto balance = [&](){
if(L.size() > R.size()+1){
R.insert(*L.rbegin());
L.erase(L.find(*L.rbegin()));
}
if(R.size() > L.size()){
L.insert(*R.begin());
R.erase(R.begin());
}
};
// auto Del = [&](int x){
// if(L.count(x))L.erase(L.find(x));
// else R.erase(R.find(x));
// balance();
// };
for(int i=0,n=sz(arr),x; i<n; i++){
x=arr[i];
if(L.empty())L.insert(x);
else if(*L.rbegin()>x)L.insert(x);
else R.insert(x);
balance();
if(sz(L)+sz(R)==k){
pf("%d ",*L.rbegin());
x=arr[i-k+1];
//Del(x);
if(L.count(x))L.erase(L.find(x));
else R.erase(R.find(x));
balance();
}
}
}
void solve(int casenum){
int n,k;
sii(n,k);
vi arr(n);
FOR(i,n)si(arr[i]);
work(arr,k);
}
int main(){
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int T=1;
//scanf("%d",&T);
//cin>>T;
for(int i=1; i<=T; i++)
solve(i);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAp0eXBlZGVmIGludDY0X3QgbGw7CnR5cGVkZWYgdWludDY0X3QgdWxsOwp0eXBlZGVmIGxvbmcgZG91YmxlIGxkOwp0eXBlZGVmIHBhaXI8aW50LGludD4gcGlpOwp0eXBlZGVmIHBhaXI8bGwsbGw+IHBsbDsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2aTsKI2RlZmluZSBzZiBzY2FuZgojZGVmaW5lIHBmIHByaW50ZgojZGVmaW5lIG5sIHByaW50ZigiXG4iKQojZGVmaW5lIHNpKHgpIHNjYW5mKCIlZCIsJngpCiNkZWZpbmUgc2lpKHgseSkgc2NhbmYoIiVkJWQiLCZ4LCZ5KQojZGVmaW5lIHNpaWkoeCx5LHopIHNjYW5mKCIlZCVkJWQiLCZ4LCZ5LCZ6KQojZGVmaW5lIHNsKHgpIHNjYW5mKCIlbGxkIiwmeCkKI2RlZmluZSBzbGwoeCx5KSBzY2FuZigiJWxsZCVsbGQiLCZ4LCZ5KQojZGVmaW5lIHNsbGwoeCx5LHopIHNjYW5mKCIlbGxkJWxsZCVsbGQiLCZ4LCZ5LCZ6KQojZGVmaW5lIEZPUihpLG4pIGZvcihpbnQgaT0wO2k8bjtpKyspCiNkZWZpbmUgc3ooeCkgKGludCl4LnNpemUoKQojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCkseC5lbmQoKQojZGVmaW5lIGNoayBjZXJyPDwiQ0FNRSBIRVJFIjw8ZW5kbAojZGVmaW5lIGRidWcoeCkg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ICAgICAgICAgICAgICBMLmVyYXNlKEwuZmluZCgqTC5yYmVnaW4oKSkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKFIuc2l6ZSgpID4gTC5zaXplKCkpewogICAgICAgICAgICAgICAgTC5pbnNlcnQoKlIuYmVnaW4oKSk7CiAgICAgICAgICAgICAgICBSLmVyYXNlKFIuYmVnaW4oKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIAoJCS8vIGF1dG8gRGVsID0gWyZdKGludCB4KXsKCQkJLy8gaWYoTC5jb3VudCh4KSlMLmVyYXNlKEwuZmluZCh4KSk7CiAgICAgICAgICAgIC8vIGVsc2UgUi5lcmFzZShSLmZpbmQoeCkpOwogICAgICAgICAgICAvLyBiYWxhbmNlKCk7CgkJLy8gfTsKCQkKICAgICAgICBmb3IoaW50IGk9MCxuPXN6KGFycikseDsgaTxuOyBpKyspewoJCQl4PWFycltpXTsKICAgICAgICAgICAgaWYoTC5lbXB0eSgpKUwuaW5zZXJ0KHgpOwoJCQllbHNlIGlmKCpMLnJiZWdpbigpPngpTC5pbnNlcnQoeCk7CgkJCWVsc2UgUi5pbnNlcnQoeCk7CgkJCWJhbGFuY2UoKTsKICAgICAgICAgICAKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmKHN6KEwpK3N6KFIpPT1rKXsKCQkJCXBmKCIlZCAiLCpMLnJiZWdpbigpKTsKIAoJCQkJeD1hcnJbaS1rKzFdOwoJCQkJLy9EZWwoeCk7CgkJCQlpZihMLmNvdW50KHgpKUwuZXJhc2UoTC5maW5kKHgpKTsKCQkJCWVsc2UgUi5lcmFzZShSLmZpbmQoeCkpOwoJCQkJYmFsYW5jZSgpOwogICAgICAgICAgICB9CiAgICAgICAgfQoJCQogCiAKICAgIH0KIAp2b2lkIHNvbHZlKGludCBjYXNlbnVtKXsKCWludCBuLGs7CglzaWkobixrKTsKCXZpIGFycihuKTsKCUZPUihpLG4pc2koYXJyW2ldKTsKCXdvcmsoYXJyLGsp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