package main

import (
	"bufio"
	"fmt"
	"os"
)

func cmp(a, b int) int {
	if a < b {
		return -1
	}
	return 1
}

func solveD(a []int, k int) {
	check := func(x int) bool {
		mn, s, idx, curr := 0, 0, 0, 0
		for i := 0; i < k-1; i++ {
			curr += cmp(a[i], x)
		}

		for i := k - 1; i < len(a); i++ {
			curr += cmp(a[i], x)
			if curr > mn {
				return true
			}

			s += cmp(a[idx], x)
			idx++
			if mn > s {
				mn = s
			}
		}

		return false
	}

	l, r := 1, int(2e5)+1
	for r-l > 1 {
		m := l + (r-l)/2
		if check(m) {
			l = m
		} else {
			r = m
		}
	}

	printf("%d", l)
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	//scan(&T)

	for t := 0; t < T; t++ {
		var n, k int
		scan(&n, &k)

		a := make([]int, n)
		for i := range a {
			scan(&a[i])
		}

		solveD(a, k)
	}
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func calc() {
	input := bufio.NewReader(os.Stdin)
	output := bufio.NewWriter(os.Stdout)
	defer output.Flush()

	var n, k int

	fmt.Fscan(input, &n, &k)
	a := make([]int, n)

	for i := range a {
		fmt.Fscan(input, &a[i])
	}

	median := sort.Search(n+1, func(mid int) bool {
		if mid < 2 {
			return false
		}

		b := make([]int, n)
		for i, v := range a {
			if v >= mid {
				b[i] = 1
			} else {
				b[i] = -1
			}
		}

		sum := make([]int, n+1)
		for i, v := range b {
			sum[i+1] = sum[i] + v
		}

		mi := sum[0]
		for i := k; i <= n; i++ {
			mi = min(mi, sum[i-k])
			if sum[i] > mi {
				return false
			}
		}

		return true
	}) - 1
	fmt.Fprintln(output, median)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	calc()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	var l0, m0, r0 int
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			for j := i - len + 1; j < i - k; j++ {
				if a[j] == res {
					l0++
					m0--
				}
			}
			l += tr[res]
			res = nextTr(res)
		}
		if a[i-k] > res {
			r0++
		} else if a[i-k] == res {
			m0++
		} else {
			l0++
		}
		if l0 + m0 > r0 {
			for j := i - len + 1; j <= i - k; j++ {
				tr[a[j]]--
			}
			len = k
			l -= l0
			l0 = 0
			m0 = 0
			r0 = 0
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, k := readTwoNums(reader)

	A := readNNums(reader, n)

	res := solve1(n, k, A)

	fmt.Println(res)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve1(n int, k int, A []int) int {
	B := make([]int, n)

	check := func(cand int) bool {
		for i := 0; i < n; i++ {
			if A[i] >= cand {
				B[i] = 1
			} else {
				B[i] = -1
			}
		}

		for i := 1; i < n; i++ {
			B[i] += B[i-1]
		}

		mx := B[k-1]
		mn := 0

		for i := k; i < n; i++ {
			mn = min(mn, B[i-k])
			mx = max(mx, B[i]-mn)
		}

		return mx > 0
	}

	var left, right = INF, 1

	for i := 0; i < n; i++ {
		if left > A[i] {
			left = A[i]
		}
		if right < A[i] {
			right = A[i]
		}
	}
	if left == right {
		return right
	}
	right++
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 1
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

const INF = 1 << 29

func solve(n int, k int, A []int) int {
	//如果存在某个区间[l...r] (r - l + 1 >= k), 它的median <= x
	//那么设ge[l...r]为大于等于x的数量, lt[l....r] 为 < x的数量
	//则ge >= lt 当 sz(S) 为偶数 ge+1>=lt when odd
	// ge(R) - ge(L) >= lt(R) - lt(L)
	// let ge(R) = x, then lt(R) = R + 1 - x
	// let ge(L) = y, then lt(L) = L + 1 - y
	// x - y >= R - L - (x - y)
	// 2x - R >= 2 * y - L

	arr := make([]int, 2*n)

	update := func(p int, v int) {
		p += n
		arr[p] = v
		for p > 1 {
			arr[p>>1] = min(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		l += n
		r += n
		res := INF

		for l < r {
			if l&1 == 1 {
				res = min(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = min(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	check := func(cand int) bool {
		for i := 0; i < len(arr); i++ {
			arr[i] = INF
		}
		var x int
		for i := 0; i < n; i++ {
			if A[i] >= cand {
				x++
			}
			cur := 2*x - (i + 1)
			if cur > 0 && i+1 >= k {
				return true
			}
			if i+1 > k {
				tmp := get(0, i+1-k)
				// [1, 1, 1, 2, 2, 2] suppose cand = 2, and k = 3, and i = 4, then tmp should get from [0...2)
				if cur > tmp {
					return true
				}
			}
			update(i, cur)
		}
		return false
	}

	var left, right = INF, 1

	for i := 0; i < n; i++ {
		if left > A[i] {
			left = A[i]
		}
		if right < A[i] {
			right = A[i]
		}
	}
	if left == right {
		return right
	}
	right++
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 1
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, k := readTwoNums(reader)

	A := readNNums(reader, n)

	res := solve(n, k, A)

	fmt.Println(res)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve1(n int, k int, A []int) int {
	B := make([]int, n)

	check := func(cand int) bool {
		for i := 0; i < n; i++ {
			if A[i] >= cand {
				B[i] = 1
			} else {
				B[i] = -1
			}
		}

		for i := 1; i < n; i++ {
			B[i] += B[i-1]
		}

		mx := B[k-1]
		mn := 0

		for i := k; i < n; i++ {
			mn = min(mn, B[i-k])
			mx = max(mx, B[i]-mn)
		}

		return mx > 0
	}

	var left, right = INF, 1

	for i := 0; i < n; i++ {
		if left > A[i] {
			left = A[i]
		}
		if right < A[i] {
			right = A[i]
		}
	}
	if left == right {
		return right
	}
	right++
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 1
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

const INF = 1 << 29

func solve(n int, k int, A []int) int {
	//如果存在某个区间[l...r] (r - l + 1 >= k), 它的median <= x
	//那么设ge[l...r]为大于等于x的数量, lt[l....r] 为 < x的数量
	//则ge >= lt 当 sz(S) 为偶数 ge+1>=lt when odd
	// ge(R) - ge(L) >= lt(R) - lt(L)
	// let ge(R) = x, then lt(R) = R + 1 - x
	// let ge(L) = y, then lt(L) = L + 1 - y
	// x - y >= R - L - (x - y)
	// 2x - R >= 2 * y - L

	arr := make([]int, 2*n)

	update := func(p int, v int) {
		p += n
		arr[p] = v
		for p > 1 {
			arr[p>>1] = min(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		l += n
		r += n
		res := INF

		for l < r {
			if l&1 == 1 {
				res = min(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = min(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	check := func(cand int) bool {
		for i := 0; i < len(arr); i++ {
			arr[i] = INF
		}
		var x int
		for i := 0; i < n; i++ {
			if A[i] >= cand {
				x++
			}
			cur := 2*x - (i + 1)
			if cur > 0 && i+1 >= k {
				return true
			}
			if i+1 > k {
				tmp := get(0, i+1-k)
				// [1, 1, 1, 2, 2, 2] suppose cand = 2, and k = 3, and i = 4, then tmp should get from [0...2)
				if cur > tmp {
					return true
				}
			}
			update(i, cur)
		}
		return false
	}

	var left, right = INF, 1

	for i := 0; i < n; i++ {
		if left > A[i] {
			left = A[i]
		}
		if right < A[i] {
			right = A[i]
		}
	}
	if left == right {
		return right
	}
	right++
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 1
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, k int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	ans := sort.Search(n+1, func(mid int) bool {
		if mid < 2 {
			return false
		}
		b := make([]int, n)
		for i, v := range a {
			if v >= mid {
				b[i] = 1
			} else {
				b[i] = -1
			}
		}
		sum := make([]int, n+1)
		for i, v := range b {
			sum[i+1] = sum[i] + v
		}
		mi := sum[0]
		for i := k; i <= n; i++ {
			mi = min(mi, sum[i-k])
			if sum[i] > mi {
				return false
			}
		}
		return true
	}) - 1
	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

const maxn int = 2e5 + 10

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var a [maxn]int
var n, k int

var L, R, pre [2 * maxn]int

func J(x int) bool {

	for i := 0; i < 2*maxn; i++ {
		L[i], R[i], pre[i] = 0, 0, 0
	}
	pre[0] = maxn
	var Min, Max int = maxn, maxn
	R[maxn] = 0
	for i := 0; i < n; i++ {
		if a[i] < x {
			pre[i+1] = pre[i] - 1
		} else {
			pre[i+1] = pre[i] + 1
		}

		if pre[i+1] < Min {
			Min = pre[i+1]
		}
		if pre[i+1] > Max {
			Max = pre[i+1]
		}
		if L[pre[i+1]] == 0 {
			L[pre[i+1]] = i + 1
		}
		R[pre[i+1]] = i + 1
	}

	L[maxn] = 0

	var flag int = 0
	for i := Max; i >= Min; i-- {
		if flag-L[i] >= k {
			return true
		}
		if R[i] > flag {
			flag = R[i]
		}
	}
	//Fprintln(out, x)
	return false
}
func main() {

	defer out.Flush()

	Fscan(in, &n, &k)
	for i := 0; i < n; i++ {
		Fscan(in, &a[i])
	}
	var l, r int = 0, n + 1

	for l+1 < r {
		mid := (l + r) / 2
		if J(mid) {
			l = mid
			//Fprintln(out, l)
		} else {
			r = mid
		}
	}
	Fprint(out, l)
}

// 5 4
// 5 1 2 5 5

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	var l0, m0, r0 int
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			l += tr[res]
			res = nextTr(res)
		}
		if a[i-k] > res {
			r0++
		} else if a[i-k] == res {
			m0++
		} else {
			l0++
		}
		if l0 + m0 > r0 {
			for j := i - len + 1; j <= i - k; j++ {
				tr[a[j]]--
			}
			len = k
			l -= l0
			l0 = 0
			m0 = 0
			r0 = 0
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	var l0, m0, r0 int
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			l += tr[res]
			res = nextTr(res)
		}
		if a[i-k] > res {
			r0++
		} else if a[i-k] == res {
			m0++
		} else {
			l0++
		}
		if l0 + m0 >= r0 {
			for j := i - len + 1; j <= i - k; j++ {
				tr[a[j]]--
			}
			len = k
			l -= l0
			l0 = 0
			m0 = 0
			r0 = 0
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	var l0, m0, r0 int
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			l += tr[res]
			res = nextTr(res)
		}
		if a[i-k+1] > res {
			r0++
		} else if a[i-k+1] == res {
			m0++
		} else {
			l0++
		}
		if l0 + m0 >= r0 {
			for j := i - len + 1; j <= i - k; j++ {
				tr[a[j]]--
			}
			len = k
			l -= l0
			l0 = 0
			m0 = 0
			r0 = 0
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	var l0, m0, r0 int
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			l += tr[res]
			res = nextTr(res)
		}
		if a[i-k+1] > res {
			r0++
		} else if a[i-len+1] == res {
			m0++
		} else {
			l0++
		}
		if l0 + m0 >= r0 {
			for j := i - len + 1; j <= i - k; j++ {
				tr[a[j]]--
			}
			len = k
			l -= l0
			l0 = 0
			m0 = 0
			r0 = 0
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			res = i
			break
		}
	}
	var len = k
	for i := k; i < n; i++ {
		tr[a[i]]++
		len++
		if a[i] < res {
			l++
		}
		if l + tr[res] < (len + 1) / 2 {
			l += tr[res]
			res = nextTr(res)
		}
		for j := i - len + 1; j <= i - k; j++ {
			if a[j] >= res {
				break
			}
			tr[a[j]]--
			len--
			l--
			if l + tr[res] < (len + 1) / 2 {
				l += tr[res]
				res = nextTr(res)
			}
		}
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a, tr [200001]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 0; i < k; i++ {
		tr[a[i]]++
	}
	var l, x int
	for i := 1; i <= 200000; i++ {
		l += tr[i]
		if l >= (k + 1) / 2 {
			l -= tr[i]
			x = i
			break
		}
	}
	res = x
	for i := k; i < n; i++ {
		tr[a[i]]++
		if a[i] < x {
			l++
		}
		if l + tr[x] < (k + 2) / 2 {
			l += tr[x]
			x = nextTr(x)
		}
		res = max(res, x)
		j := i - k
		tr[a[j]]--
		if a[j] < x {
			l--
		}
		if l + tr[x] < (k + 1) / 2 {
			l += tr[x]
			x = nextTr(x)
		}
		res = max(res, x)
	}
}

func nextTr(pos int) int {
	for i := pos + 1; i < 200000; i++ {
		if tr[i] > 0 {
			return i
		}
	}
	return 200000
}

func prevTr(pos int) int {
	for i := pos - 1; i > 1; i-- {
		if tr[i] > 0 {
			return i
		}
	}
	return 1
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

const (
	MOD int = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	a [200000]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	sort.Ints(a[:n])
	res = a[n-1-k/2]
}

func output() {
	out.Write(intToBytes(res))
}

func test() {

}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	return int(getInt64())
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	return int64ToBytes(int64(n))
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, k := readTwoNums(reader)

	A := readNNums(reader, n)

	res := solve(n, k, A)

	fmt.Println(res)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 29

func solve(n int, k int, A []int) int {
	//如果存在某个区间[l...r] (r - l + 1 >= k), 它的median <= x
	//那么设ge[l...r]为大于等于x的数量, lt[l....r] 为 < x的数量
	//则ge >= lt 当 sz(S) 为偶数 ge+1>=lt when odd
	// ge(R) - ge(L) >= lt(R) - lt(L)
	// let ge(R) = x, then lt(R) = R + 1 - x
	// let ge(L) = y, then lt(L) = L + 1 - y
	// x - y >= R - L - (x - y)
	// 2x - R >= 2 * y - L

	arr := make([]int, 2*n)

	update := func(p int, v int) {
		p += n
		arr[p] = v
		for p > 1 {
			arr[p>>1] = min(arr[p], arr[p^1])
			p >>= 1
		}
	}

	get := func(l, r int) int {
		l += n
		r += n
		res := INF

		for l < r {
			if l&1 == 1 {
				res = min(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = min(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	check := func(cand int) bool {
		for i := 0; i < len(arr); i++ {
			arr[i] = INF
		}
		var x int
		for i := 0; i < n; i++ {
			if A[i] >= cand {
				x++
			}
			cur := 2*x - (i + 1)
			if cur > 0 {
				return true
			}
			if i+1 > k {
				tmp := get(0, i+1-k)
				// [1, 1, 1, 2, 2, 2] suppose cand = 2, and k = 3, and i = 4, then tmp should get from [0...2)
				if cur > tmp {
					return true
				}
			}
			update(i, cur)
		}
		return false
	}

	var left, right = INF, 1

	for i := 0; i < n; i++ {
		if left > A[i] {
			left = A[i]
		}
		if right < A[i] {
			right = A[i]
		}
	}
	if left == right {
		return right
	}
	right++
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 1
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func cmp(a, b int) int {
	if a < b {
		return -1
	}
	return 1
}

func solveD(a []int, k int) {
	check := func(x int) bool {
		mn, s, idx, curr := 0, 0, 0, 0
		for i := 0; i < k-1; i++ {
			curr += cmp(a[i], x)
		}

		for i := k - 1; i < len(a); i++ {
			curr += cmp(a[i], x)
			if curr >= mn {
				return true
			}

			s += a[idx]
			idx++
			if mn > s {
				mn = s
			}
		}

		return false
	}

	l, r := 1, int(2e5)+1
	for r-l > 1 {
		m := l + (r-l)/2
		if check(m) {
			l = m
		} else {
			r = m
		}
	}

	printf("%d", l)
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	//scan(&T)

	for t := 0; t < T; t++ {
		var n, k int
		scan(&n, &k)

		a := make([]int, n)
		for i := range a {
			scan(&a[i])
		}

		solveD(a, k)
	}
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, k int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	ans := sort.Search(n+1, func(mid int) bool {
		if mid < 2 {
			return false
		}
		b := make([]int, n)
		for i, v := range a {
			if v >= mid {
				b[i] = 1
			} else {
				b[i] = -1
			}
		}
		sum := make([]int, n+1)
		for i, v := range b {
			sum[i+1] = sum[i] + v
		}
		mi := sum[0]
		for i := 0; i < n-k; i++ {
			mi = min(mi, sum[i])
		}
		for i := k; i <= n; i++ {
			mi = min(mi, sum[i-k])
			if sum[i] > mi {
				return false
			}
		}
		return true
	}) - 1
	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

const maxn int = 2e5 + 10

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var a [maxn]int
var n, k int

var L, R, pre [2 * maxn]int

func J(x int) bool {

	for i := 0; i < 2*maxn; i++ {
		L[i], R[i], pre[i] = 0, 0, 0
	}
	pre[0] = maxn
	var Min, Max int = 2 * maxn, 0
	for i := 0; i < n; i++ {
		if a[i] < x {
			pre[i+1] = pre[i] - 1
		} else {
			pre[i+1] = pre[i] + 1
		}
		if pre[i+1] < Min {
			Min = pre[i+1]
		}
		if pre[i+1] > Max {
			Max = pre[i+1]
		}
		if L[pre[i+1]] == 0 {
			L[pre[i+1]] = i + 1
		}
		R[pre[i+1]] = i + 1
	}

	L[maxn] = 0

	var flag int = 0
	for i := Max; i >= Min; i-- {
		if flag-L[i] >= k {
			return true
		}
		if R[i] > flag {
			flag = R[i]
		}
	}
	//Fprintln(out, x)
	return false
}
func main() {

	defer out.Flush()

	Fscan(in, &n, &k)
	for i := 0; i < n; i++ {
		Fscan(in, &a[i])
	}
	var l, r int = 0, n + 1

	for l+1 < r {
		mid := (l + r) / 2
		if J(mid) {
			l = mid
			//Fprintln(out, l)
		} else {
			r = mid
		}
	}
	Fprint(out, l)
}

// 5 4
// 5 1 2 5 5


package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if a[0] < 0  {
			Fprintln(out, "no")
			return
		}
		Fprintln(out, "yes")

			Fprintln(out, a[n-1]+1)
			for i := 0; i <= a[n-1]; i++ {
				Fprint(out, i, " ")
			}
		Fprintln(out)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"os"
	"fmt"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		var n int

		fmt.Fscan(r, &n)

		a := make([]int, n)
		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &a[j])
		}

		res, arr := solve(a, n)

		if !res {
			fmt.Println("NO")

		} else {
			fmt.Println("YES")
			fmt.Println(len(arr))

			for i := 0; i < len(arr); i++ {
				fmt.Print(arr[i])
				fmt.Print(" ")
			}
			fmt.Println()
		}
	}
}

func solve(a []int, n int)  (bool, []int){

	neg := false

	zero := false

	for i := 0; i < n; i++ {

		if a[i] < 0 {
			neg = true
		}
		if a[i] == 0 {
			zero = true
		}
	}

	if neg {
		return false, []int{}
	}

	sort.Ints(a)

	max := a[len(a) - 1]

	var ans []int

	for i := 1; i <= max; i++ {
		ans = append(ans, i)
	}
	if zero {
		ans = append(ans, 0)
	}
	return true, ans

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) string {
	max := 0
	for _, x := range a {
		if x < 0 {
			return "No"
		}
		if max < x {
			max = x
		}
	}
	r := "Yes\n" + fmt.Sprintf("%d", 1+max) + "\n"
	for i := 0; i <= max; i++ {
		r += fmt.Sprintf("%d ", i)
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

import(
    "fmt"
)

func main(){
    var i int
    fmt.Scan(&i)
    for i>0{
		i--
		var n int
		fmt.Scan(&n)
		ans:="yes"
		for j:=0;j<n;j++{
			var k int
			fmt.Scan(&k)
			if k<0{
				ans="no"
			}
		}
		fmt.Println(ans)
		if ans=="yes"{
			fmt.Println(101)
			for j:=0;j<=100;j++{
				fmt.Print(j," ")
			}
			println()
		}
    }
}

package main
import (
    "os"
    "fmt"
    "bufio"
    "strconv"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        mn, mx := int(1E9), -int(1E9)
        for _, v := range a {
            if v < mn {
                mn = v
            }
            if v > mx {
                mx = v
            }
        }
        if mn < 0 {
            fmt.Println("NO")
        } else {
            fmt.Println("YES\n" + strconv.Itoa(mx + 1))
            for i := 0; i <= mx; i++ {
                fmt.Print(i, " ")
            }
        }
    }
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        mn, mx := int(1E9), -int(1E9)
        for _, v := range a {
            if v < mn {
                mn = v
            }
            if v > mx {
                mx = v
            }
        }
        if mn < 0 {
            fmt.Println("NO")
        } else {
            fmt.Println("YES")
            fmt.Println(mx + 1)
            for i := 0; i <= mx; i++ {
                fmt.Print(i, " ")
            }
        }
    }
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,max int
		low:=9999999999
		fmt.Fscan(in,&n)
		var neg,zero bool
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			if list[j] < 0 {neg=true}
			if list[j] == 0 {zero=true}
			if list[j] > max || j==0 {max=list[j]}
			if list[j] < low && (list[j] != 0 || list[j] != 1) {low=list[j]}
		}
		if neg == true {
			fmt.Fprintln(out,"NO")
			continue
		}
		if max > 300 || (max == 300 && zero == true) {
			for j:=1;j<n;j++{
				if list[j]%low != 0 {
					fmt.Fprintln(out,"NO")
					goto out
				}
			}
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j+=low{
				fmt.Fprintf(out,"%v ",list[j])
			}
			fmt.Fprintln(out)
		}else{
			fmt.Fprintln(out,"YES")
			if zero==true{
				fmt.Fprintln(out,max+1)
				for j:=0;j<=max;j++ {fmt.Fprintf(out,"%v ",j)}
			} else {
				fmt.Fprintln(out,max)
				for j:=1;j<=max;j++ {fmt.Fprintf(out,"%v ",j)}
			}
			fmt.Fprintln(out)
		}
		out:
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

type CF1536A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1536A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1536A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1536A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1536A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1536A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1536A
Date: 4/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1536/A
Problem: CF1536A
**/
func (in *CF1536A) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int64, n)
		mapa := make(map[int64]bool)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt64()
			mapa[arr[i]] = true
		}

		for i := 0; i < len(arr) && len(arr) <= 301; i++ {
			for j := 0; j < len(arr) && len(arr) <= 301; j++ {
				if i != j {
					mult := int64(math.Abs(float64(arr[i] - arr[j])))
					if _, ok := mapa[mult]; !ok {
						arr = append(arr, mult)
						mapa[mult] = true
					}
				}
			}
		}

		if len(arr) <= 300 {
			fmt.Println("YES")
			fmt.Println(len(arr))
			for i := 0; i < len(arr); i++ {
				fmt.Print(arr[i], " ")
			}
			fmt.Println()
		} else {
			fmt.Println("NO")
		}

	}

}

func NewCF1536A(r *bufio.Reader) *CF1536A {
	return &CF1536A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1536A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scan *bufio.Scanner

func init() {
	scan = bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanWords)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n := nextInt()
		minVal := 101
		maxVal := -101
		for j := 0; j < n; j++ {
			v := nextInt()
			// fmt.Printf("v: %d\n", v)
			if minVal > v {
				minVal = v
			}
			if maxVal < v {
				maxVal = v
			}
		}
		if minVal < 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			b := maxVal
			if minVal == 0 {
				b += 1
			}
			fmt.Println(b)
			if minVal == 0 {
				fmt.Print("0 ")
			}
			for k := 1; k < maxVal; k++ {
				fmt.Printf("%d ", k)
			}
			fmt.Println(maxVal)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if a[0] < 0 {
			Fprintln(out, "No")
			return
		}
		Fprintln(out, "yes")
		Fprintln(out, a[n-1]+1)
		for i := 0; i <= a[n-1]; i++ {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscan(reader, &t)

	var n, num int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		min, max := 1<<31-1, -1<<31
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &num)
			min = Min(min, num)
			max = Max(max, num)
		}
		if min < 0 {
			fmt.Fprintln(writer, "NO")
			continue
		}
		fmt.Fprintln(writer, "YES")
		fmt.Fprintln(writer, max+1)
		for i := 0; i <= max; i++ {
			fmt.Fprint(writer, i, " ")
		}
		fmt.Fprintln(writer)
	}
}

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		arr := make([]int, n)

		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &arr[i])
		}

		sort.Ints(arr)

		if arr[0] < 0 {
			fmt.Println("NO")
			continue
		}

		fmt.Println("YES")
		fmt.Println(arr[n-1] + 1)

		for i := 0; i <= arr[n-1]; i++ {
			fmt.Printf("%d ", i)
		}

		fmt.Println()
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		var n int

		fmt.Fscan(r, &n)

		a := make([]int, n)
		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &a[j])
		}

		res, arr := solve(a, n)

		if !res {
			fmt.Println("NO")

		} else {
			fmt.Println("YES")
			fmt.Println(len(arr))

			for i := 0; i < len(arr); i++ {
				fmt.Print(arr[i])
				fmt.Print(" ")
			}
			fmt.Println()
		}
	}
}

func solve(a []int, n int)  (bool, []int){

	neg := false
	pos := false

	zero := false

	for i := 0; i < n; i++ {
		if a[i] > 0 {
			pos = true
		}
		if a[i] < 0 {
			neg = true
		}
		if a[i] == 0 {
			zero = true
		}
	}

	if neg && pos {
		return false, []int{}
	}

	sort.Ints(a)

	max := a[len(a) - 1]
	min := a[0]

	var ans []int

	if pos {
		for i := 1; i <= max; i++ {
			ans = append(ans, i)
		}
		if zero {
			ans = append(ans, 0)
		}
		return true, ans

	} else {
		for i := -1; i  >= min; i-- {
			ans = append(ans, i)
		}
		if zero {
			ans = append(ans, 0)
		}

		return true, ans
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		var n int

		fmt.Fscan(r, &n)

		a := make([]int, n)
		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &a[j])
		}

		res, arr := solve(a, n)

		if !res {
			fmt.Println("NO")

		} else {
			fmt.Println("YES")
			fmt.Println(len(arr))

			for i := 0; i < len(arr); i++ {
				fmt.Print(arr[i])
				fmt.Print(" ")
			}
			fmt.Println()
		}
	}
}

func solve(a []int, n int)  (bool, []int){

	neg := false
	pos := false

	zero := false

	for i := 0; i < n; i++ {
		if a[i] > 0 {
			pos = true
		}
		if a[i] < 0 {
			neg = true
		}
		if a[i] == 0 {
			zero = true
		}
	}

	if neg && pos {
		return false, []int{}
	}

	sort.Ints(a)

	max := a[len(a) - 1]
	min := a[0]

	var ans []int

	if pos {
		for i := 1; i <= max; i++ {
			ans = append(ans, i)
		}
		if zero {
			ans = append(ans, ans[0])
		}
		return true, ans
	} else {
		for i := -1; i  >= min; i++ {
			ans = append(ans, i)
		}
		if zero {
			ans = append(ans, ans[0])
		}

		return true, ans
	}

	return true, ans
}

func abs(x int) int {
	if x < 0 {
		return - x
	}
	return x
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		var n int

		fmt.Fscan(r, &n)

		a := make([]int, n)
		for j := 0; j < n; j ++ {
			fmt.Fscan(r, &a[j])
		}

		res, arr := solve(a, n)

		if !res {
			fmt.Println("NO")

		} else {
			fmt.Println("YES")
			fmt.Println(len(arr))

			for i := 0; i < len(arr); i++ {
				fmt.Print(arr[i])
				fmt.Print(" ")
			}
			fmt.Println()
		}
	}
}

func solve(a []int, n int)  (bool, []int){

	neg := false
	pos := false

	for i := 0; i < n; i++ {
		if a[i] > 0 {
			pos = true
		}
		if a[i] < 0 {
			neg = true
		}
	}

	if neg && pos {
		return false, []int{}
	}

	sort.Ints(a)

	max := a[len(a) - 1]
	min := a[0]

	var ans []int

	if pos {
		for i := 1; i <= max; i++ {
			ans = append(ans, i)
		}
		return true, ans
	} else {
		for i := -1; i  >= min; i++ {
			ans = append(ans, i)
		}
		return true, ans
	}

	return true, ans
}

func abs(x int) int {
	if x < 0 {
		return - x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) string {
	max := 0
	for _, x := range a {
		if x < 0 {
			return "No"
		}
		if max < x {
			max = x
		}
	}
	r := "Yes\n" + fmt.Sprintf("%d", max) + "\n"
	for i := 0; i <= max; i++ {
		r += fmt.Sprintf("%d ", i)
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) string {
	max := 0
	for _, x := range a {
		if x < 0 {
			return "No"
		}
		if max < x {
			max = x
		}
	}
	r := "Yes\n"
	for i := 0; i <= max; i++ {
		r += fmt.Sprintf("%d ", i)
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

import(
    "fmt"
)

func main(){
    var i int
    fmt.Scan(&i)
    for i>0{
		i--
		var n int
		fmt.Scan(&n)
		ans:="yes"
		for j:=0;j<n;j++{
			var k int
			fmt.Scan(&k)
			if k<0{
				ans="no"
			}
		}
		fmt.Println(ans)
		if ans=="yes"{
			for j:=0;j<=100;j++{
				fmt.Print(j," ")
			}
			println()
		}
    }
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if a[0] < 0 && a[n-1] > 0 {
			Fprintln(out, "no")
			return
		}
		Fprintln(out, "yes")
		if a[0] >=0 {
			Fprintln(out, a[n-1]+1)
			for i := 0; i <= a[n-1]; i++ {
				Fprint(out, i, " ")
			}
		} else {
			Fprintln(out, -a[0]+1)
			for i := 0; i <= -a[0]; i++ {
				Fprint(out, -i, " ")
			}
		}
		Fprintln(out)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }