#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <utility>
#include <vector>

template <typename T, size_t bitsize> class WaveletMatrix {
public:
	using value_type = T;
	using size_type = std::size_t;

private:
	using uint32 = std::uint_least32_t;
	static size_type popcount32(uint32 c) {
#ifdef __GNUC__
		return __builtin_popcount(c);
#elif _MSC_VER_
		return _mm_popcnt_u32(c);
#else
		c = (c & 0x55555555ULL) + ((c >> 1) & 0x55555555ULL);
		c = (c & 0x33333333ULL) + ((c >> 2) & 0x33333333ULL);
		c = (c + (c >> 4)) & 0x0F0F0F0FULL;
		c += c >> 8;
		c += c >> 16;
		return static_cast<size_type>(c) & 0x3F;
#endif
	}
	struct FID {
		std::vector<uint32> dic;
		size_type cnt;
		value_type bit;
		FID() {}
		FID(const size_type bsize) : dic(bsize, 0) {}
		void set(const size_type index) {
			dic[index >> 4 | 1] |= static_cast<uint32>(1) << (index & 0x1f);
		}
		void build() {
			const size_type len = dic.size();
			for (size_type j = 2; j < len; j += 2)
				dic[j] = dic[j - 2] + popcount32(dic[j - 1]);
		}
		size_type rank(const size_type index) const {
			return static_cast<size_type>(
				dic[index >> 4 & ~static_cast<size_type>(1)]) +
				popcount32(dic[index >> 4 | 1] &
				(static_cast<size_type>(1) << (index & 0x1f)) - 1);
		}
		bool access(const size_type index) const {
			return dic[index >> 4 | 1] >> (index & 0x1f) & 1;
		}
	};
	std::array<FID, bitsize> matrix;

public:
	WaveletMatrix(std::vector<value_type> data) {
		const size_type len = data.size(), block = ((len >> 5) + 1) << 1;
		std::vector<value_type> L(len), R(len);
		size_type l, r;
		value_type temp = static_cast<value_type>(1) << (bitsize - 1);
		for (auto &x : matrix) {
			x = FID(block);
			x.bit = temp;
			temp = temp >> 1 & ~temp;
			l = 0;
			r = 0;
			for (size_type j = 0; j < len; ++j)
				if (data[j] & x.bit)
					R[r++] = data[j], x.set(j);
				else
					L[l++] = data[j];
			x.cnt = l;
			x.build();
			std::swap(data, L);
			std::copy(R.begin(), R.begin() + r, data.begin() + l);
		}
	}
	value_type operator[](size_type index) const {
		value_type ret = 0;
		for (const auto &x : matrix)
			if (x.access(index))
				ret |= x.bit, index = x.rank(index) + x.cnt;
			else
				index -= x.rank(index);
		return ret;
	}
	size_type rank(size_type begin, size_type end, const value_type data) const {
		for (const auto &x : matrix)
			if (data & x.bit)
				begin = x.rank(begin) + x.cnt, end = x.rank(end) + x.cnt;
			else
				begin -= x.rank(begin), end -= x.rank(end);
		return end - begin;
	}
	value_type quantile(size_type begin, size_type end, size_type k) const {
		value_type ret = 0;
		for (const auto &x : matrix) {
			const size_type l = x.rank(begin), r = x.rank(end);
			if (r - l > k)
				begin = l + x.cnt, end = r + x.cnt, ret |= x.bit;
			else
				begin -= l, end -= r, k -= r - l;
		}
		return ret;
	}
	value_type rquantile(size_type begin, size_type end, size_type k) const {
		return quantile(begin, end, end - begin - k - 1);
	}
	size_type less_than(size_type begin, size_type end,
		const value_type data) const {
		size_type ret = 0;
		for (const auto &x : matrix) {
			if (data & x.bit) {
				ret += end - begin + x.rank(begin) - x.rank(end);
				begin = x.rank(begin) + x.cnt;
				end = x.rank(end) + x.cnt;
			}
			else {
				begin -= x.rank(begin);
				end -= x.rank(end);
			}
		}
		return ret + end - begin;
	}
	size_type more_than(size_type begin, size_type end,
		const value_type data) const {
		size_type ret = 0;
		for (const auto &x : matrix) {
			if (data & x.bit) {
				begin = x.rank(begin) + x.cnt;
				end = x.rank(end) + x.cnt;
			}
			else {
				ret += x.rank(end) - x.rank(begin);
				begin -= x.rank(begin);
				end -= x.rank(end);
			}
		}
		return ret;
	}
	size_type rangefreq(size_type begin, size_type end, const value_type lower,
		const value_type upper) const {
		return less_than(begin, end, upper) - less_than(begin, end, lower);
	}
	value_type successor(const size_type begin, const size_type end,
		const value_type data) const {
		return rquantile(begin, end, less_than(begin, end, data));
	}
	value_type predecessor(const size_type begin, const size_type end,
		const value_type data) const {
		return quantile(begin, end, more_than(begin, end, data));
	}
	value_type next(const size_type begin, const size_type end,
		const value_type data) const {
		return quantile(begin, end, more_than(begin, end, data) - 1);
	}
	value_type prev(const size_type begin, const size_type end,
		const value_type data) const {
		return rquantile(begin, end, less_than(begin, end, data) - 1);
	}
};

#include<cstdio>
#include<vector>
int main() {
	int n, l;
	scanf("%d %d", &n, &l);
	std::vector<int> a(n);
	for (auto &x : a)scanf("%d", &x);
	WaveletMatrix<int, 30> W(a);
	for (int i = 0;i <= n - l;++i)
		printf("%d%c", W.quantile(i, i + l, l-1), " \n"[i == n - l]);
	return 0;
}


Measured memory_bytes: 25396