You have an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are positive integers.In one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i \neq j$$$; $$$i \neq k$$$; $$$j \neq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i. e. make $$$a_i = a_j + a_k$$$.Can you make all $$$a_i$$$ lower or equal to $$$d$$$ using the operation above any number of times (possibly, zero)?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$3 \le n \le 100$$$; $$$1 \le d \le 100$$$) — the number of elements in the array $$$a$$$ and the value $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$) — the array $$$a$$$.

For each test case, print YES, if it's possible to make all elements $$$a_i$$$ less or equal than $$$d$$$ using the operation above. Otherwise, print NO. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

NoteIn the first test case, we can prove that we can't make all $$$a_i \le 3$$$.In the second test case, all $$$a_i$$$ are already less or equal than $$$d = 4$$$.In the third test case, we can, for example, choose $$$i = 5$$$, $$$j = 1$$$, $$$k = 2$$$ and make $$$a_5 = a_1 + a_2 = 2 + 1 = 3$$$. Array $$$a$$$ will become $$$[2, 1, 5, 3, 3]$$$.After that we can make $$$a_3 = a_5 + a_2 = 3 + 1 = 4$$$. Array will become $$$[2, 1, 4, 3, 3]$$$ and all elements are less or equal than $$$d = 4$$$.

package main

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

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

func (in *CF1473A) 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 *CF1473A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1473A
 Date: 2/04/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1473/A
 Problem: CF1473A
**/
func (in *CF1473A) Run() {
	T := in.NextInt()
	for ; T > 0; T-- {
		N := in.NextInt()
		D := in.NextInt()
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			value := in.NextInt()
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}

}

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

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

package main

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

type CFRead struct {
	sc *bufio.Reader
	split []string
	index int
}
func (read *CFRead) GetLine() string {
	line, err := read.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:" , line, " err: ", err)
	}
	read.split = []string{}
	return line
}

func (read *CFRead) NextInt() int {
	if len(read.split) <= read.index {
		read.split = strings.Split(read.GetLine()," ")
		read.index = 0
	}
	val, _ := strconv.Atoi(strings.TrimSpace(read.split[read.index]))
	read.index++
	return val
}

func NewCFRead(r *bufio.Reader ) *CFRead {
	return &CFRead{
		sc: r,
		split: []string{},
		index: 0,
	}
}

func main() {

	rd := NewCFRead(bufio.NewReader(os.Stdin))

	T := rd.NextInt()
	for ; T > 0; T-- {
		N := rd.NextInt()
		D := rd.NextInt()
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			value := rd.NextInt()
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := strings.TrimSpace(text)
	T, _ := strconv.Atoi(line)
	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		N, _ = strconv.Atoi(strings.TrimSpace(lines[0]))
		D, _ = strconv.Atoi(strings.TrimSpace(lines[1]))
		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(strings.TrimSpace(lines[i]))
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,d int
		fmt.Fscan(in,&n,&d)
		var lowest,second_lowest int = 999999999,9999999999
		var highest int = 0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x >= highest {
				highest = x
			}
			if x <= lowest {
				second_lowest = lowest
				lowest = x
			}
			if x > lowest && x < second_lowest {
				second_lowest = x
			}
		}
		if d >= highest || lowest+second_lowest <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	min1 := a[0]
	min2 := a[1]
	max:= a[0]
	if a[0] < a[1]{
		max= a[1]
	}
	for i:=2; i < len(a); i++{
		if a[i] > max{
			max=a[i]
		}
		if a[i] < min1{
			if min1 < min2{
				min2 = min1
			}
			min1 = a[i]
		} else {
			if a[i] < min2 {
				min2 = a[i]
			}
		}
	}
	if max <= d || (min1+min2) <= d{return "YES"}
	return "NO"
}

package main

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

func main() {
	var t, n, d, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &d)
		m1 := 1000
		m2 := 1000
		ans := true
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			m1, m2 = getMin(m1, m2, a)
			if a > d {
				ans = false
			}
		}
		if ans || m1+m2 <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

package main

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

func sorting(arr []int32, left int32, right int32) []int32 {
	if left > right {
		return []int32{}
	}
	if left == right {
		return []int32{arr[left]}
	}
	mid := (left + right) / 2
	arrLeft := sorting(arr, left, mid)
	arrRight := sorting(arr, mid+1, right)
	sizeLeft := len(arrLeft)
	sizeRight := len(arrRight)
	startLeft := 0
	startRight := 0
	sorted := []int32{}
	for startLeft < sizeLeft && startRight < sizeRight {
		if arrLeft[startLeft] < arrRight[startRight] {
			sorted = append(sorted, arrLeft[startLeft])
			startLeft++
		} else {
			sorted = append(sorted, arrRight[startRight])
			startRight++
		}
	}
	for startLeft < sizeLeft {
		sorted = append(sorted, arrLeft[startLeft])
		startLeft++
	}
	for startRight < sizeRight {
		sorted = append(sorted, arrRight[startRight])
		startRight++
	}
	return sorted
}

func isValid(d int32, arr []int32) bool {
	for _, value := range arr {
		if value > d {
			return false
		}
	}
	return true
}

func solve(n int32, d int32, arr []int32) string {
	sorted := sorting(arr, 0, n-1)
	if isValid(d, arr) || sorted[0]+sorted[1] <= d {
		return "YES"
	} else {
		return "NO"
	}
}

