You are a given an array $$$a$$$ of length $$$n$$$. Find a subarray $$$a[l..r]$$$ with length at least $$$k$$$ with the largest median.A median in an array of length $$$n$$$ is an element which occupies position number $$$\lfloor \frac{n + 1}{2} \rfloor$$$ after we sort the elements in non-decreasing order. For example: $$$median([1, 2, 3, 4]) = 2$$$, $$$median([3, 2, 1]) = 2$$$, $$$median([2, 1, 2, 1]) = 1$$$.Subarray $$$a[l..r]$$$ is a contiguous part of the array $$$a$$$, i. e. the array $$$a_l,a_{l+1},\ldots,a_r$$$ for some $$$1 \leq l \leq r \leq n$$$, its length is $$$r - l + 1$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq n$$$).

Output one integer $$$m$$$ — the maximum median you can get.

NoteIn the first example all the possible subarrays are $$$[1..3]$$$, $$$[1..4]$$$, $$$[1..5]$$$, $$$[2..4]$$$, $$$[2..5]$$$ and $$$[3..5]$$$ and the median for all of them is $$$2$$$, so the maximum possible median is $$$2$$$ too.In the second example $$$median([3..4]) = 3$$$.

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"
	"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"
	"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"
	"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 {
			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


Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of $$$n$$$ distinct integers. An array $$$b = [b_1, b_2, \ldots, b_k]$$$ is called nice if for any two distinct elements $$$b_i, b_j$$$ of $$$b$$$, $$$|b_i-b_j|$$$ appears in $$$b$$$ at least once. In addition, all elements in $$$b$$$ must be distinct. Can you add several (maybe, $$$0$$$) integers to $$$a$$$ to create a nice array $$$b$$$ of size at most $$$300$$$? If $$$a$$$ is already nice, you don't have to add any elements.For example, array $$$[3, 6, 9]$$$ is nice, as $$$|6-3|=|9-6| = 3$$$, which appears in the array, and $$$|9-3| = 6$$$, which appears in the array, while array $$$[4, 2, 0, 6, 9]$$$ is not nice, as $$$|9-4| = 5$$$ is not present in the array.For integers $$$x$$$ and $$$y$$$, $$$|x-y| = x-y$$$ if $$$x > y$$$ and $$$|x-y| = y-x$$$ otherwise.

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \leq t \leq 50$$$), the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ distinct integers $$$a_1, a_2, \cdots, a_n$$$ ($$$-100 \leq a_i \leq 100$$$) — the elements of the array $$$a$$$.

For each test case, output one line containing YES if Omkar can create a nice array $$$b$$$ by adding elements to $$$a$$$ and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted. If the first line is YES, output a second line containing a single integer $$$k$$$ ($$$n \leq k \leq 300$$$).  Then output one line containing $$$k$$$ distinct integers $$$b_1, b_2, \cdots, b_k$$$ ($$$-10^9 \leq b_i \leq 10^9$$$), the elements of the nice array $$$b$$$. $$$b_1, b_2, \cdots, b_k$$$ can be in any order. For each $$$a_i$$$ in $$$a$$$, $$$a_i$$$ must appear at least once in $$$b$$$. It can be proved that if Omkar can create such an array $$$b$$$, then he can also do so in a way that satisfies the above constraints. If multiple solutions exist, you can print any.

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

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
// 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) }


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Let $$$min(l, r)$$$ be the minimum value among $$$a_l, a_{l + 1}, \ldots, a_r$$$ and $$$max(l, r)$$$ be the maximum value among $$$a_l, a_{l + 1}, \ldots, a_r$$$.Your task is to choose three positive (greater than $$$0$$$) integers $$$x$$$, $$$y$$$ and $$$z$$$ such that:  $$$x + y + z = n$$$;  $$$max(1, x) = min(x + 1, x + y) = max(x + y + 1, n)$$$. In other words, you have to split the array $$$a$$$ into three consecutive non-empty parts that cover the whole array and the maximum in the first part equals the minimum in the second part and equals the maximum in the third part (or determine it is impossible to find such a partition).Among all such triples (partitions), you can choose any.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer: NO in the only line if there is no such partition of $$$a$$$ that satisfies the conditions from the problem statement. Otherwise, print YES in the first line and three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$x + y + z = n$$$) in the second line. If there are several answers, you can print any.

YES
6 1 4
NO
YES
2 5 2
YES
4 1 2
YES
1 1 3
YES
2 1 4

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

// 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) []int {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		const border int = 2e9
		type pair struct{ v, i int }

		posL := make([]int, n)
		for i := range posL {
			posL[i] = -1
		}
		stack := []pair{{border, -1}}
		for i, v := range a {
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posL[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		posR := make([]int, n)
		for i := range posR {
			posR[i] = n
		}
		stack = []pair{{border, n}}
		for i := n - 1; i >= 0; i-- {
			v := a[i]
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posR[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		mx := bits.Len(uint(n)) + 1
		st := make([][]int, n)
		for i, v := range a {
			st[i] = make([]int, mx)
			st[i][0] = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = max(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}

		qmax := func(l, r int) int { k := bits.Len(uint(r-l)) - 1; return max(st[l][k], st[r-1<<k][k]) }

		st2 := make([][]int, n)
		for i, v := range a {
			st2[i] = make([]int, mx)
			st2[i][0] = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st2[i][j] = min(st2[i][j-1], st2[i+1<<(j-1)][j-1])
			}
		}

		qmin := func(l, r int) int { k := bits.Len(uint(r-l)) - 1; return min(st2[l][k], st2[r-1<<k][k]) }

		pos := map[int][]int{}
		for i, v := range a {
			pos[v] = append(pos[v], i)
		}

		for v, ps := range pos {
			if len(ps) < 3 || qmax(0, ps[0]+1) > v || qmax(ps[len(ps)-1], n) > v {
				continue
			}
			ll, rr := -1, -1
			occCnt, occI := 0, 0
			for i := 1; i < len(ps); i++ {
				l, r := ps[i-1], ps[i]
				if qmax(l, r) > v {
					occCnt++
					occI = i
					if ll == -1 {
						ll = posR[l]
					}
					rr = posL[r]
				}
			}
			if ll == -1 {
				l := ps[1]
				return []int{l, 1, n - 1 - l}
			}
			if occCnt == 1 {
				if occI == 1 {
					rr = ps[occI]
				} else if occI == len(ps)-1 {
					ll = ps[occI-1]
				} else {
					if qmin(ps[occI-1], rr) >= v {
						ll = ps[occI-1]
					} else {
						rr = ps[occI]
					}
				}
			}

			if qmin(ll, rr+1) < v {
				continue
			}
			return []int{ll, rr - ll + 1, n - rr - 1}
		}
		return nil
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		a := solve(Case)
		if len(a) == 0 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		Fprintln(out, a[0], a[1], a[2])
	}
}

func main() { run(os.Stdin, os.Stdout) }
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"
	"io"
	"math/bits"
	"os"
)

// 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) []int {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		const border int = 2e9
		type pair struct{ v, i int }

		posL := make([]int, n)
		for i := range posL {
			posL[i] = -1
		}
		stack := []pair{{border, -1}}
		for i, v := range a {
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posL[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		posR := make([]int, n)
		for i := range posR {
			posR[i] = n
		}
		stack = []pair{{border, n}}
		for i := n - 1; i >= 0; i-- {
			v := a[i]
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posR[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		mx := bits.Len(uint(n)) + 1
		st := make([][]int, n)
		for i, v := range a {
			st[i] = make([]int, mx)
			st[i][0] = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = max(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}

		qmax := func(l, r int) int { k := bits.Len(uint(r-l)) - 1; return max(st[l][k], st[r-1<<k][k]) }

		st2 := make([][]int, n)
		for i, v := range a {
			st2[i] = make([]int, mx)
			st2[i][0] = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st2[i][j] = min(st2[i][j-1], st2[i+1<<(j-1)][j-1])
			}
		}

		qmin := func(l, r int) int { k := bits.Len(uint(r-l)) - 1; return min(st2[l][k], st2[r-1<<k][k]) }

		pos := map[int][]int{}
		for i, v := range a {
			pos[v] = append(pos[v], i)
		}

		for v, ps := range pos {
			if len(ps) < 3 {
				continue
			}
			if qmax(0, ps[0]+1) > v || qmax(ps[len(ps)-1], n) > v {
				continue
			}
			ll, rr := -1, -1
			tmpll := -1
			cntMidMax := 0
			for i := 1; i < len(ps); i++ {
				l, r := ps[i-1], ps[i]
				if qmax(l, r) > v {
					if ll == -1 {
						ll  = posR[l]
						tmpll = l
						//ll = l
					}

					if rr == -1 {
						rr = r-1
					} else {
						rr = posL[r]
					}
					//rr = r

					cntMidMax++

				}
			}
			//for i := 1; i < len(ps); i++ {
			//	l, r := ps[i-1], ps[i]
			//	mx := qmax(l, r)
			//
			//	if mx > v {
			//		if ll == -1 {
			//			p := posR[l]
			//			if qmin(p, r) < v {
			//				continue o
			//			}
			//			ll = p
			//		} else {
			//			p := posL[r]
			//			if qmin(l,p) < v {
			//				continue o
			//			}
			//			rr = p
			//		}
			//
			//	}
			//}
			if ll == -1 {
				l := ps[1]
				return []int{l, 1, n - 1 - l}
			}

if cntMidMax == 1 {
	ll = tmpll
}

			if qmin(ll,rr) != v { // todo
				ll = tmpll
				if qmin(ll,rr+1) < v {
					continue
				}

			}

			return []int{ll, rr - ll + 1, n - rr - 1}
		}
		return nil
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		a := solve(Case)
		if len(a) == 0 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		Fprintln(out, a[0], a[1], a[2])
	}
}

func main() { run(os.Stdin, os.Stdout) }
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"
	"io"
	"math/bits"
	"os"
)

// 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) []int {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		const border int = 2e9
		type pair struct{ v, i int }

		posL := make([]int, n)
		for i := range posL {
			posL[i] = -1
		}
		stack := []pair{{border, -1}}
		for i, v := range a {
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posL[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		posR := make([]int, n)
		for i := range posR {
			posR[i] = n
		}
		stack = []pair{{border, n}}
		for i := n - 1; i >= 0; i-- {
			v := a[i]
			for {
				if top := stack[len(stack)-1]; top.v > v { //
					posR[i] = top.i
					break
				}
				stack = stack[:len(stack)-1]
			}
			stack = append(stack, pair{v, i})
		}

		mx := bits.Len(uint(n)) + 1
		st := make([][]int, n)
		for i, v := range a {
			st[i] = make([]int, mx)
			st[i][0] = v
		}
		for j := 1; 1<<j <= n; j++ {
			for i := 0; i+1<<j <= n; i++ {
				st[i][j] = max(st[i][j-1], st[i+1<<(j-1)][j-1])
			}
		}

		q := func(l, r int) int { k := bits.Len(uint(r-l)) - 1; return max(st[l][k], st[r-1<<k][k]) }

		pos := map[int][]int{}
		for i, v := range a {
			pos[v] = append(pos[v], i)
		}
		for v, ps := range pos {
			if len(ps) < 3 {
				continue
			}
			if q(0, ps[0]+1) > v || q(ps[len(ps)-1], n) > v {
				continue
			}
			ll, rr := -1, -1
			for i := 1; i < len(ps); i++ {
				l, r := ps[i-1], ps[i]
				mx := q(l, r)
				if mx > v {
					if ll == -1 {
						ll  = posR[l]
						//ll = l
					}
					rr = posL[r]
					//rr = r
				}
			}
			if ll == -1 {
				l := ps[1]
				return []int{l , 1, n-1-l}
			}
			return []int{ll , rr - ll + 1, n - rr-1}
		}
		return nil
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		a := solve(Case)
		if len(a) == 0 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		Fprintln(out, a[0], a[1], a[2])
	}
}

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