#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 uint64 = std::uint_fast64_t;
	static size_type popcount64(uint64 c) {
#ifdef __GNUC__
		return __builtin_popcountll(c);
#elif _MSC_VER_
		return _mm_popcnt_u64(c);
#else
		c = (c & 0x5555555555555555ULL) + ((c >> 1) & 0x5555555555555555ULL);
		c = (c & 0x3333333333333333ULL) + ((c >> 2) & 0x3333333333333333ULL);
		c = (c + (c >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
		c += c >> 8;
		c += c >> 16;
		c += c >> 32;
		return static_cast<size_type>(c) & 0x7F;
#endif
	}
	struct FID {
		std::vector<uint64> dic;
		size_type cnt;
		value_type bit;
		FID() {}
		FID(const size_type bsize) : dic(bsize, 0) {}
		void set(const size_type index) {
			dic[index >> 5 | 1] |= static_cast<uint64>(1) << (index & 0x3f);
		}
		void build() {
			const size_type len = dic.size();
			for (size_type j = 2; j < len; j += 2)
				dic[j] = dic[j - 2] + popcount64(dic[j - 1]);
		}
		size_type rank(const size_type index) const {
			return static_cast<size_type>(
				dic[index >> 5 & ~static_cast<size_type>(1)]) +
				popcount64(dic[index >> 5 | 1] &
				(static_cast<size_type>(1) << (index & 0x3f)) - 1);
		}
		bool access(const size_type index) const {
			return dic[index >> 5 | 1] >> (index & 0x3f) & 1;
		}
	};
	std::array<FID, bitsize> matrix;

public:
	WaveletMatrix(std::vector<value_type> data) {
		const size_type len = data.size(), block = ((len >> 6) + 1) << 1;
		for (auto &x : matrix)
			x = FID(block);
		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 >>= 1;
			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);
		}
	}
	T operator[](size_type index) const {
		T 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;
	}
	T rank(size_type begin, size_type end, const T 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;
	}
	T quantile(size_type begin, size_type end, size_type k) const {
		T 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;
	}
	T 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 T 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 T 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 T lower,
		const T upper) const {
		return end - begin - less_than(begin, end, lower) -
			more_than(begin, end, upper);
	}
};

#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: 25704