Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

Chef is at a Code Expo where many coders are present discussing, solving, sharing, and eavesdropping on solutions :P

He recently learnt that a former HackerPlant employee, Reziba, who is now working at KodeKarma stole some questions for their KoolKontest. Chef wants to find Reziba, but the only data he has on him, and everyone else present, are their CodeXP ratings, which are distinct.
Chef decides to find Reziba through his rating by asking different people present at the expo. Everyone present are arranged in such a way that, assuming a person with rating X, every person with a rating higher than X are on the person's right, while every person with a rating lower than X are on the person's left.

Everyone present there knows Reziba's rating, except Chef, who now asks people where he could find Reziba.

Chef initially asks an arbitrary person, who replies by giving information on whether Reziba is to the person's left or the person's right, depending on whether this person has a higher or lower rating than Reziba.

Chef proceeds in that direction for an arbitrary distance and stops and asks the next person encountered, and repeats this procedure.
However, Chef will never go beyond a person whose rating Chef has asked before. For example, if Chef was walking to the left and finds a person who already told him to walk to the right then he will not continue going to the person's left. 
Chef finally finds Reziba when he finally stops in front of Reziba.

During Chef's search for Reziba, he wrote the sequence of ratings of the people Chef asked in the exact same order, including Reziba's rating, which is the last integer in the sequence.
Towards the end, Chef feels he might've made a mistake while writing this sequence.

Given the sequence that Chef wrote and Reziba's rating, find out whether this sequence is possible or has mistakes.

------ Input ------ 

First line contains number of test cases T.
The first line of each test case contains the number of people Chef meets, N and Reziba's rating R seperated by a space.
Second line of each test case contains N number of space separated ratings from A_{1} to A_{N} where A_{N} is always equal to R.

------ Output ------ 

For each test case, output a singe line with either  "YES" if the sequence is correct, or print "NO" if the sequence has mistakes, without quotes.

------ Constraints ------ 

1 ≤ T ≤ 50
1 ≤ N ≤ 10^{6}
1 ≤ sum of N in all test-cases ≤ 1.5*10^{6}
1 ≤ A_{i} ≤ 10^{9}
Integers in A are distinct
A_{N} = R

------ Subtasks ------ 

Subtask #1: N ≤ 20
Subtask #2: Original Constraints
 
----- Sample Input 1 ------ 
2
5 200
600 300 100 350 200
5 890
5123 3300 783 1111 890

----- Sample Output 1 ------ 
NO
YES
----- explanation 1 ------ 
Example case 1.The first person that Chef asked has a rating of 600, which is more than 200 so he tells Chef to go to his left. The second person Chef meets has a rating of 300, also tells Chef to go to the left. The third person that chef asked has a rating of 100 so he tells Chef to go to the right. Then Chef asked a person with rating 350, that means Chef went beyond the person with rating of 300, which should never happen, so Chef must have made a mistake while writing this sequence.

Source: codechef | Difficulty: MEDIUM
Tags: Implementation


Solutions:
t = int(input())
for jhj in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	if n < 3:
		print('YES')
		continue
	b = a[0:n - 1]
	mini = min(b)
	maxi = max(b)
	ans = 'YES'
	for i in b:
		if i > r and i <= maxi:
			maxi = i
		elif i < r and i >= mini:
			mini = i
		else:
			ans = 'NO'
	print(ans)


for i in range(int(input())):
	(person_cnt, reziba_rating) = map(int, input().split())
	person_rating_array = [int(x) for x in input().split()]
	left_max = 9999999999
	right_max = -999999999
	found = True
	for i in person_rating_array:
		if i > reziba_rating:
			if i < left_max:
				left_max = i
			else:
				found = False
				break
		elif i < reziba_rating:
			if i > right_max:
				right_max = i
			else:
				found = False
				break
	if found:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	x = list(map(int, input().split()))
	above = []
	below = []
	ans = [0] * (n - 1)
	for i in range(len(ans)):
		ans[i] = x[i] - r
	for i in ans:
		if i > 0:
			above.append(i)
		elif i < 0:
			below.append(i)
	if sorted(above, reverse=True) == above and below == sorted(below):
		print('YES')
	else:
		print('NO')