func arrayScanf(in *bufio.Reader, n int32) []int32 {
	m := int32(0)
	arr := []int32{}
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		arr = append(arr, m)
	}
	fmt.Fscanf(in, "\n")
	return arr
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		d := int32(0)

		fmt.Fscanf(in, "%d %d\n", &n, &d)
		arr := arrayScanf(in, n)

		fmt.Fprintf(out, "%s\n", solve(n, d, arr))
		out.Flush()
		tt--
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n, d := scanInt(), scanInt()
		a := make([]int, n)

		for i := 0; i < n; i++ {
			a[i] = scanInt()
		}

		sort.Ints(a)

		switch {
		case a[n-1] <= d:
			fmt.Println("YES")
		case n == 1:
			fmt.Println("NO")
		case a[0]+a[1] <= d:
			fmt.Println("YES")
		default:
			fmt.Println("NO")
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	t := 0
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		n, d := 0, 0
		fmt.Fscan(in, &n, &d)
		var a []int
		mx := 0
		for i := 0; i < n; i++ {
			x := 0
			fmt.Fscan(in, &x)
			if x > mx {
				mx = x
			}
			a = append(a, x)
		}
		sort.Ints(a)
		if a[0]+a[1] <= d || mx <= d {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	out.Flush()
}

package main

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

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

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

func main() {
	defer writer.Flush()
	t, n, d := 0, 0, 0
	scanf("%d\n", &t)
	for test := 0; test < t; test++ {
		scanf("%d %d\n", &n, &d)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			if i + 1 == n {
				scanf("%d\n", &arr[i])
			} else {
				scanf("%d ", &arr[i])
			}
		}
		sort.Ints(arr)
		for i := 2; i < n; i++ {
			if arr[0] + arr[1] < arr[i] {
				arr[i] = arr[0] + arr[1]
			}
		}
		if arr[n - 1] <= d {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

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

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

func solve() {
	var n, d int
	scanf("%d %d\n", &n, &d)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		if i+1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
	}
	sort.Ints(v)
	ans := "NO\n"
	if v[0] + v[1] <= d || v[len(v) - 1] <= d {
		ans = "YES\n"
	}
	printf(ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		min, min1, c := 101, 101, 0
		scanner.Scan()
		tsl := strings.Split(scanner.Text(), " ")
		d, _ := strconv.Atoi(tsl[1])
		scanner.Scan()
		tsl = strings.Split(scanner.Text(), " ")
		for j := 0; j < len(tsl); j++ {
			temp, _ := strconv.Atoi(tsl[j])
			if temp > d {
				c++
			}
			if temp < min {
				min1 = min
				min = temp
			} else if temp < min1 {
				min1 = temp
			}
		}
		if min+min1 > d && c > 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

import (
	"bufio"
	"os"
	"strings"
)

var x = -1

func min(A []int, n int) int {
	var res, y int
	if x != 0 {
		res = A[0]
		y = 0
	} else {
		res = A[n-1]
		y = n - 1
	}
	for i := 0; i < n; i++ {
		if A[i] < res && i != x {
			res = A[i]
			y = i
		}
	}
	x = y
	return res
}

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		nd := getIntln(reader)
		n, d := nd[0], nd[1]
		A := getIntln(reader)
		allLess := true
		x = -1
		for _, v := range A {
			if v > d {
				allLess = false
				break
			}
		}
		if allLess {
			writer.WriteString("YES\n")
		} else {
			a := min(A, n)
			b := min(A, n)
			if a+b <= d {
				writer.WriteString("YES\n")
			} else {
				writer.WriteString("NO\n")
			}
		}
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI()
	for ; cases > 0; cases-- {
		n, d := getI(), getI()
		a := getInts(n)
		sortInts(a)

		if a[n-1] <= d {
			out("YES")
			continue
		}

		if a[0]+a[1] <= d {
			out("YES")
		} else {
			out("NO")
		}
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

func solve() {
	var n, d int
	fmt.Fscan(input, &n, &d)

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

	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	if arr[0] > d || arr[1] > d {
		fmt.Fprintln(output, "NO")
		return
	}

	q := arr[0] + arr[1]

	for i := 2; i < n; i++ {
		if arr[i] > d && q > d {
			fmt.Fprintln(output, "NO")
			return
		}
	}

	fmt.Fprintln(output, "YES")
}

func main() {
	fmt.Fscan(input, &t)

	for t > 0 {
		t--
		solve()
	}

	defer output.Flush()
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	n   int
	d   int
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &d)
		a := make([]int, n)

		flag := true

		for i := range a {

			fmt.Fscan(in, &a[i])

			if a[i] > d {
				flag = false
			}

		}

		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, solve(n, d, a))
		}

	}

}

func solve(n int, d int, a []int) string {

	sort.Ints(a)

	min := a[0] + a[1]

	if min <= d {
		return "YES"
	}

	return "NO"

}

package main

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		var n, d int
		fmt.Fscan(reader, &n, &d)

		alreadyLess := true
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(reader, &a[j])
			if a[j] > d {
				alreadyLess = false
			}
		}

		if alreadyLess {
			fmt.Fprintln(writer, "YES")
			continue
		}

		sort.Ints(a)
		if a[0]+a[1] <= d {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}

	}
}

package main

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

// 2 3 2 5 4
// 2 2 3 4 5
// 1 2 3 5 6
// 1 2 3 5 3
var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	n := ReadInt()
	for i := 0; i < n; i++ {
		size := ReadInt()
		d := ReadInt()
		elements := ReadIntSliceln(size)
		fmt.Println(process(elements, d))
	}
}

const (
	YES = "YES"
	NO  = "NO"
)

func process(a []int, d int) string {
	if len(a) == 1 {
		if a[0] <= d {
			return YES
		}
		return NO
	}
	sort.Ints(a)
	minPossible := true
	if a[0]+a[1] > d {
		minPossible = false
	}
	for i := 0; i < len(a); i++ {
		if a[i] > d && !minPossible {
			return NO
		}
	}
	return YES
}

// ReadInt Read a single integer followed by a space
func ReadInt() (v int) {
	fmt.Fscan(reader, &v)
	return v
}

// ReadIntSliceln reads a line of integers into a slice.
func ReadIntSliceln(size int) []int {
	a := make([]int, size)
	for i := range a {
		fmt.Fscan(reader, &a[i])
	}
	//fmt.Scanf("\n")
	return a
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

func solve() {
    var (
        n, d int
    )
    fmt.Fscan(input, &n, &d)
    a := make([]int, n)
    mm := 0
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
        mm = max(mm, a[i])
    }
    sort.Ints(a)
    if a[0] + a[1] <= d || mm <= d {
        fmt.Fprintln(output, "Yes")
    } else {
        fmt.Fprintln(output, "No")
    }
}