z = int(input())
for k in range(z):
	(n, k) = map(int, input().split())
	c = input().split(' ')
	c = [int(i) for i in c]
	u = 10 ** 9 + 1
	l = -1
	flag = False
	for i in range(1, len(c)):
		if c[i] < c[i - 1]:
			if c[i] <= l:
				flag = True
				break
			u = c[i - 1]
		if c[i] > c[i - 1]:
			if c[i] >= u:
				flag = True
				break
			l = c[i - 1]
	if c[-1] != k:
		flag = True
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(l, r) = (0, 0)
	flag = 'YES'
	(N, R) = input().split()
	N = int(N)
	R = int(R)
	A = input().split()
	for i in range(N):
		A[i] = int(A[i])
	for i in range(N):
		if l != 0 and A[i] < l or (r != 0 and A[i] > r):
			flag = 'NO'
			break
		if R < A[i]:
			r = A[i]
		elif R > A[i]:
			l = A[i]
	print(flag)


for _ in range(int(input())):
	(people, rez) = list(map(int, input().split()))
	people_ratings = list(map(int, input().split()))
	lowest_max = 0
	highest_min = 0
	found = False
	possible = True
	for item in range(people):
		compare = people_ratings[item]
		if compare > rez:
			if compare > lowest_max and lowest_max != 0:
				possible = False
				break
			lowest_max = compare
		elif compare < rez:
			if compare < highest_min:
				possible = False
				break
			highest_min = compare
	if possible:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	a = [int(x) - r for x in input().split()]
	ap = []
	an = []
	for j in range(n):
		if a[j] > 0:
			ap.append(a[j])
	for j in range(n):
		if a[j] < 0:
			an.append(a[j])
	AP = []
	AN = []
	AP = sorted(ap, reverse=True)
	AN = sorted(an)
	if AP == ap and AN == an:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	arr = [int(x) - r for x in input().split()]
	ap = []
	an = []
	for j in range(n):
		if arr[j] > 0:
			ap.append(arr[j])
	for j in range(n):
		if arr[j] < 0:
			an.append(arr[j])
	AP = []
	AN = []
	AP = sorted(ap, reverse=True)
	AN = sorted(an)
	if AP == ap and AN == an:
		print('YES')
	else:
		print('NO')


def sub(arr, num):
	result = []
	for i in arr:
		result.append(i - num)
	return result
for _ in range(int(input())):
	(n, r) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	result = sub(arr, r)
	ap = []
	an = []
	for j in range(n):
		if result[j] > 0:
			ap.append(result[j])
		elif result[j] < 0:
			an.append(result[j])
	AP = []
	AN = []
	AP = sorted(ap, reverse=True)
	AN = sorted(an)
	if AP == ap and AN == an:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, r) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	(f, mn, mx) = (-1, -1, 1000000001)
	for i in range(n - 1):
		if mn < a[i] < mx:
			if a[i] > r:
				mx = a[i]
			elif a[i] < r:
				mn = a[i]
		else:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	(n, r) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a = 0
	k = 0
	for i in l:
		if i > r:
			if k == 0:
				k = i
			else:
				if i > k:
					print('NO')
					break
				k = i
		elif a == 0:
			a = i
		else:
			if i < a:
				print('NO')
				break
			a = i
	else:
		print('YES')


for t in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	x = 0
	y = max(a) + 1
	c = 'YES'
	for i in range(n - 1):
		if a[i] > r:
			if a[i] < y:
				y = a[i]
			else:
				c = 'NO'
				break
		elif a[i] > x:
			x = a[i]
		else:
			c = 'NO'
			break
	print(c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = 0
	mini = 0
	maxi = pow(10, 9) + 1
	for i in range(n - 1):
		if a[i] > mini and a[i] < maxi:
			m = 0
		else:
			print('NO')
			break
		if a[i] > k:
			maxi = a[i]
		elif a[i] < k:
			mini = a[i]
	else:
		print('YES')


for i in range(int(input())):
	(N, Reziba) = map(int, input().split())
	ratings = list(map(int, input().split()))
	ratings.pop()
	higher = []
	lower = []
	for x in ratings:
		if Reziba > x:
			lower.append(x)
		else:
			higher.append(x)
	if higher == sorted(higher, reverse=True) and lower == sorted(lower):
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	T -= 1
	(n, rez) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = 1
	r = 10 ** 9
	for i in a[:n - 1]:
		if i >= l and i < rez:
			l = i
		elif i <= r and i > rez:
			r = i
		else:
			print('NO')
			break
	else:
		print('YES')


for i in range(int(input())):
	(c, d) = map(int, input().split(' '))
	e = [int(i) for i in input().split()]
	final = 1
	(left, right) = (d, d)
	for j in range(c - 2, -1, -1):
		if int(e[j]) <= left:
			left = int(e[j])
		elif int(e[j]) >= right:
			right = int(e[j])
		else:
			final = 0
			break
	if final == 1:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, r) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	(left, right) = (r, r)
	ans = 0
	for i in range(n - 2, -1, -1):
		if a[i] <= left:
			left = a[i]
		elif a[i] >= right:
			right = a[i]
		else:
			ans = 1
			break
	if ans == 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(N, R) = map(int, input().split())
	A = list(map(int, input().split()))
	flag = True
	MIN = 0
	MAX = 1000000000
	STEP = False
	for j in range(0, N - 1):
		if A[j] > MAX or A[j] < MIN:
			flag = False
			break
		if j != 0 and (A[j] > A[j - 1]) != STEP:
			flag = False
			break
		STEP = R > A[j]
		if STEP:
			MIN = A[j]
		else:
			MAX = A[j]
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, R) = map(int, input().split())
	A = list(map(int, input().split()))
	minR = max(A) + 1
	minL = 0
	i = 0
	flag = 0
	while i < len(A) - 1:
		if A[i] > A[i + 1]:
			if minL > A[i + 1]:
				flag = -1
				break
			else:
				minR = A[i]
		elif A[i] < A[i + 1]:
			if minR < A[i + 1]:
				flag = -1
				break
			else:
				minL = A[i]
		i += 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(a, z) = map(int, input().split())
	lis = list(map(int, input().split()))
	a = []
	b = []
	for j in range(len(lis)):
		if lis[j] > z:
			a.append(lis[j])
		else:
			b.append(lis[j])
	c = sorted(a, reverse=True)
	d = sorted(b)
	if a != c or b != d:
		print('NO')
	else:
		print('YES')


tests = int(input())
for i in range(tests):
	(length, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	greater = 10 ** 9 + 1
	smaller = 0
	ans = 'YES'
	for j in arr:
		if j == r:
			greater = j
			smaller = j
		elif j > r:
			if j > greater:
				ans = 'NO'
				break
			greater = j
		elif j < r:
			if j < smaller:
				ans = 'NO'
				break
			smaller = j
	print(ans)


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	list1 = list(map(int, input().split()))
	mini = 0
	maxi = max(list1) + 1
	ans = ''
	for i in range(n):
		if list1[i] > r:
			if list1[i] < maxi:
				maxi = list1[i]
			else:
				ans = 'NO'
				break
		elif list1[i] > mini:
			mini = list1[i]
		else:
			ans = 'NO'
			break
	if ans == 'NO':
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	(N, Rez) = (l[0], l[1])
	l = [int(x) for x in input().split()]
	if l[-1] != Rez:
		print('NO')
		continue
	else:
		L = 0
		R = 10 ** 9 + 1
		for i in range(N - 1):
			if not L < l[i] < R:
				print('NO')
				break
			if l[i] > Rez:
				R = l[i]
			elif l[i] < Rez:
				L = l[i]
		else:
			print('YES')
			continue


t = int(input())
for j in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	up = 10 ** 9 + 1
	low = 0
	for i in range(0, n):
		if a[i] > up or a[i] < low:
			print('NO')
			break
		if a[i] < r:
			low = a[i]
		else:
			up = a[i]
	else:
		print('YES')


inp = int(input())
for i in range(inp):
	f = True
	l1 = [int(x) for x in input().split(' ')]
	l2 = [int(x) for x in input().split(' ')]
	high = None
	low = None
	for val in l2:
		if val > l1[1]:
			try:
				if val > high:
					f = False
				high = val
			except:
				high = val
		elif val < l1[1]:
			try:
				if val < low:
					f = False
				low = val
			except:
				low = val
	if f == True:
		print('YES')
	else:
		print('NO')


T = int(input())
LEFT = 1
RIGHT = 0
for i in range(T):
	(_, me) = [int(n) for n in input().split(' ')]
	ratings = input().split(' ')
	v = list()
	toPrint = 'YES'
	lastRight = 0
	lastLeft = 10000000000.0
	wentTo = -1
	for ratingstr in ratings:
		rating = int(ratingstr)
		if rating > me:
			if rating > lastLeft:
				toPrint = 'NO'
				break
			lastLeft = rating
		elif rating < me:
			if rating < lastRight:
				toPrint = 'NO'
				break
			lastRight = rating
	print(toPrint)


from sys import maxsize
T = int(input())
for x in range(T):
	(N, R) = list(map(int, input().split()))
	seq = list(map(int, input().split()))
	(l, h) = (0, 0)
	mistake = False
	if N < 3:
		print('YES')
		continue
	(l, m, h) = (0, seq[0], maxsize)
	for i in range(1, N):
		if seq[i] < m:
			h = m
			m = seq[i]
		else:
			l = m
			m = seq[i]
		if m < l or m > h:
			mistake = True
			break
	if mistake:
		print('NO')
	else:
		print('YES')


class BTree:

	def __init__(self, root, left=None, right=None):
		self.root = root
		self.left = left
		self.right = right

	def correct(self, N):
		for num in N:
			if num > self.root:
				if not self.updateRight(num):
					return False
			elif num < self.root:
				if not self.updateLeft(num):
					return False
		return True

	def updateLeft(self, num):
		if self.left:
			if num > self.left:
				self.left = num
				return True
		else:
			self.left = num
			return True
		return False

	def updateRight(self, num):
		if self.right:
			if num < self.right:
				self.right = num
				return True
		else:
			self.right = num
			return True
		return False
T = int(input())

def solve():
	R = int(input().split(' ')[1])
	N = [int(x) for x in input().split(' ')]
	tree = BTree(R)
	ans = tree.correct(N)
	if ans:
		print('YES')
	else:
		print('NO')
for _ in range(T):
	solve()


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	if l[0] < r:
		st = l[0]
		en = max(l) + 1
	if l[0] > r:
		en = l[0]
		st = 1
	for i in range(1, n):
		if l[i] in range(st, en):
			if l[i] > r:
				en = l[i]
			if l[i] < r:
				st = l[i]
		else:
			c += 1
	if c > 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if a[0] > m:
		st = 1
		ed = a[0]
	if a[0] < m:
		st = a[0]
		ed = max(a) + 1
	if len(a) == 1:
		print('YES')
	else:
		z = 0
		for i in range(1, n):
			if a[i] in range(st, ed):
				if a[i] > m:
					ed = a[i]
				if a[i] < m:
					st = a[i]
			else:
				z = 1
				print('NO')
				break
		if z == 0:
			print('YES')


t = int(input())
for _ in range(t):
	a = input().split()
	n = int(a[0])
	r = int(a[1])
	l = list(map(int, input().split()))
	if l[0] > r:
		st = 1
		en = l[0]
	if l[0] < r:
		st = l[0]
		en = max(l) + 1
	if len(l) == 1:
		print('YES')
	else:
		z = 0
		for i in range(1, n):
			if l[i] in range(st, en):
				if l[i] > r:
					en = l[i]
				if l[i] < r:
					st = l[i]
			else:
				z = 1
				print('NO')
				break
		if z == 0:
			print('YES')


for _ in range(int(input())):
	(n, r) = list(map(int, input().strip().split()))
	mlist = list(map(int, input().strip().split()))
	d = dict()
	d['l'] = 0
	d['r'] = float('inf')
	for i in range(len(mlist)):
		if r < mlist[i]:
			if mlist[i] < d['r']:
				d['r'] = mlist[i]
			else:
				print('NO')
				break
		elif mlist[i] > d['l']:
			d['l'] = mlist[i]
		else:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	hashmap = {}
	for i in range(n - 1):
		if lis[i] > k:
			if 'l' not in hashmap or hashmap['l'] > lis[i]:
				hashmap['l'] = lis[i]
			else:
				print('NO')
				break
		elif 'r' not in hashmap or hashmap['r'] < lis[i]:
			hashmap['r'] = lis[i]
		else:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	lst = list(map(int, input().split()))
	res = True
	(mx, mn) = (float('inf'), 0)
	prev = lst[0]
	for idx in range(1, n):
		cur = lst[idx]
		if cur < mn or cur > mx:
			res = False
			break
		if cur > prev:
			mn = prev
		elif cur < prev:
			mx = prev
		prev = cur
	print('YES') if res else print('NO')


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	l = [int(x) for x in input().split()]
	maxi = max(l)
	mini = min(l)
	s = 0
	for i in range(n - 1):
		if l[i] > maxi or l[i] < mini:
			s = 1
			break
		elif l[i] > l[i + 1]:
			maxi = l[i]
		elif l[i] < l[i + 1]:
			mini = l[i]
	if r <= maxi and r >= mini and (s == 0):
		print('YES')
	else:
		print('NO')


def solution():
	(n, target) = map(int, input().split(' '))
	arr = [0, *map(int, input().split(' '))]
	left = 0
	right = 0
	prev_dir = 1
	for i in range(1, n):
		target_dir = target - arr[i] > 0
		chef_dir = arr[i + 1] - arr[i] > 0
		if chef_dir != target_dir:
			return 'NO'
		if chef_dir == prev_dir:
			continue
		elif chef_dir:
			left = arr[i]
			right = arr[i - 1]
			if arr[i + 1] > right:
				return 'NO'
		else:
			right = arr[i]
			left = arr[i - 1]
			if arr[i + 1] < left:
				return 'NO'
		prev_dir = chef_dir
	return 'YES'
tests = int(input())
while tests:
	print(solution())
	tests -= 1


import sys
for _ in range(int(input().strip())):
	(N, R) = map(int, input().strip().split())
	pos = list(map(int, input().strip().split()))
	right = sys.maxsize
	left = -sys.maxsize
	ans = 'YES'
	for i in pos:
		if i < R:
			if i < left:
				ans = 'NO'
				break
			left = max(left, i)
		elif i > R:
			if i > right:
				ans = 'NO'
				break
			right = min(right, i)
		else:
			continue
	print(ans)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	if arr[0] < r:
		direct = 'r'
	else:
		direct = 'l'
	for i in range(1, n - 1):
		if arr[i] > arr[i - 1] and direct != 'r' or (arr[i] < arr[i - 1] and direct != 'l'):
			print('NO')
			break
		elif arr[i] < r:
			if direct == 'l':
				if arr[i - 1] > arr[i + 1] > arr[i]:
					pass
				else:
					print('NO')
					break
			direct = 'r'
		elif arr[i] > r:
			if direct == 'r':
				if arr[i - 1] < arr[i + 1] < arr[i]:
					pass
				else:
					print('NO')
					break
			direct = 'l'
	else:
		print('YES')


for _ in range(int(input())):
	(n, rating) = map(int, input().split())
	l = [int(i) for i in input().split()]
	flag = 1
	greater = []
	lower = []
	for i in range(n):
		if rating < l[i]:
			if len(greater) == 0:
				greater.append(l[i])
			elif greater[-1] > l[i]:
				greater.append(l[i])
		elif rating > l[i]:
			if len(lower) == 0:
				lower.append(l[i])
			elif lower[-1] < l[i]:
				lower.append(l[i])
	if len(greater) + len(lower) == n - 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	maxB = 1 * 10 ** 9
	minB = -1
	no = False
	for i in arr:
		if i > maxB or i < minB:
			no = True
			break
		if i > r:
			maxB = i
		elif i < r:
			minB = i
	if no == True:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	(n, rating) = map(int, input().split())
	flag = 1
	maxi = 0
	mini = 99999999999999
	array = [int(x) for x in input().split()]
	for index in range(len(array)):
		if array[index] > rating:
			mini = min(mini, array[index])
			if mini != array[index]:
				flag = 0
		elif array[index] < rating:
			maxi = max(maxi, array[index])
			if maxi != array[index]:
				flag = 0
		if index == len(array) - 1 and array[index] != rating:
			flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, r) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	c = 0
	(low, high) = (float('-inf'), float('inf'))
	for i in range(n):
		if l[i] == r:
			print('YES')
			break
		elif l[i] < low or l[i] > high:
			print('NO')
			break
		elif l[i] < r:
			low = l[i]
		else:
			high = l[i]


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	arr = list(map(int, input().lstrip().split()))
	upper = 10000000000
	lower = -upper
	for i in range(n):
		if arr[i] == r:
			print('YES')
			break
		elif arr[i] > upper or arr[i] < lower:
			print('NO')
			break
		elif arr[i] > r:
			upper = arr[i]
		elif arr[i] < r:
			lower = arr[i]


test_cases = int(input())
for _ in range(test_cases):
	(n, rat) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	lower = max(arr)
	upper = min(arr)
	res = True
	for i in range(1, n):
		if arr[i] > arr[i - 1]:
			upper = arr[i - 1]
			if arr[i] > lower:
				res = False
		elif arr[i] < arr[i - 1]:
			lower = arr[i - 1]
			if arr[i] < upper:
				res = False
				break
	if res:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, rezRating) = map(int, input().split())
	rating = list(map(int, input().split()))
	maxBound = 10000000000
	minBound = -maxBound
	for index in range(n):
		currRating = rating[index]
		if currRating == rezRating:
			print('YES')
			break
		elif currRating > maxBound or currRating < minBound:
			print('NO')
			break
		elif currRating > rezRating:
			maxBound = currRating
		elif currRating < rezRating:
			minBound = currRating


for _ in range(int(input())):
	(N, R) = map(int, input().split(' '))
	lis = list(map(int, input().split(' ')))
	lis1 = []
	lis2 = []
	for j in lis:
		if j > R:
			lis1.append(j)
		if j < R:
			lis2.append(j)
	a = lis1.copy()
	b = lis2.copy()
	a.sort()
	b.sort()
	if a == lis1[::-1] and b == lis2:
		print('YES')
	else:
		print('NO')


import numpy as np
for i in range(int(input())):
	(N, R) = map(int, input().split(' '))
	lis = list(map(int, input().split(' ')))
	lis1 = np.array(lis)
	a = np.where(lis1 > R)
	b = np.where(lis1 < R)
	lis2 = lis1[a]
	lis3 = lis1[b]
	a1 = np.argsort(lis2)
	b1 = np.argsort(lis3)
	a1 = list(lis2[a1])
	lis2 = list(lis2)
	b1 = list(lis3[b1])
	lis3 = list(lis3)
	if a1 == lis2[::-1] and b1 == lis3:
		print('YES')
	else:
		print('NO')


import sys
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	prev = sys.maxsize
	S = 0
	prev1 = 0
	for i in range(N):
		if A[i] > M:
			if A[i] < prev:
				prev = A[i]
			else:
				S = 1
				break
		elif A[i] > prev1:
			prev1 = A[i]
		else:
			S = 1
			break
	if S:
		print('NO')
	elif A[i] == M:
		print('YES')
	else:
		print('NO')


import math
for i in range(int(input())):
	p1 = [int(x) for x in input().split()]
	p2 = [int(x) for x in input().split()]
	right = math.inf
	left = -math.inf
	for j in range(p1[0]):
		if p2[j] > right or p2[j] < left:
			print('NO')
			break
		if p2[j] > p1[1]:
			right = p2[j]
		if p2[j] < p1[1]:
			left = p2[j]
	else:
		print('YES')


import math

def fun():
	(n, r) = map(int, input().split())
	arr = list(map(int, input().split()))
	high = math.inf
	low = -math.inf
	for i in range(n):
		if arr[i] > high or arr[i] < low:
			print('NO')
			return
		if arr[i] > r:
			high = arr[i]
		if arr[i] < r:
			low = arr[i]
	print('YES')
for _ in range(int(input())):
	fun()


import math
t = int(input())
for i in range(t):
	[n, r] = list(map(int, input().split()))
	a = list(map(int, input().split()))
	mn = 1
	mx = 10 ** 9
	for i in a:
		if i < mn or i > mx:
			print('NO')
			break
		if i < r:
			mn = i
		else:
			mx = i
	else:
		print('YES')


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	max_rating = max(a)
	min_rating = min(a)
	ans = True
	for y in a:
		if y > max_rating or y < min_rating:
			ans = False
		elif y < r:
			min_rating = y
		elif y > r:
			max_rating = y
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input(''))):
	(num, rez) = map(int, input().split())
	lst = list(map(int, input().split()))
	nmax = 10000000000
	nmin = -10000000000
	for l in lst:
		l = int(l)
		if l == rez:
			print('YES')
			break
		elif l > nmax or l < nmin:
			print('NO')
			break
		elif l > rez:
			nmax = l
		elif l < rez:
			nmin = l


def snek(x):
	r = float('inf')
	l = -float('inf')
	for i in range(1, len(x)):
		e = x[i]
		if l < e and e < r:
			if x[i] < x[i - 1]:
				r = x[i - 1]
			else:
				l = x[i - 1]
		else:
			return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	(n, r1) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	print(snek(x))


import sys
import math

def main(arr):
	r_bound = float('inf')
	l_bound = -float('inf')
	for i in range(1, len(arr)):
		e = arr[i]
		if l_bound < e and e < r_bound:
			if arr[i] < arr[i - 1]:
				r_bound = arr[i - 1]
			else:
				l_bound = arr[i - 1]
		else:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, R) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(main(arr))


T = int(input())
ans = []
for _ in range(T):
	(N, R) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	last_right = float('inf')
	last_left = -float('inf')
	valid = True
	for i in range(N - 1):
		if A[i + 1] > A[i]:
			if A[i + 1] > last_right:
				valid = False
				break
			last_left = A[i]
		elif A[i + 1] < A[i]:
			if A[i + 1] < last_left:
				valid = False
				break
			last_right = A[i]
	if valid:
		ans.append('YES')
	else:
		ans.append('NO')
for i in ans:
	print(i)


for i in range(int(input())):
	(n, r) = map(int, input().split())
	li = list(map(int, input().split()))
	ans = 'YES'
	least = None
	most = None
	for el in li:
		if el > r:
			if most == None or most > el:
				most = el
			else:
				ans = 'NO'
				break
		elif least == None or least < el:
			least = el
		else:
			ans = 'NO'
			break
	print(ans)