/*
URL:
https://codeforces.com/contest/1473/problem/A
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

var (
	println = fmt.Println

	tc   int
	n, d int
	A    []int
)

func main() {
	defer stdout.Flush()

	tc = readi()
	for i := 0; i < tc; i++ {
		n, d = readi2()
		A = readis(n)

		solve()
	}
}

func solve() {
	ok := true
	for i := 0; i < n; i++ {
		if A[i] > d {
			ok = false
			break
		}
	}
	if ok {
		printf("YES\n")
		return
	}

	sort.Sort(sort.IntSlice(A))

	s := A[0] + A[1]

	if s <= d {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		d := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%s\n", sol(a, d))
	}
}

func sol(a []int64, d int64) string {
	sort.Slice(a, func(il, ir int) bool {
		return a[il] < a[ir]
	})
	if allLess(a, d) {
		return "YES"
	}
	if a[0]+a[1] <= d {
		return "YES"
	}
	return "NO"
}

func allLess(a []int64, d int64) bool {
	for _, n := range a {
		if n > d {
			return false
		}
	}
	return true
}

package main

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

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		var d int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &d)

		ARRAY := make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Fscan(input, &ARRAY[k])
		}

		sort.Ints(ARRAY)

		if ARRAY[0]+ARRAY[1] > d && ARRAY[len(ARRAY)-1] > d {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := strings.TrimSpace(text)
	T, _ := strconv.Atoi(line)
	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		N, _ = strconv.Atoi(strings.TrimSpace(lines[0]))
		D, _ = strconv.Atoi(strings.TrimSpace(lines[1]))
		fmt.Println("Id 3 " , N , " / " , D)
		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		fmt.Println("3 " ,line)
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(strings.TrimSpace(lines[i]))
			fmt.Println("super id 4 :" , value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := strings.TrimSpace(text)
	T, _ := strconv.Atoi(line)
	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		N, _ = strconv.Atoi(strings.TrimSpace(lines[0]))
		D, _ = strconv.Atoi(strings.TrimSpace(lines[1]))
		fmt.Println("Id 3 " , N , " / " , D)
		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		fmt.Println("3 " ,line)
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])
			fmt.Println("super id 4 :" , value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := strings.TrimSpace(text)
	T, _ := strconv.Atoi(line)
	fmt.Println("1 " ,T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		fmt.Println("2 " ,line)
		N, _ = strconv.Atoi(strings.TrimSpace(lines[0]))
		D, _ = strconv.Atoi(strings.TrimSpace(lines[1]))

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		fmt.Println("3 " ,line)
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	fmt.Println("Text ", text)
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)
	fmt.Println("1 " ,T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		fmt.Println("2 " ,line)
		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		fmt.Println("3 " ,line)
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)
	fmt.Println("1 " ,T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")
		fmt.Println("2 " ,line)
		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		fmt.Println("3 " ,line)
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")

		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value,  _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")

		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES",arr[0])
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES",arr[0])
			} else {
				fmt.Println("NO",arr[0])
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")

		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println(arr[0],"YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println(arr[0],"YES")
			} else {
				fmt.Println(arr[0],"NO")
			}
		}

	}
}

package main

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

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

	//6
	//3 1
	//1 1 1
	//3 2
	//1 1 1
	//3 3
	//1 1 1
	//3 4
	//1 1 1
	//3 5
	//1 1 1
	//3 1
	//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	line := text[:len(text)-1]

	T, _ := strconv.Atoi(line)

	for ; T > 0; T-- {
		var N, D = 0, 0
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines := strings.Split(line, " ")

		N, _ = strconv.Atoi(lines[0])
		D, _ = strconv.Atoi(lines[1])

		var arr [100]int
		var ws bool = false
		text, _ = reader.ReadString('\n')
		line = text[:len(text)-1]
		lines = strings.Split(line, " ")
		i := 0
		for ; N > 0; N-- {
			value, _ := strconv.Atoi(lines[i])

			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println(arr[:i],"YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println(arr[:i],"YES")
			} else {
				fmt.Println(arr[:i],"NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

//6
//3 1
//1 1 1
//3 2
//1 1 1
//3 3
//1 1 1
//3 4
//1 1 1
//3 5
//1 1 1
//3 1
//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	var T = 0
	fmt.Scanf("%d\n",&T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		fmt.Scanf("%d %d\n",&N, &D)
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			var value = 0
			fmt.Scan(&value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}

//6
//3 1
//1 1 1
//3 2
//1 1 1
//3 3
//1 1 1
//3 4
//1 1 1
//3 5
//1 1 1
//3 1
//2 1 1
	//	fmt.Println()
	//}
	//
	//return
	var T = 0
	fmt.Scanf("%d\n",&T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		fmt.Scanf("%d %d\n",&N, &D)
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			var value = 0
			fmt.Scanf("%d",&value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}
	//	fmt.Println()
	//}
	//
	//return
	var T = 0
	fmt.Scanf("%d\n",&T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		fmt.Scanf("%d %d\n",&N, &D)
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			var value = 0
			fmt.Scanf("%d",&value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}
	//	fmt.Println()
	//}
	//
	//return
	var T = 0
	fmt.Scanf("%d", &T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		fmt.Scanf("%d %d", &N, &D)
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			var value = 0
			fmt.Scanf("%d", &value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			//fmt.Println("Arr " , arr)
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	//fmt.Println(2000)
	//for j := 0; j < 2000; j++ {
	//	fmt.Println("100 99")
	//	for i := 100; i > 0; i-- {
	//		fmt.Print(i , " ")
	//	}
	//	fmt.Println()
	//}
	//
	//return
	var T = 0
	fmt.Scanf("%d", &T)

	for ; T > 0; T-- {
		var N, D = 0, 0
		fmt.Scanf("%d %d", &N, &D)
		var arr [100]int
		var ws bool = false
		i := 0
		for ; N > 0; N-- {
			var value = 0
			fmt.Scanf("%d", &value)
			if value > D {
				ws = true
			}
			arr[i] = value
			i++
			//arr = append(arr, value)
		}

		if !ws {
			fmt.Println("YES")
		} else {
			sort.Ints(arr[:i])
			if arr[0]+arr[1] <= D {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,d int
		fmt.Scan(&n,&d)
		var lowest,second_lowest int = 999999999,9999999999
		var highest int = 0
		for j:=0;j<n;j++{
			var x int
			fmt.Scan(&x)
			if x >= highest {
				highest = x
			}
			if x <= lowest {
				second_lowest = lowest
				lowest = x
			}
		}
		if d >= highest || lowest+second_lowest <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,d int
		fmt.Scan(&n,&d)
		var lowest,second_lowest int = 999999999,9999999999
		var highest int = 0
		for j:=0;j<n;j++{
			var x int
			fmt.Scan(&x)
			if x >= highest {
				highest = x
			}
			if x <= lowest {
				second_lowest = lowest
				lowest = x
			}
		}
		if d >= highest {
			fmt.Println("YES")
		} else if lowest+second_lowest > d {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,d int
		fmt.Scan(&n,&d)
		var lowest,second_lowest int = 999999999,9999999999
		var highest int = 0
		for j:=0;j<n;j++{
			var x int
			fmt.Scan(&x)
			if x >= highest {
				highest = x
			}
			if x <= lowest {
				second_lowest = lowest
				lowest = x
			}
		}
		if lowest+second_lowest > d {
			if d >= highest {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("YES")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,d int
		fmt.Scan(&n,&d)
		var lowest,second_lowest int = 999999999,9999999999
		var highest int = 0
		for j:=0;j<n;j++{
			var x int
			fmt.Scan(&x)
			if x > highest {
				highest = x
			}
			if x < lowest {
				lowest = x
			}
			if x > lowest && x < second_lowest {
				second_lowest = x
			}
		}
		if lowest+second_lowest > d {
			if d >= highest {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	min1 := a[0]
	min2 := a[0]
	max:= a[0]
	for i:=1; i < len(a); i++{
		if a[i] > max{
			max=a[i]
		}
		if a[i] < min1{
			if min1 < min2{
				min2 = min1
			}
			min1 = a[i]
		} else {
			if a[i] < min2 {
				min2 = a[i]
			}
		}
	}
	if max <= d || (min1+min2) <= d{return "YES"}
	return "NO"
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	min1 := a[0]
	min2 := a[0]
	max:= a[0]
	for i:=1; i < len(a); i++{
		if a[i] > max{
			max=a[i]
		}
		if a[i] < min1{
			if min1 < min2{
				min2 = min1
			}
			min1 = a[i]
		} else {
			if a[i] < min2 && a[i] != min1 {
				min2 = a[i]
			}
		}
	}
	if max <= d || (min1+min2) <= d{return "YES"}
	return "NO"
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	min1 := 101
	min2 := 101
	max:= -1
	for i:=0; i < len(a); i++{
		if a[i] > max{
			max=a[i]
		}
		if a[i] < min1{
			if min1 < min2{
				min2 = min1
			}
			min1 = a[i]
		}
		if a[i] < min2 && a[i] != min1{
			min2 = a[i]
		}
	}
	if max <= d || (min1+min2) <= d{return "YES"}
	return "NO"
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	min1 := 101
	min2 := 101
	max:= -1
	for i:=0; i < len(a)-1; i++{
		if a[i] > max{
			max=a[i]
		}
		if a[i] < min1{
			if min1 < min2{
				min2 = min1
			}
			min1 = a[i]
		}
		if a[i] < min2 && a[i] != min1{
			min2 = a[i]
		}
	}
	if max <= d || (min1+min2) < d{return "YES"}
	return "NO"
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	ns,_:=strconv.Atoi(sc.Text())

	for i:=0; i < ns; i++{
		sc.Scan()
		d, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[1])
		l, _ :=strconv.Atoi(strings.Split(sc.Text(), " ")[0])
		a := make([]int, l)
		sc.Scan()
		for j,el := range strings.Split(sc.Text()," "){
			a[j],_ = strconv.Atoi(el)
		}
		fmt.Printf("%s\n",fn(a, d))
	}
}

func fn(a []int, d int) string{
	more := false
	for i:=0; i < len(a)-1; i++{
		if !(a[i] <= d){
			more = true
		}
		if (a[i] + a[i+1]) <= d{
			return "YES"
		}
	}
	if more{
		return "NO"
	}
	return "YES"
}

package main

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

func main() {
	var t, n, d, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &d)
		m1 := 1000
		m2 := 1000
		ans := true
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			if a <= m1 {
				m2 = m1
				m1 = a
			}
			if a > d {
				ans = false
			}
		}
		if ans || m1+m2 <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t, n, d, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &d)
		m1 := 1000
		m2 := 1000
		ans := true
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			if a < m1 {
				m2 = m1
				m1 = a
			}
			if a > d {
				ans = false
			}
		}
		if ans || m1+m2 <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t, n, d, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &d)
		m1 := math.MaxInt32
		m2 := math.MaxInt32
		ans := true
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			if a < m1 {
				m2 = m1
				m1 = a
			}
			if a > d {
				ans = false
			}
		}
		if ans || m1+m2 <= d {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func sorting(arr []int32, left int32, right int32) []int32 {
	if left > right {
		return []int32{}
	}
	if left == right {
		return []int32{arr[left]}
	}
	mid := (left + right) / 2
	arrLeft := sorting(arr, left, mid)
	arrRight := sorting(arr, mid+1, right)
	sizeLeft := len(arrLeft)
	sizeRight := len(arrRight)
	startLeft := 0
	startRight := 0
	sorted := []int32{}
	for startLeft < sizeLeft && startRight < sizeRight {
		if arrLeft[startLeft] < arrRight[startRight] {
			sorted = append(sorted, arrLeft[startLeft])
			startLeft++
		} else {
			sorted = append(sorted, arrRight[startRight])
			startRight++
		}
	}
	for startLeft < sizeLeft {
		sorted = append(sorted, arrLeft[startLeft])
		startLeft++
	}
	for startRight < sizeRight {
		sorted = append(sorted, arrRight[startRight])
		startRight++
	}
	return sorted
}

func isValid(d int32, arr []int32) bool {
	for _, value := range arr {
		if value > d {
			return false
		}
	}
	return true
}

func solve(n int32, d int32, arr []int32) string {
	sorted := sorting(arr, 0, n-1)
	if isValid(d, arr) || sorted[0]+sorted[1] <= d {
		return "YES"
	} else {
		return "NO"
	}
}

func arrayScanf(in *bufio.Reader, n int32) []int32 {
	m := int32(0)
	arr := []int32{}
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		arr = append(arr, m)
	}
	fmt.Fscanf(in, "\n")
	return arr
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		d := int32(0)
		arr := arrayScanf(in, n)
		fmt.Fprintf(out, "%s\n", solve(n, d, arr))
		out.Flush()
		tt--
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n, d := scanInt(), scanInt()
		a := make([]int, n)

		for i := 0; i < n; i++ {
			a[i] = scanInt()
		}

		switch {
		case a[n-1] <= d:
			fmt.Println("YES")
		case n == 1:
			fmt.Println("NO")
		case a[0]+a[1] <= d:
			fmt.Println("YES")
		default:
			fmt.Println("NO")
		}
	}
}


Vasya has got $$$n$$$ books, numbered from $$$1$$$ to $$$n$$$, arranged in a stack. The topmost book has number $$$a_1$$$, the next one — $$$a_2$$$, and so on. The book at the bottom of the stack has number $$$a_n$$$. All numbers are distinct.Vasya wants to move all the books to his backpack in $$$n$$$ steps. During $$$i$$$-th step he wants to move the book number $$$b_i$$$ into his backpack. If the book with number $$$b_i$$$ is in the stack, he takes this book and all the books above the book $$$b_i$$$, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order $$$[1, 2, 3]$$$ (book $$$1$$$ is the topmost), and Vasya moves the books in the order $$$[2, 1, 3]$$$, then during the first step he will move two books ($$$1$$$ and $$$2$$$), during the second step he will do nothing (since book $$$1$$$ is already in the backpack), and during the third step — one book (the book number $$$3$$$). Note that $$$b_1, b_2, \dots, b_n$$$ are distinct.Help Vasya! Tell him the number of books he will put into his backpack during each step.

The first line contains one integer $$$n~(1 \le n \le 2 \cdot 10^5)$$$ — the number of books in the stack. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(1 \le a_i \le n)$$$ denoting the stack of books. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n~(1 \le b_i \le n)$$$ denoting the steps Vasya is going to perform. All numbers $$$a_1 \dots a_n$$$ are distinct, the same goes for $$$b_1 \dots b_n$$$.

Print $$$n$$$ integers. The $$$i$$$-th of them should be equal to the number of books Vasya moves to his backpack during the $$$i$$$-th step.

NoteThe first example is described in the statement.In the second example, during the first step Vasya will move the books $$$[3, 1, 4]$$$. After that only books $$$2$$$ and $$$5$$$ remain in the stack ($$$2$$$ is above $$$5$$$). During the second step Vasya will take the books $$$2$$$ and $$$5$$$. After that the stack becomes empty, so during next steps Vasya won't move any books.

package main

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

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

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

func pubChan(s []int, c chan int) {
	for _, val := range s {
		c <- val
	}
	close(c)
}

func solution(stack, sequence []int) []int {
	solSeq := make([]int, len(sequence))
	had := make(map[int]bool)

	s, q := make(chan int, len(sequence)), make(chan int, len(sequence))
	go pubChan(stack, s)
	go pubChan(sequence, q)

	index, counter := 0, 0

	for qVal := range q {
		if _, ok := had[qVal]; ok {
			// printf("skipping value: %v\n", qVal)
			index++
			continue
		}
		counter = 0

		for sVal := range s {
			// printf("inside inner loop:%v\n", sVal)
			counter++
			if sVal == qVal {
				solSeq[index] = counter
				index++
				// printf("breaked inner loop: %v\n", sVal)
				break
			}
			had[sVal] = true
		}
	}

	return solSeq
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	stack, sequence := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d", &stack[i])
	}
	scanf("\n")
	for i := 0; i < n; i++ {
		scanf("%d", &sequence[i])
	}
	scanf("\n")
	for _, val := range solution(stack, sequence) {
		printf("%v ", val)
	}
	printf("\n")
}

package main

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

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

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

func pubChan(s []int, c chan int) {
	for _, val := range s {
		c <- val
	}
	close(c)
}

func solution(stack, sequence []int) []int {
	solSeq := make([]int, len(sequence))
	had := make(map[int]bool)

	s, q := make(chan int, len(sequence)), make(chan int, len(sequence))
	pubChan(stack, s)
	pubChan(sequence, q)

	index, counter := 0, 0

	for qVal := range q {
		if _, ok := had[qVal]; ok {
			// printf("skipping value: %v\n", qVal)
			index++
			continue
		}
		counter = 0

		for sVal := range s {
			// printf("inside inner loop:%v\n", sVal)
			counter++
			if sVal == qVal {
				solSeq[index] = counter
				index++
				// printf("breaked inner loop: %v\n", sVal)
				break
			}
			had[sVal] = true
		}
	}

	return solSeq
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	stack, sequence := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d", &stack[i])
	}
	scanf("\n")
	for i := 0; i < n; i++ {
		scanf("%d", &sequence[i])
	}
	scanf("\n")
	for _, val := range solution(stack, sequence) {
		printf("%v ", val)
	}
	printf("\n")
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	m := map[string]int{}
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 1; i <= n; i++ {
		scanner.Scan()
		m[scanner.Text()] = i
	}

	top := 0
	result := []string{}
	for i := 1; i <= n; i++ {
		scanner.Scan()
		newTop := m[scanner.Text()]
		if newTop > top {
			result = append(result, strconv.Itoa(newTop-top))
			top = newTop
		} else {
			result = append(result, "0")
		}
	}
	fmt.Println(strings.Join(result, " "))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	stack := make([]int, n)
	place := make([]int, n+1)
	deleted := make([]bool, n+1)

	for i := 0; i < n; i++ {
		scanner.Scan()
		bookID, _ := strconv.Atoi(scanner.Text())

		stack[i] = bookID
		place[bookID] = i
		deleted[bookID] = false
	}

	bottom := -1
	for i := 0; i < n; i++ {
		scanner.Scan()
		bookID, _ := strconv.Atoi(scanner.Text())

		pos := place[bookID]
		cnt := max(pos-bottom, 0)
		bottom = max(pos, bottom)

		fmt.Println(cnt)
	}
}

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

// A simple #ad-hoc problem.
package main

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

func main() {
	N, _ := strconv.Atoi(readLine())
	a := make([]int, N)
	b := make([]int, N)
	m := map[int]int{}
	counter := 0
	for i, raw := range strings.Split(readLine(), " ") {
		a[i], _ = strconv.Atoi(raw)
		m[a[i]] = i + 1
	}
	for i, raw := range strings.Split(readLine(), " ") {
		b[i], _ = strconv.Atoi(raw)
	}

	steps := make([]string, N)
	for i := 0; i < N; i++ {
		step := m[b[i]] - counter
		if step < 0 {
			steps[i] = "0"
		} else {
			steps[i] = strconv.Itoa(step)
			counter = m[b[i]]
		}
	}
	fmt.Println(strings.Join(steps, " "))
}

var scanner = bufio.NewScanner(os.Stdin)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

package main

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

func main() {
	m := map[string]int{}
	readLine()
	for i, s := range strings.Split(readLine(), " ") {
		m[s] = i + 1
	}
	top := 0
	for _, s := range strings.Split(readLine(), " ") {
		newTop := m[s]
		if newTop > top {
			fmt.Println(newTop - top)
			top = newTop
		} else {
			fmt.Println(0)
		}
	}
}

var scanner = bufio.NewScanner(os.Stdin)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

package main

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

func main() {
	m := map[string]int{}
	readLine()
	for i, s := range strings.Split(readLine(), " ") {
		m[s] = i + 1
	}
	top := 0
	result := []string{}
	for _, s := range strings.Split(readLine(), " ") {
		newTop := m[s]
		if newTop > top {
			result = append(result, strconv.Itoa(newTop-top))
			top = newTop
		} else {
			result = append(result, "0")
		}
	}
	fmt.Println(strings.Join(result, " "))
}

var scanner = bufio.NewReader(os.Stdin)

func readLine() string {
	line, _, _ := scanner.ReadLine()
	return string(line)
}


You are given a problemset consisting of $$$n$$$ problems. The difficulty of the $$$i$$$-th problem is $$$a_i$$$. It is guaranteed that all difficulties are distinct and are given in the increasing order.You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let $$$a_{i_1}, a_{i_2}, \dots, a_{i_p}$$$ be the difficulties of the selected problems in increasing order. Then for each $$$j$$$ from $$$1$$$ to $$$p-1$$$ $$$a_{i_{j + 1}} \le a_{i_j} \cdot 2$$$ should hold. It means that the contest consisting of only one problem is always valid.Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems in the problemset. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

NoteDescription of the first example: there are $$$10$$$ valid contests consisting of $$$1$$$ problem, $$$10$$$ valid contests consisting of $$$2$$$ problems ($$$[1, 2], [5, 6], [5, 7], [5, 10], [6, 7], [6, 10], [7, 10], [21, 23], [21, 24], [23, 24]$$$), $$$5$$$ valid contests consisting of $$$3$$$ problems ($$$[5, 6, 7], [5, 6, 10], [5, 7, 10], [6, 7, 10], [21, 23, 24]$$$) and a single valid contest consisting of $$$4$$$ problems ($$$[5, 6, 7, 10]$$$).In the second example all the valid contests consist of $$$1$$$ problem.In the third example are two contests consisting of $$$3$$$ problems: $$$[4, 7, 12]$$$ and $$$[100, 150, 199]$$$.

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n,pre int
	Scan(&n,&pre)
	max:=1
	cnt:=1
	in:=bufio.NewReader(os.Stdin)
	for i:=1;i<n;i++{
		var cur int
		Fscan(in,&cur)
		if cur<=pre<<1{
			cnt++
			if max<cnt{
				max=cnt
			}
		}else{
			cnt=1
		}
		pre=cur
	}

	Print(max)
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n,pre int
	Scan(&n,&pre)
	max:=1
	cnt:=1
	in:=bufio.NewReader(os.Stdin)
	for i:=1;i<n;i++{
		var cur int
		Fscan(in,&cur)
		if cur<=pre<<1{
			cnt++
		}else{
			if max<cnt{
				max=cnt
			}
			cnt=1
		}
		pre=cur
	}

	if max<cnt{
		max=cnt
	}
	Print(max)
}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n int
	fmt.Fscan(in, &n)

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

	max := 1
	cnt := 1
	for i := 0; i < n - 1; i++ {
		if arr[i] * 2 >= arr[i + 1] {
			cnt++
		} else {
			if max < cnt {
				max = cnt
			}
			cnt = 1
		}
	}
	if max < cnt {
		max = cnt
	}

	fmt.Fprintln(out, max)

}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	A := sc.NextIntArray()

	mx := 0
	for i := 0; i < N; i++ {
		j := i + 1
		for ; j < N; j++ {
			if A[j-1]*2 < A[j] {
				if mx < j-i {
					mx = j - i
				}
				break
			}
		}

		if j == N {
			if mx < j-i {
				mx = j - i
			}
		}
		i = j - 1
	}
	fmt.Println(mx)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	Maxn = 200005
)

var n int
var a, dp [Maxn]int

func find(value, end int) int {
	l, r, mid, last := 0, end + 1, end, end
	for l < r {
		mid = (l + r) / 2
		if a[mid] < value {
			l = mid + 1
		} else {
			r = mid
			last = mid
		}
	}
	return last
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	ans := 1
	for i := 0; i < n; i++ {
		threshold := a[i] / 2 + a[i] % 2
		index := find(threshold, i)
		dp[i] = 1
		res := dp[index] + i - index
		if dp[i] < res {
			dp[i] = res
		}
		if ans < dp[i] {
			ans = dp[i]
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"bufio"
	"strconv"
	"os"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n int
	fmt.Scan(&n)
	var l,m,k int
	for i:=0;i<n;i++{
		j := ReadInt32()
		if i == 0 {
			k++
		} else if j <= l *2 {
			k++
		} else if j> l*2  {
			k = 1
		}
		if k>m {
			m = k
		}
		l=j
	}
	fmt.Println(m)
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n,pre int
	Scan(&n,&pre)
	max:=1
	cnt:=1
	in:=bufio.NewReader(os.Stdin)
	for i:=1;i<n;i++{
		var cur int
		Fscan(in,&cur)
		if cur<=pre<<1{
			cnt++
		}else{
			if max<cnt{
				max=cnt
			}
			cnt=1
		}
		pre=cur
	}

	Print(max)
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	A := sc.NextIntArray()

	mx := 0
	for i := 0; i < N; i++ {
		j := i + 1
		for ; j < N; j++ {
			if A[i]*2 < A[j] {
				if mx < j-i {
					mx = j - i
				}
				break
			}
		}
		if j == N {
			if mx < j-i {
				mx = j - i
			}
		}
		i = j - 1
	}
	fmt.Println(mx)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — the number of vertices in the graph and the number of special offers, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) — the numbers written on the vertices. Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \le x, y \le n$$$, $$$1 \le w \le 10^{12}$$$, $$$x \ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.

Print one integer — the minimum number of coins you have to pay to make the graph connected.

NoteIn the first example it is possible to connect $$$1$$$ to $$$2$$$ using special offer $$$2$$$, and then $$$1$$$ to $$$3$$$ without using any offers.In next two examples the optimal answer may be achieved without using special offers.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

type Edge struct {
	p1, p2 int
	cost int64
}

type Edges []Edge
func (es Edges) Len() int {
	return len(es)
}
func (es Edges) Less(i, j int) bool {
	return es[i].cost < es[j].cost
}
func (es Edges) Swap(i, j int) {
	es[i], es[j] = es[j], es[i]
}

func find(u []int, x int) int {
	if u[x] == x {
		return x
	} else {
		u[x] = find(u, u[x])
		return u[x]
	}
}

func associate(u []int, x,y int) {
	ux := find(u, x)
	u[ux] = y
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	var min int64 = 10000000000000
	var minp int
	union := make([]int, n)

	for i := 0;i < n;i ++ {
		union[i] = i
	}

	a := make([]int64, n)
	for i := 0;i < n;i ++ {
		if i != n - 1 {
			fmt.Fscanf(reader, "%d ", &a[i])
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i])
		}
		if a[i] < min {
			min = a[i]
			minp = i
		}
	}
	es := make(Edges, n - 1 + m)
	for i := 0;i < n;i ++ {
		if i != minp {
			es = append(es, Edge{p1: minp, p2: i, cost: min + a[i]})
		}
	}
	for i := 0;i < m;i ++ {
		var e Edge
		fmt.Fscanf(reader, "%d %d %d\n", &e.p1, &e.p2, &e.cost)
		e.p1 --
		e.p2 --
		es = append(es, e)
	}
	sort.Sort(es)
	selected := 0
	var ans int64 = 0
	for i := 0;i < len(es) && selected < n - 1;i ++ {
		e := es[i]
		if find(union, e.p1) != find(union, e.p2) {
			associate(union, e.p1, e.p2)
			ans += e.cost
			selected ++
		}
	}
	fmt.Printf("%d", ans)
}


Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex is connected with its parent by an edge. The parent of vertex i is vertex pi, the parent index is always less than the index of the vertex (i.e., pi < i).The depth of the vertex is the number of nodes on the path from the root to v along the edges. In particular, the depth of the root is equal to 1.We say that vertex u is in the subtree of vertex v, if we can get from u to v, moving from the vertex to the parent. In particular, vertex v is in its subtree.Roma gives you m queries, the i-th of which consists of two numbers vi, hi. Let's consider the vertices in the subtree vi located at depth hi. Determine whether you can use the letters written at these vertices to make a string that is a palindrome. The letters that are written in the vertexes, can be rearranged in any order to make a palindrome, but all letters should be used.

The first line contains two integers n, m (1 ≤ n, m ≤ 500 000) — the number of nodes in the tree and queries, respectively. The following line contains n - 1 integers p2, p3, ..., pn — the parents of vertices from the second to the n-th (1 ≤ pi < i). The next line contains n lowercase English letters, the i-th of these letters is written on vertex i. Next m lines describe the queries, the i-th line contains two numbers vi, hi (1 ≤ vi, hi ≤ n) — the vertex and the depth that appear in the i-th query.

Print m lines. In the i-th line print "Yes" (without the quotes), if in the i-th query you can make a palindrome from the letters written on the vertices, otherwise print "No" (without the quotes).

NoteString s is a palindrome if reads the same from left to right and from right to left. In particular, an empty string is a palindrome.Clarification for the sample test.In the first query there exists only a vertex 1 satisfying all the conditions, we can form a palindrome "z".In the second query vertices 5 and 6 satisfy condititions, they contain letters "с" and "d" respectively. It is impossible to form a palindrome of them.In the third query there exist no vertices at depth 1 and in subtree of 4. We may form an empty palindrome.In the fourth query there exist no vertices in subtree of 6 at depth 1. We may form an empty palindrome.In the fifth query there vertices 2, 3 and 4 satisfying all conditions above, they contain letters "a", "c" and "c". We may form a palindrome "cac".

package main

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

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

	var n, q, v, t, d int
	Fscan(in, &n, &q)
	g := make([][]int, n)
	for w := 1; w < n; w++ {
		Fscan(in, &v)
		g[v-1] = append(g[v-1], w)
	}
	var s string
	Fscan(in, &s)
	tin := make([]int, n)
	tout := make([]int, n)
	depT := make([][]int, n+1)
	dep := make([][]int, n+1)
	for i := range dep {
		dep[i] = []int{0}
	}
	var f func(v, fa, d int)
	f = func(v, fa, d int) {
		t++
		tin[v] = t
		depT[d] = append(depT[d], t)
		dep[d] = append(dep[d], dep[d][len(dep[d])-1]^1<<(s[v]-'a'))
		for _, w := range g[v] {
			if w != fa {
				f(w, v, d+1)
			}
		}
		tout[v] = t
	}
	f(0, -1, 1)

	for ; q > 0; q-- {
		Fscan(in, &v, &d)
		v--
		row := depT[d]
		l := sort.SearchInts(row, tin[v])
		r := sort.SearchInts(row, tout[v]+1)
		c := dep[d][r] ^ dep[d][l]
		if c&(c-1) == 0 {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

	var n, q, v, t, d int
	Fscan(in, &n, &q)
	g := make([][]int, n)
	for w := 1; w < n; w++ {
		Fscan(in, &v)
		g[v-1] = append(g[v-1], w)
	}
	var s string
	Fscan(in, &s)
	tin := make([]int, n)
	tout := make([]int, n)
	dep := make([][]int, n+1)
	depT := make([][]int, n+1)
	for i := range dep {
		dep[i] = []int{0}
		depT[i] = []int{0}
	}
	var f func(v, fa, d int)
	f = func(v, fa, d int) {
		t++
		tin[v] = t
		dep[d] = append(dep[d], dep[d][len(dep[d])-1]^1<<(s[v]-'a'))
		depT[d] = append(depT[d], t)
		for _, w := range g[v] {
			if w != fa {
				f(w, v, d+1)
			}
		}
		tout[v] = t
	}
	f(0, -1, 1)

	for ; q > 0; q-- {
		Fscan(in, &v, &d)
		v--
		row := depT[d]
		l := sort.SearchInts(row, tin[v]) - 1
		r := sort.SearchInts(row, tout[v]+1) - 1
		c := dep[d][r] ^ dep[d][l]
		if c&(c-1) == 0 {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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


Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.Help Okabe determine whether a given lab is good!

The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.  The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 ≤ ai, j ≤ 105).

Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case.

NoteIn the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No".

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([][]int, n)
	for i := range a {
		a[i] = make([]int, n)
		for j := range a[i] {
			fmt.Scan(&a[i][j])
		}
	}
	for i := range a {
	loop:
		for j, v := range a[i] {
			if v == 1 {
				continue
			}
			for s := 0; s < n; s++ {
				for t := 0; t < n; t++ {
					if a[s][j]+a[i][t] == v {
						continue loop
					}
				}
			}
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

package main

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

// var file, err = os.Open("a.in")
// var sc *Scanner = NewScanner(bufio.NewReader(file))
var sc *Scanner = NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

func printSpace() { w.WriteByte(' ') }
func println()    { w.WriteByte('\n') }

func nextToken() string { sc.Scan(); return sc.Text() }

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func nextInt64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func printInt(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		printSpace()
	}
}

func printInt64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		printSpace()
	}
}

func print(s ...string) {
	for _, ss := range s {
		w.WriteString(ss)
		printSpace()
	}
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func min64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func max64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()

	n := nextInt()
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			a[i][j] = nextInt()
		}
	}
	result := true
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if a[i][j] != 1 {
				found := false
				for s := 0; s < n; s++ {
					for t := 0; t < n; t++ {
						if a[i][j] == a[i][s]+a[t][j] {
							found = true
							break
						}
					}
				}
				result = result && found
			}
		}
	}

	if result {
		print("Yes")
	} else {
		print("No")
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	matrix := make([][]int, N)
	for i := 0; i < N; i++ {
		matrix[i] = sc.NextIntArray()
	}

	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if matrix[i][j] == 1 {
				continue
			}

			ok := false
			for k := 0; k < N; k++ {
				if k == i {
					continue
				}
				for l := 0; l < N; l++ {
					if l == j {
						continue
					}

					if matrix[i][j] == matrix[k][j]+matrix[i][l] {
						ok = true
						break
					}
				}
			}
			if !ok {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

// var file, err = os.Open("a.in")
// var sc *Scanner = NewScanner(bufio.NewReader(file))
var sc *Scanner = NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

func printSpace() { w.WriteByte(' ') }
func println()    { w.WriteByte('\n') }

func nextToken() string { sc.Scan(); return sc.Text() }

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func nextInt64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func printInt(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		printSpace()
	}
}

func printInt64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		printSpace()
	}
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func min64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func max64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()

	n := nextInt()
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			a[i][j] = nextInt()
		}
	}
	result := true
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if a[i][j] != 1 {
				found := false
				for s := 0; s < n; s++ {
					for t := 0; t < n; t++ {
						if a[i][j] == a[i][s]+a[t][j] {
							found = true
							break
						}
					}
				}
				result = result && found
			}
		}
	}

	if result {
		print("Yes")
	} else {
		print("No")
	}
}