T = int(input())
for _ in range(T):
	(N, R) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	mini = 0
	maxi = 1000000001
	for i in A:
		if i == R:
			print('YES')
		elif i > mini and i < maxi:
			if i < R:
				mini = i
			else:
				maxi = i
		else:
			print('NO')
			break


for j in range(int(input())):
	(n, r) = map(int, input().split())
	x = list(map(int, input().split()))
	(y, z) = ([], [])
	for i in x:
		if i < r:
			y.append(i)
		else:
			z.append(i)
	am = sorted(y)
	bm = sorted(z, reverse=True)
	if am == y and bm == z:
		print('YES')
	else:
		print('NO')


def check_if_valid(arr, N, R):
	left_limit = 0
	right_limit = 100000000000
	for i in range(N - 1):
		if i == 0:
			if arr[i] > R:
				right_limit = arr[i]
			elif arr[i] < R:
				left_limit = arr[i]
		elif arr[i] > left_limit and arr[i] < right_limit:
			if arr[i] > R:
				right_limit = arr[i]
			elif arr[i] < R:
				left_limit = arr[i]
		else:
			return False
	return True
testcase = int(input())
for z in range(testcase):
	(N, R) = [int(d) for d in input().split()]
	arr = [int(d) for d in input().split()]
	if check_if_valid(arr, N, R):
		print('YES')
	else:
		print('NO')


try:
	for _ in range(int(input())):
		(N, R) = input().split()
		(N, R) = (int(N), int(R))
		A = [int(j) for j in input().split()]
		(l, r) = (0, max(A) + 1)
		for i in range(N):
			if A[i] > R and A[i] < r:
				r = A[i]
			elif A[i] < R and A[i] > l:
				l = A[i]
			elif A[i] == R:
				print('YES')
				break
			else:
				print('NO')
				break
except:
	pass


import sys
t = int(input())
while t != 0:
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	left = 0
	right = sys.maxsize
	flag = True
	for i in range(n):
		if a[i] > r:
			if a[i] <= right:
				right = a[i]
			else:
				flag = False
		elif a[i] < r:
			if a[i] >= left:
				left = a[i]
			else:
				flag = False
	if flag == False:
		print('NO')
	else:
		print('YES')
	t -= 1


T = int(input())
for p in range(0, T):
	inp = input().split(' ')
	n = int(inp[0])
	r = int(inp[1])
	arr = input().split(' ')
	maxd = 99999999999999
	mind = -99999999999999
	count = 0
	for i in range(0, n):
		arr[i] = int(arr[i])
		if arr[i] > maxd:
			print('NO')
			count += 1
			break
		if arr[i] < mind:
			print('NO')
			count += 1
			break
		if arr[i] > r:
			if maxd > arr[i]:
				maxd = arr[i]
		if arr[i] < r:
			if mind < arr[i]:
				mind = arr[i]
	if count == 0:
		print('YES')


import math
T = int(input())
for i in range(T):
	(n, rating) = [int(s) for s in input().split()]
	l = [int(s) for s in input().split()]
	start = -1 * math.inf
	end = math.inf
	pro = 0
	for j in l:
		if j > rating:
			if j > end:
				pro = 1
				break
			else:
				end = j
		elif j < rating:
			if j < start:
				pro = 1
				break
			else:
				start = j
	if pro == 1:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	d = []
	e = []
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	for i in c:
		if i < b[1]:
			d.append(i)
		elif i > b[1]:
			e.append(i)
	f = sorted(d)
	g = sorted(e, reverse=True)
	if d == f and e == g:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	(n, r) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	mn = 0
	mx = 1000000001
	for num in l:
		if num < r:
			if num < mn:
				print('NO')
				break
			else:
				mn = num
		elif num > r:
			if num > mx:
				print('NO')
				break
			else:
				mx = num
		else:
			print('YES')
			break
	t -= 1