Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.

The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.

Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move. 

Help Anton and write the program that for the given position determines whether the white king is in check.

Remainder, on how do chess pieces move:   Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.  Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.  Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap". 


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.

The second line contains two integers x_0 and y_0 ( - 10^9 ≤ x_0, y_0 ≤ 10^9) — coordinates of the white king.

Then follow n lines, each of them contains a character and two integers x_{i} and y_{i} ( - 10^9 ≤ x_{i}, y_{i} ≤ 10^9) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.


-----Output-----

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.


-----Examples-----
Input
2
4 2
R 1 1
B 1 5

Output
YES

Input
2
4 2
R 3 3
B 1 5

Output
NO



-----Note-----

Picture for the first sample:  [Image]  White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is "YES".

Picture for the second sample:  [Image]  Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is "NO".

Difficulty: MEDIUM_HARD

Solutions:
MAX_NUM = 10 ** 9
n = int(input())
(king_x, king_y) = map(int, input().split())
nomakers = {'Rook': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': []}, 'Bishop': {'left': [], 'right': [], 'up': [], 'down': []}}
yes = {'Queen': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': [], 'left': [], 'right': [], 'up': [], 'down': []}, 'Bishop': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': []}, 'Rook': {'left': [], 'right': [], 'up': [], 'down': []}}
for i in range(n):
	(figure, figure_x, figure_y) = input().split()
	(figure_x, figure_y) = (int(figure_x), int(figure_y))
	if figure == 'Q':
		if figure_x == king_x:
			if figure_y < king_y:
				half = 'down'
			else:
				half = 'up'
			yes['Queen'][half].append(abs(king_y - figure_y))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Queen'][half][-1]:
					del yes['Queen'][half][-1]
					break
		elif figure_y == king_y:
			if figure_x < king_x:
				half = 'left'
			else:
				half = 'right'
			yes['Queen'][half].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Queen'][half][-1]:
					del yes['Queen'][half][-1]
					break
		elif abs(figure_x - king_x) == abs(figure_y - king_y):
			if figure_x > king_x:
				if figure_y > king_y:
					quarter = 'right-up'
				else:
					quarter = 'right-down'
			elif figure_y > king_y:
				quarter = 'left-up'
			else:
				quarter = 'left-down'
			yes['Queen'][quarter].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Rook'][quarter])):
				if nomakers['Rook'][quarter][i] < yes['Queen'][quarter][-1]:
					del yes['Queen'][quarter][-1]
					break
	elif figure == 'R':
		if figure_x == king_x:
			if figure_y < king_y:
				half = 'down'
			else:
				half = 'up'
			yes['Rook'][half].append(abs(king_y - figure_y))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Rook'][half][-1]:
					del yes['Rook'][half][-1]
					break
		elif figure_y == king_y:
			if figure_x > king_x:
				half = 'right'
			else:
				half = 'left'
			yes['Rook'][half].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Rook'][half][-1]:
					del yes['Rook'][half][-1]
					break
		elif abs(figure_x - king_x) == abs(figure_y - king_y):
			if figure_x > king_x:
				if figure_y > king_y:
					quarter = 'right-up'
				else:
					quarter = 'right-down'
			elif figure_y > king_y:
				quarter = 'left-up'
			else:
				quarter = 'left-down'
			nomakers['Rook'][quarter].append(abs(figure_x - king_x))
			i = 0
			n = len(yes['Queen'][quarter])
			while i < n:
				element = yes['Queen'][quarter][i]
				if nomakers['Rook'][quarter][-1] < element:
					del yes['Queen'][quarter][i]
					n = n - 1
				else:
					i = i + 1
			i = 0
			n = len(yes['Bishop'][quarter])
			while i < n:
				element = yes['Bishop'][quarter][i]
				if nomakers['Rook'][quarter][-1] < element:
					del yes['Bishop'][quarter][i]
					n = n - 1
				else:
					i = i + 1
	elif abs(figure_x - king_x) == abs(figure_y - king_y):
		if figure_x > king_x:
			if figure_y > king_y:
				quarter = 'right-up'
			else:
				quarter = 'right-down'
		elif figure_y > king_y:
			quarter = 'left-up'
		else:
			quarter = 'left-down'
		yes['Bishop'][quarter].append(abs(figure_x - king_x))
		for i in range(len(nomakers['Rook'][quarter])):
			if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
				del yes['Bishop'][quarter][-1]
				break
	elif figure_x == king_x or figure_y == king_y:
		if figure_y < king_y:
			a = figure_y - king_y
			half = 'down'
		elif figure_y > king_y:
			half = 'up'
			a = figure_y - king_y
		elif figure_x > king_x:
			a = figure_x - king_x
			half = 'right'
		else:
			a = figure_x - king_x
			half = 'left'
		nomakers['Bishop'][half].append(abs(a))
		i = 0
		n = len(yes['Rook'][half])
		while i < n:
			element = yes['Rook'][half][i]
			if nomakers['Bishop'][half][-1] < element:
				del yes['Rook'][half][i]
				n = n - 1
			else:
				i = i + 1
		i = 0
		n = len(yes['Queen'][half])
		while i < n:
			element = yes['Queen'][half][i]
			if nomakers['Bishop'][half][-1] < element:
				del yes['Queen'][half][i]
				n = n - 1
			else:
				i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or (len(yes['Queen']['up']) > 0) or (len(yes['Queen']['left-up']) > 0) or (len(yes['Queen']['left-down']) > 0) or (len(yes['Queen']['right-up']) > 0) or (len(yes['Queen']['right-down']) > 0) or (len(yes['Bishop']['right-down']) > 0) or (len(yes['Bishop']['right-up']) > 0) or (len(yes['Bishop']['left-up']) > 0) or (len(yes['Bishop']['left-down']) > 0) or (len(yes['Rook']['left']) > 0) or (len(yes['Rook']['right']) > 0) or (len(yes['Rook']['up']) > 0) or (len(yes['Rook']['down']) > 0):
	print('YES')
else:
	print('NO')


from math import sqrt
from copy import copy

class figure:

	def __init__(self, ras=None, type=None):
		self.ras = copy(ras)
		self.type = type
n = int(input())
(x0, y0) = map(int, input().split())
sup = 'NO'
f = []
for i in range(8):
	d = figure(10 ** 11)
	f.append(d)
for i in range(n):
	(teg, x, y) = map(str, input().split())
	(x, y) = (int(x), int(y))
	if x == x0:
		if y < y0:
			ras = abs(y - y0)
			if ras < f[0].ras:
				f[0] = figure(ras, teg)
		if y > y0:
			ras = abs(y0 - y)
			if ras < f[1].ras:
				f[1] = figure(ras, teg)
	if y == y0:
		if x > x0:
			ras = abs(x - x0)
			if ras < f[2].ras:
				f[2] = figure(ras, teg)
		if x < x0:
			ras = abs(x0 - x)
			if ras < f[3].ras:
				f[3] = figure(ras, teg)
	if abs(x - x0) == abs(y - y0):
		if y < y0 and x < x0:
			ras = sqrt(2) * abs(x - x0)
			if ras < f[4].ras:
				f[4] = figure(ras, teg)
		if y < y0 and x > x0:
			ras = sqrt(2) * abs(x - x0)
			if ras < f[5].ras:
				f[5] = figure(ras, teg)
		if y > y0 and x > x0:
			ras = sqrt(2) * abs(x - x0)
			if ras < f[6].ras:
				f[6] = figure(ras, teg)
		if y > y0 and x < x0:
			ras = sqrt(2) * abs(x - x0)
			if ras < f[7].ras:
				f[7] = figure(ras, teg)
for i in range(8):
	if i in [0, 1, 2, 3]:
		if f[i].type == 'R' or f[i].type == 'Q':
			sup = 'YES'
	elif i in [4, 5, 6, 7]:
		if f[i].type == 'Q' or f[i].type == 'B':
			sup = 'YES'
print(sup)


INF = 1000000000000.0
mx = [-1, -1, 0, 1, 1, 1, 0, -1]
my = [0, 1, 1, 1, 0, -1, -1, -1]

def canSolve(x, y, j):
	if mx[j] == 0:
		return x == 0 and y // my[j] > 0
	elif my[j] == 0:
		return x // mx[j] > 0 and y == 0
	else:
		return y // my[j] == x // mx[j] and y // my[j] > 0

def main():
	global INF
	n = int(input())
	(x0, y0) = map(int, input().split())
	close = [(INF, 'a')] * 8
	for i in range(n):
		(piece, x, y) = input().split()
		x = int(x) - x0
		y = int(y) - y0
		for j in range(8):
			if canSolve(x, y, j):
				aux = abs(x * mx[j] + y * my[j])
				if aux < close[j][0]:
					close[j] = (aux, piece)
	can = False
	for i in range(8):
		if i % 2 == 0 and (close[i][1] == 'R' or close[i][1] == 'Q'):
			can = True
			break
		elif i % 2 != 0 and (close[i][1] == 'B' or close[i][1] == 'Q'):
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')
main()


def cf(c):
	if c > 0:
		return (0, c)
	else:
		return (1, -c)

def cd(v):
	d = [[] for c in range(8)]
	for c in v:
		for x in range(2):
			if c[x] == 0:
				(n, z) = cf(c[1 - x])
				d[2 * x + n].append((z, c[2]))
		for x in range(2):
			k = 2 * x - 1
			if c[x] == k * c[1 - x]:
				(n, z) = cf(c[x])
				d[4 + 2 * x + n].append((z, c[2]))
	for c in d:
		c.sort(key=lambda x: x[0])
	return d

def ic(v):
	f = (('R', 'Q'), ('B', 'Q'))
	d = cd(v)
	for (c, t) in enumerate(d):
		for x in t:
			if x[1] in f[c // 4]:
				return 1
			elif x[1] == f[1 - c // 4][0]:
				break
	return 0
n = int(input())
(kx, kz) = [int(c) for c in input().split()]
v = []
for c in range(n):
	t = input().split()
	(s, x, z) = (t[0], int(t[1]), int(t[2]))
	v.append((z - kz, x - kx, s))
s = 'NO'
if ic(v):
	s = 'YES'
print(s)


import sys
import math
files = False
if files:
	sys.stdin = open('slalom.in')
sz = int(input())
(x, y) = [int(i) for i in input().split()]
tow = [[1, 0], [-1, 0], [0, -1], [0, 1]]
bis = [[1, 1], [-1, 1], [1, -1], [-1, -1]]
towd = [[1, 0, 'N'], [-1, 0, 'N'], [0, -1, 'N'], [0, 1, 'N']]
bisd = [[1, 1, 'N'], [-1, 1, 'N'], [1, -1, 'N'], [-1, -1, 'N']]
for n1 in range(sz):
	(l, xt, yt) = [i for i in input().split()]
	xt = int(xt) - x
	yt = int(yt) - y
	if xt == 0 or yt == 0:
		for (n, i1) in enumerate(tow):
			if i1[0] == 0 and xt != 0:
				continue
			if i1[1] == 0 and yt != 0:
				continue
			if xt * i1[0] >= 0 and yt * i1[1] >= 0:
				if towd[n][2] == 'N':
					towd[n][0] = xt
					towd[n][1] = yt
					towd[n][2] = l
					continue
				if abs(towd[n][0]) + abs(towd[n][1]) > abs(xt) + abs(yt):
					towd[n][0] = xt
					towd[n][1] = yt
					towd[n][2] = l
					continue
		continue
	if abs(xt) != abs(yt):
		continue
	for (n, i1) in enumerate(bis):
		if xt * i1[0] >= 0 and yt * i1[1] >= 0:
			if bisd[n][2] == 'N':
				bisd[n][0] = xt
				bisd[n][1] = yt
				bisd[n][2] = l
				break
			if abs(bisd[n][0]) > abs(xt):
				bisd[n][0] = xt
				bisd[n][1] = yt
				bisd[n][2] = l
				break
hit = 'NO'
for (n1, i1) in enumerate(bisd):
	if i1[2] == 'B' or i1[2] == 'Q':
		hit = 'YES'
for (n1, i1) in enumerate(towd):
	if i1[2] == 'R' or i1[2] == 'Q':
		hit = 'YES'
print(hit)
sys.stdout.close()


n = int(input())
(x0, y0) = [int(i) for i in input().split()]
max_num = 2 * 10 ** 9 + 5
N = ['A', max_num]
S = ['A', max_num]
W = ['A', max_num]
E = ['A', max_num]
NE = ['A', max_num]
NW = ['A', max_num]
SW = ['A', max_num]
SE = ['A', max_num]
for i in range(n):
	(symbol, x, y) = input().split()
	x = int(x)
	y = int(y)
	if x == x0:
		if y > y0:
			dist = y - y0
			if dist < N[1]:
				N[0] = symbol
				N[1] = dist
		else:
			dist = y0 - y
			if dist < S[1]:
				S[0] = symbol
				S[1] = dist
	elif y == y0:
		if x > x0:
			dist = x - x0
			if dist < W[1]:
				W[0] = symbol
				W[1] = dist
		else:
			dist = x0 - x
			if dist < E[1]:
				E[0] = symbol
				E[1] = dist
	elif y - y0 == x - x0:
		if y > y0:
			dist = y - y0
			if dist < NE[1]:
				NE[0] = symbol
				NE[1] = dist
		else:
			dist = y0 - y
			if dist < SW[1]:
				SW[0] = symbol
				SW[1] = dist
	elif y - y0 == x0 - x:
		if y > y0:
			dist = y - y0
			if dist < SE[1]:
				SE[0] = symbol
				SE[1] = dist
		else:
			dist = y0 - y
			if dist < NW[1]:
				NW[0] = symbol
				NW[1] = dist
if N[0] in 'QR' or S[0] in 'QR' or E[0] in 'QR' or (W[0] in 'QR'):
	print('YES')
elif NE[0] in 'QB' or SE[0] in 'QB' or SW[0] in 'QB' or (NW[0] in 'QB'):
	print('YES')
else:
	print('NO')


def main():
	n = int(input())
	(x, y) = list(map(int, input().split()))
	a = []
	for i in range(n):
		a.append(input().split())
	for i in range(n):
		a[i][1] = int(a[i][1]) - x
		a[i][2] = int(a[i][2]) - y
	typneedbql = []
	typneedbqr = []
	typneedbqu = []
	typneedbqd = []
	typneedrlu = []
	typneedrru = []
	typneedrld = []
	typneedrrd = []
	for i in range(n):
		if a[i][1] * a[i][2] == 0 and a[i][1] < 0:
			typneedbql.append([abs(a[i][1] + a[i][2])] + a[i])
		elif a[i][1] * a[i][2] == 0 and a[i][1] > 0:
			typneedbqr.append([abs(a[i][1] + a[i][2])] + a[i])
		elif a[i][1] * a[i][2] == 0 and a[i][2] > 0:
			typneedbqu.append([abs(a[i][1] + a[i][2])] + a[i])
		elif a[i][1] * a[i][2] == 0 and a[i][2] < 0:
			typneedbqd.append([abs(a[i][1] + a[i][2])] + a[i])
		elif abs(a[i][1] / a[i][2]) == 1 and a[i][1] < 0 and (a[i][2] < 0):
			typneedrlu.append([abs(a[i][1])] + a[i])
		elif abs(a[i][1] / a[i][2]) == 1 and a[i][1] < 0 and (a[i][2] > 0):
			typneedrld.append([abs(a[i][1])] + a[i])
		elif abs(a[i][1] / a[i][2]) == 1 and a[i][1] > 0 and (a[i][2] > 0):
			typneedrrd.append([abs(a[i][1])] + a[i])
		elif abs(a[i][1] / a[i][2]) == 1 and a[i][1] > 0 and (a[i][2] < 0):
			typneedrru.append([abs(a[i][1])] + a[i])
	typneedbql.sort()
	typneedbqr.sort()
	typneedbqd.sort()
	typneedbqu.sort()
	typneedrlu.sort()
	typneedrru.sort()
	typneedrld.sort()
	typneedrrd.sort()
	for i in range(len(typneedbql)):
		if typneedbql[i][1] == 'R' or typneedbql[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedbqr)):
		if typneedbqr[i][1] == 'R' or typneedbqr[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedbqu)):
		if typneedbqu[i][1] == 'R' or typneedbqu[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedbqd)):
		if typneedbqd[i][1] == 'R' or typneedbqd[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedrlu)):
		if typneedrlu[i][1] == 'B' or typneedrlu[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedrld)):
		if typneedrld[i][1] == 'B' or typneedrld[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedrrd)):
		if typneedrrd[i][1] == 'B' or typneedrrd[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	for i in range(len(typneedrru)):
		if typneedrru[i][1] == 'B' or typneedrru[i][1] == 'Q':
			print('YES')
			return
		else:
			break
	print('NO')
main()


n = int(input())
(x, y) = map(int, input().split())
directions = [None for x in range(8)]
for i in range(n):
	line = input().split()
	xi = int(line[1])
	yi = int(line[2])
	if yi == y:
		if xi < x:
			if directions[6] == None:
				directions[6] = (xi, yi, line[0])
			elif directions[6][0] < xi:
				directions[6] = (xi, yi, line[0])
		elif directions[2] == None:
			directions[2] = (xi, yi, line[0])
		elif directions[2][0] > xi:
			directions[2] = (xi, yi, line[0])
	elif xi == x:
		if yi < y:
			if directions[4] == None:
				directions[4] = (xi, yi, line[0])
			elif directions[4][1] < yi:
				directions[4] = (xi, yi, line[0])
		elif directions[0] == None:
			directions[0] = (xi, yi, line[0])
		elif directions[0][1] > yi:
			directions[0] = (xi, yi, line[0])
	elif xi - x == yi - y:
		if xi > x:
			if directions[1] == None:
				directions[1] = (xi, yi, line[0])
			elif directions[1][0] > xi:
				directions[1] = (xi, yi, line[0])
		elif directions[5] == None:
			directions[5] = (xi, yi, line[0])
		elif directions[5][1] < yi:
			directions[5] = (xi, yi, line[0])
	elif xi - x == y - yi:
		if xi > x:
			if directions[3] == None:
				directions[3] = (xi, yi, line[0])
			elif directions[3][0] > xi:
				directions[3] = (xi, yi, line[0])
		elif directions[7] == None:
			directions[7] = (xi, yi, line[0])
		elif directions[7][1] > yi:
			directions[7] = (xi, yi, line[0])
for i in range(8):
	if directions[i] != None:
		if i % 2 == 0:
			if directions[i][2] == 'R' or directions[i][2] == 'Q':
				print('YES')
				exit()
		elif directions[i][2] == 'B' or directions[i][2] == 'Q':
			print('YES')
			exit()
print('NO')


import math, sys, re, itertools, pprint, collections, copy
(rs, ri, rai, raf) = (input, lambda : int(input()), lambda : list(map(int, input().split())), lambda : list(map(float, input().split())))
n = ri()
(x0, y0) = rai()
rays = [[[], lambda x, y: x == x0 and y > y0], [[], lambda x, y: x == x0 and y < y0], [[], lambda x, y: y == y0 and x > x0], [[], lambda x, y: y == y0 and x < x0], [[], lambda x, y: x - x0 == y - y0 and x > x0], [[], lambda x, y: x - x0 == y - y0 and x < x0], [[], lambda x, y: x - x0 == -(y - y0) and x > x0], [[], lambda x, y: x - x0 == -(y - y0) and x < x0]]
for i in range(n):
	t = input().split()
	(x, y) = (int(t[1]), int(t[2]))
	t = (t[0], x, y)
	for (k, v) in rays:
		if v(x, y):
			k.append(t)
dist = lambda a: abs(x0 - a[1]) + abs(y0 - a[2])
flag = False
for (i, (k, v)) in enumerate(rays):
	k.sort(key=dist)
	if len(k) > 0 and i > 3 and (k[0][0] in 'BQ'):
		flag = True
		break
	if len(k) > 0 and i <= 3 and (k[0][0] in 'RQ'):
		flag = True
		break
print('YES' if flag else 'NO')


n = int(input())
(xo, yo) = (int(x) for x in input().split())
inf = 1000000000000
above = [inf, 'N']
below = [inf, 'N']
left = [inf, 'N']
right = [inf, 'N']
upright = [inf, 'N']
upleft = [inf, 'N']
botright = [inf, 'N']
botleft = [inf, 'N']
for i in range(n):
	[T, curx, cury] = input().split()
	x = int(curx)
	y = int(cury)
	if x == xo:
		if y > yo and y - yo < above[0]:
			above[0] = y - yo
			above[1] = T
		elif y < yo and yo - y < below[0]:
			below[0] = yo - y
			below[1] = T
	elif y == yo:
		if x > xo and x - xo < right[0]:
			right[0] = x - xo
			right[1] = T
		elif x < xo and xo - x < left[0]:
			left[0] = xo - x
			left[1] = T
	if x - xo == y - yo:
		if x > xo and x - xo < upright[0]:
			upright[0] = x - xo
			upright[1] = T
		elif x < xo and xo - x < botleft[0]:
			botleft[0] = xo - x
			botleft[1] = T
	elif x - xo == yo - y:
		if x > xo and x - xo < botright[0]:
			botright[0] = x - xo
			botright[1] = T
		elif x < xo and xo - x < upleft[0]:
			upleft[0] = xo - x
			upleft[1] = T
if botright[1] == 'B' or botright[1] == 'Q' or botleft[1] == 'B' or (botleft[1] == 'Q') or (upleft[1] == 'B') or (upleft[1] == 'Q') or (upright[1] == 'B') or (upright[1] == 'Q') or (above[1] == 'R') or (above[1] == 'Q') or (below[1] == 'R') or (below[1] == 'Q') or (left[1] == 'R') or (left[1] == 'Q') or (right[1] == 'R') or (right[1] == 'Q'):
	print('YES')
else:
	print('NO')


BORDER = 10 ** 10

def get_type(x, y):
	if x == 0:
		return 1 if y > 0 else 5
	if y == 0:
		return 3 if x > 0 else 7
	if x == -y:
		return 0 if y > 0 else 4
	if x == y:
		return 2 if y > 0 else 6
	return -1

def __starting_point():
	(n,) = list(map(int, input().split()))
	(x0, y0) = list(map(int, input().split()))
	check = False
	block = [(-BORDER, BORDER), (0, BORDER), (BORDER, BORDER), (BORDER, 0), (BORDER, -BORDER), (0, -BORDER), (-BORDER, -BORDER), (-BORDER, 0)]
	killer = [None for _ in range(8)]
	for _ in range(n):
		(f, xs, ys) = input().split()
		(x, y) = list(map(int, (xs, ys)))
		(x, y) = (x - x0, y - y0)
		tp = get_type(x, y)
		if tp < 0:
			continue
		if f == 'B' and tp % 2 == 1 or (f == 'R' and tp % 2 == 0):
			if abs(block[tp][0]) + abs(block[tp][1]) > abs(x) + abs(y):
				block[tp] = (x, y)
		else:
			if abs(block[tp][0]) + abs(block[tp][1]) < abs(x) + abs(y):
				continue
			if killer[tp] is None:
				killer[tp] = (x, y)
				continue
			if abs(killer[tp][0]) + abs(killer[tp][1]) > abs(x) + abs(y):
				killer[tp] = (x, y)
				continue
	for tp in range(8):
		if killer[tp] is None:
			continue
		if abs(killer[tp][0]) + abs(killer[tp][1]) < abs(block[tp][0]) + abs(block[tp][1]):
			check = True
			break
	if check:
		print('YES')
	else:
		print('NO')
__starting_point()


def check(type, offset, win_way, dif_type):
	if offset == 1:
		if type != dif_type:
			print('YES')
			exit()
		elif win_way == 1:
			print('NO')
			exit()
		else:
			win_way -= 1
	return ([type, offset], win_way)
n = int(input())
(x_0, y_0) = map(int, input().split())
inf = float('inf')
north = [None, inf]
east = [None, inf]
south = [None, inf]
west = [None, inf]
northeast = [None, inf]
southeast = [None, inf]
southwest = [None, inf]
northwest = [None, inf]
win_way = 8
for i in range(n):
	piece = input().split()
	type = piece[0]
	(x, y) = map(int, piece[1:])
	if x == x_0:
		if y < y_0:
			offset = y_0 - y
			if offset < west[1]:
				(west, win_way) = check(type, offset, win_way, 'B')
		else:
			offset = y - y_0
			if offset < east[1]:
				(east, win_way) = check(type, offset, win_way, 'B')
	elif y == y_0:
		if x < x_0:
			offset = x_0 - x
			if offset < north[1]:
				(north, win_way) = check(type, offset, win_way, 'B')
		else:
			offset = x - x_0
			if offset < south[1]:
				(south, win_way) = check(type, offset, win_way, 'B')
	elif abs((x_0 - x) / (y_0 - y)) == 1:
		if x < x_0:
			if y < y_0:
				offset = y_0 - y
				if offset < northwest[1]:
					(northwest, win_way) = check(type, offset, win_way, 'R')
			else:
				offset = y - y_0
				if offset < northeast[1]:
					(northeast, win_way) = check(type, offset, win_way, 'R')
		elif y < y_0:
			offset = y_0 - y
			if offset < southwest[1]:
				(southwest, win_way) = check(type, offset, win_way, 'R')
		else:
			offset = y - y_0
			if offset < southeast[1]:
				(southeast, win_way) = check(type, offset, win_way, 'R')
if north[0] == 'R' or north[0] == 'Q' or east[0] == 'R' or (east[0] == 'Q') or (south[0] == 'R') or (south[0] == 'Q') or (west[0] == 'R') or (west[0] == 'Q') or (northeast[0] == 'B') or (northeast[0] == 'Q') or (southeast[0] == 'B') or (southeast[0] == 'Q') or (southwest[0] == 'B') or (southwest[0] == 'Q') or (northwest[0] == 'B') or (northwest[0] == 'Q'):
	print('YES')
else:
	print('NO')


n = int(input())
(x, y) = [int(i) for i in input().split()]
MIN_B = -10 ** 9 - 1
MAX_B = 10 ** 9 + 1
l_v = [MIN_B, 0]
u_v = [MAX_B, 0]
l_h = [MIN_B, 0]
u_h = [MAX_B, 0]
l_v1 = [MIN_B, MIN_B, 0]
u_v1 = [MAX_B, MAX_B, 0]
l_v2 = [MIN_B, MAX_B, 0]
u_v2 = [MAX_B, MIN_B, 0]
chess = []

def ok(type1, x1, y1, x, y):
	if type(type1) is int:
		return False
	if type1 == 'R':
		return x1 == x or y1 == y
	elif type1 == 'B':
		return -x1 + y1 == y - x or x1 + y1 == x + y
	elif type1 == 'Q':
		return x1 == x or y1 == y or -x1 + y1 == y - x or (x1 + y1 == x + y)
for i in range(n):
	(t1, t2, t3) = [i for i in input().split()]
	chess.append((t1, int(t2), int(t3)))
for i in chess:
	if i[1] == x:
		if i[2] > y and i[2] < u_v[0]:
			u_v = [i[2], i[0]]
		if i[2] < y and i[2] > l_v[0]:
			l_v = [i[2], i[0]]
	if i[2] == y:
		if i[1] > x and i[1] < u_h[0]:
			u_h = [i[1], i[0]]
		if i[1] < x and i[1] > l_h[0]:
			l_h = [i[1], i[0]]
	if -i[1] + i[2] == y - x:
		if (i[1] > x and i[2] > y) and (i[1] < u_v1[0] and i[2] < u_v1[1]):
			u_v1 = [i[1], i[2], i[0]]
		if (i[1] < x and i[2] < y) and (i[1] > l_v1[0] and i[2] > l_v1[1]):
			l_v1 = [i[1], i[2], i[0]]
	if i[1] + i[2] == x + y:
		if (i[1] > x and i[2] < y) and (i[1] < u_v2[0] and i[2] > u_v2[1]):
			u_v2 = [i[1], i[2], i[0]]
		if (i[1] < x and i[2] > y) and (i[1] > l_v2[0] and i[2] < l_v2[1]):
			l_v2 = [i[1], i[2], i[0]]
c = False
c = c or ok(l_v[1], x, l_v[0], x, y)
c = c or ok(u_v[1], x, u_v[0], x, y)
c = c or ok(l_h[1], l_h[0], y, x, y)
c = c or ok(u_h[1], u_h[0], y, x, y)
c = c or ok(l_v1[2], l_v1[0], l_v1[1], x, y)
c = c or ok(u_v1[2], u_v1[0], u_v1[1], x, y)
c = c or ok(l_v2[2], l_v2[0], l_v2[1], x, y)
c = c or ok(u_v2[2], u_v2[0], u_v2[1], x, y)
if c:
	print('YES')
else:
	print('NO')


from collections import defaultdict
import bisect
n = int(input())
(x0, y0) = list(map(int, input().split(' ')))
verticale = []
horizontale = []
diagonale1 = []
diagonale2 = []
for _ in range(n):
	(t, x, y) = input().split(' ')
	(x, y) = (int(x), int(y))
	if x == x0:
		verticale.append((y, t))
	if y == y0:
		horizontale.append((x, t))
	if x + y == x0 + y0:
		diagonale1.append((x, t))
	if x - y == x0 - y0:
		diagonale2.append((x, t))
dead = False
v = sorted(verticale)
if v:
	l = bisect.bisect(v, (y0, 'K'))
	if 0 < l < len(v):
		if v[l][1] in {'Q', 'R'} or v[l - 1][1] in {'Q', 'R'}:
			dead = True
	elif l == 0:
		if v[0][1] in {'Q', 'R'}:
			dead = True
	elif v[len(v) - 1][1] in {'Q', 'R'}:
		dead = True
v = sorted(horizontale)
if v:
	l = bisect.bisect(v, (x0, 'K'))
	if 0 < l < len(v):
		if v[l][1] in {'Q', 'R'} or v[l - 1][1] in {'Q', 'R'}:
			dead = True
	elif l == 0:
		if v[0][1] in {'Q', 'R'}:
			dead = True
	elif v[len(v) - 1][1] in {'Q', 'R'}:
		dead = True
v = sorted(diagonale1)
if v:
	l = bisect.bisect(v, (x0, 'K'))
	if 0 < l < len(v):
		if v[l][1] in {'Q', 'B'} or v[l - 1][1] in {'Q', 'B'}:
			dead = True
	elif l == 0:
		if v[0][1] in {'Q', 'B'}:
			dead = True
	elif v[len(v) - 1][1] in {'Q', 'B'}:
		dead = True
v = sorted(diagonale2)
if v:
	l = bisect.bisect(v, (x0, 'K'))
	if 0 < l < len(v):
		if v[l][1] in {'Q', 'B'} or v[l - 1][1] in {'Q', 'B'}:
			dead = True
	elif l == 0:
		if v[0][1] in {'Q', 'B'}:
			dead = True
	elif v[len(v) - 1][1] in {'Q', 'B'}:
		dead = True
if dead:
	print('YES')
else:
	print('NO')


def main():
	n = int(input())
	inf = 10 ** 10
	(x0, y0) = map(int, input().split())
	(h, v, d1, d2) = ([(-inf, 'K'), (0, 'K'), (inf, 'K')] for _ in range(4))
	for _ in range(n):
		(f, x, y) = input().split()
		x = int(x) - x0
		y = int(y) - y0
		if not x:
			h.append((y, f))
		elif not y:
			v.append((x, f))
		elif x == y:
			d1.append((x, f))
		elif x == -y:
			d1.append((x, f))
	res = False
	for l in (h, v, d1, d2):
		l.sort()
	i = h.index((0, 'K'))
	if h[i - 1][1] in 'RQ':
		res = True
	if h[i + 1][1] in 'RQ':
		res = True
	i = v.index((0, 'K'))
	if v[i - 1][1] in 'RQ':
		res = True
	if v[i + 1][1] in 'RQ':
		res = True
	i = d1.index((0, 'K'))
	if d1[i - 1][1] in 'BQ':
		res = True
	if d1[i + 1][1] in 'BQ':
		res = True
	i = d2.index((0, 'K'))
	if d2[i - 1][1] in 'BQ':
		res = True
	if d2[i + 1][1] in 'BQ':
		res = True
	print(('NO', 'YES')[res])
main()


def main():
	n = int(input())
	(kx, ky) = (int(x) for x in input().split())
	pieces = [None] * n
	for i in range(n):
		(piece, x, y) = (t for t in input().split())
		pieces[i] = (piece, int(x), int(y))
	print(solver2(kx, ky, pieces))

def isDiagonal(kx, ky, px, py):
	return abs(px - kx) == abs(py - ky)

def isSameRoworCol(kx, ky, px, py):
	return kx == px or ky == py

def dist(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def solver2(kx, ky, pieces):
	tl = None
	t = None
	tr = None
	l = None
	r = None
	bl = None
	b = None
	br = None
	for (piece, x, y) in pieces:
		if x == kx:
			if y > ky and (t == None or dist(kx, ky, x, y) < dist(kx, ky, t[1], t[2])):
				t = (piece, x, y)
			elif y < ky and (b == None or dist(kx, ky, x, y) < dist(kx, ky, b[1], b[2])):
				b = (piece, x, y)
		elif y == ky:
			if x > kx and (r == None or dist(kx, ky, x, y) < dist(kx, ky, r[1], r[2])):
				r = (piece, x, y)
			elif x < kx and (l == None or dist(kx, ky, x, y) < dist(kx, ky, l[1], l[2])):
				l = (piece, x, y)
		elif isDiagonal(kx, ky, x, y):
			if x - kx > 0:
				if y - ky > 0:
					if tr == None or dist(kx, ky, x, y) < dist(kx, ky, tr[1], tr[2]):
						tr = (piece, x, y)
				elif y - ky < 0:
					if br == None or dist(kx, ky, x, y) < dist(kx, ky, br[1], br[2]):
						br = (piece, x, y)
			if x - kx < 0:
				if y - ky > 0:
					if tl == None or dist(kx, ky, x, y) < dist(kx, ky, tl[1], tl[2]):
						tl = (piece, x, y)
				elif y - ky < 0:
					if bl == None or dist(kx, ky, x, y) < dist(kx, ky, bl[1], bl[2]):
						bl = (piece, x, y)
	for val in [t, l, r, b, tl, tr, bl, br]:
		if val == None:
			continue
		(piece, x, y) = val
		if piece == 'R' and isSameRoworCol(kx, ky, x, y):
			return 'YES'
		elif piece == 'B' and isDiagonal(kx, ky, x, y):
			return 'YES'
		elif piece == 'Q' and (isSameRoworCol(kx, ky, x, y) or isDiagonal(kx, ky, x, y)):
			return 'YES'
	return 'NO'
main()


def in_ls(name_type, string):
	string = string.split()
	string = map(name_type, string)
	string = list(string)
	return string
n = int(input())
king = in_ls(int, input())
cord = {}
for i in range(0, n):
	in_str = input().split()
	x = int(in_str[1])
	y = int(in_str[2])
	cord[x, y] = in_str[0]
nearest = []
for i in range(0, 8):
	nearest.append((1000000000000000000, 0))
for el in cord.keys():
	res = (el[0] - king[0], el[1] - king[1])
	if res[0] == 0:
		if res[1] > 0:
			if abs(res[1]) < nearest[0][0]:
				nearest[0] = (abs(res[1]), el)
		elif abs(res[1]) < nearest[4][0]:
			nearest[4] = (abs(res[1]), el)
	if res[1] == 0:
		if res[0] > 0:
			if abs(res[0]) < nearest[6][0]:
				nearest[6] = (abs(res[0]), el)
		elif abs(res[0]) < nearest[2][0]:
			nearest[2] = (abs(res[0]), el)
	if abs(res[0]) == abs(res[1]):
		if res[0] > 0 and res[1] > 0:
			if abs(res[0]) < nearest[7][0]:
				nearest[7] = (abs(res[0]), el)
		if res[0] < 0 and res[1] > 0:
			if abs(res[0]) < nearest[1][0]:
				nearest[1] = (abs(res[0]), el)
		if res[0] < 0 and res[1] < 0:
			if abs(res[0]) < nearest[3][0]:
				nearest[3] = (abs(res[0]), el)
		if res[0] > 0 and res[1] < 0:
			if abs(res[0]) < nearest[5][0]:
				nearest[5] = (abs(res[0]), el)
check = False
for i in range(8):
	if nearest[i][1] != 0:
		if i in [1, 3, 5, 7]:
			if cord[nearest[i][1]] == 'Q' or cord[nearest[i][1]] == 'B':
				check = True
		elif cord[nearest[i][1]] == 'R' or cord[nearest[i][1]] == 'Q':
			check = True
if check:
	print('YES')
else:
	print('NO')


from collections import defaultdict
from math import inf

def dist(x, y, a1, b1, a2, b2):
	first = (x - a1) ** 2 + (y - b1) ** 2
	second = (x - a2) ** 2 + (y - b2) ** 2
	if first <= second:
		return True
	return False

def find(a, b, x, y):
	if a == x:
		if b > y:
			return 'N'
		else:
			return 'S'
	elif b == y:
		if a > x:
			return 'E'
		else:
			return 'W'
	elif abs(a - x) == abs(b - y):
		if a > x:
			if b > y:
				return 'NE'
			else:
				return 'SE'
		elif b > y:
			return 'NW'
		else:
			return 'SW'
	else:
		return 'BHAK'
n = int(input())
(x, y) = map(int, input().split())
check = dict({'N': [inf, inf], 'S': [inf, inf], 'E': [inf, inf], 'W': [inf, inf], 'NE': [inf, inf], 'SE': [inf, inf], 'NW': [inf, inf], 'SW': [inf, inf]})
block = dict({'N': [inf, inf], 'S': [inf, inf], 'E': [inf, inf], 'W': [inf, inf], 'NE': [inf, inf], 'SE': [inf, inf], 'NW': [inf, inf], 'SW': [inf, inf]})
simple = set(['N', 'W', 'S', 'E'])
for i in range(n):
	(type, a, b) = map(str, input().split())
	a = int(a)
	b = int(b)
	direction = find(a, b, x, y)
	if direction == 'BHAK':
		continue
	elif type == 'R':
		if direction in simple:
			if check[direction] != [inf, inf]:
				if dist(x, y, a, b, check[direction][0], check[direction][1]):
					check[direction] = [a, b]
			else:
				check[direction] = [a, b]
		elif block[direction] != [inf, inf]:
			if dist(x, y, a, b, block[direction][0], block[direction][1]):
				block[direction] = [a, b]
		else:
			block[direction] = [a, b]
	elif type == 'B':
		if direction in simple:
			if block[direction] != [inf, inf]:
				if dist(x, y, a, b, block[direction][0], block[direction][1]):
					block[direction] = [a, b]
			else:
				block[direction] = [a, b]
		elif check[direction] != [inf, inf]:
			if dist(x, y, a, b, check[direction][0], check[direction][1]):
				check[direction] = [a, b]
		else:
			check[direction] = [a, b]
	elif check[direction] != [inf, inf]:
		if dist(x, y, a, b, check[direction][0], check[direction][1]):
			check[direction] = [a, b]
	else:
		check[direction] = [a, b]
ok = False
for key in check.keys():
	if check[key] != [inf, inf]:
		if block[key] == [inf, inf]:
			ok = True
		elif dist(x, y, check[key][0], check[key][1], block[key][0], block[key][1]):
			ok = True
if ok:
	print('YES')
else:
	print('NO')


MAX_NUM = 10 ** 9
MIN_NUM = -10 ** 9
from sys import stdin, stdout
n = int(stdin.readline().rstrip())
(king_x, king_y) = map(int, stdin.readline().rstrip().split())
nomakers = {'Rook': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': []}, 'Bishop': {'left': [], 'right': [], 'up': [], 'down': []}}
yes = {'Queen': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': [], 'left': [], 'right': [], 'up': [], 'down': []}, 'Bishop': {'right-down': [], 'right-up': [], 'left-down': [], 'left-up': []}, 'Rook': {'left': [], 'right': [], 'up': [], 'down': []}}
for i in range(n):
	(figure, figure_x, figure_y) = stdin.readline().rstrip().split()
	(figure_x, figure_y) = (int(figure_x), int(figure_y))
	if figure == 'Q':
		if figure_x == king_x:
			if figure_y < king_y:
				half = 'down'
			else:
				half = 'up'
			yes['Queen'][half].append(abs(king_y - figure_y))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Queen'][half][-1]:
					del yes['Queen'][half][-1]
					break
		elif figure_y == king_y:
			if figure_x < king_x:
				half = 'left'
			else:
				half = 'right'
			yes['Queen'][half].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Queen'][half][-1]:
					del yes['Queen'][half][-1]
					break
		elif abs(figure_x - king_x) == abs(figure_y - king_y):
			if figure_x > king_x:
				if figure_y > king_y:
					quarter = 'right-up'
				else:
					quarter = 'right-down'
			elif figure_y > king_y:
				quarter = 'left-up'
			else:
				quarter = 'left-down'
			yes['Queen'][quarter].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Rook'][quarter])):
				if nomakers['Rook'][quarter][i] < yes['Queen'][quarter][-1]:
					del yes['Queen'][quarter][-1]
					break
	elif figure == 'R':
		if figure_x == king_x:
			if figure_y < king_y:
				half = 'down'
			else:
				half = 'up'
			yes['Rook'][half].append(abs(king_y - figure_y))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Rook'][half][-1]:
					del yes['Rook'][half][-1]
					break
		elif figure_y == king_y:
			if figure_x > king_x:
				half = 'right'
			else:
				half = 'left'
			yes['Rook'][half].append(abs(king_x - figure_x))
			for i in range(len(nomakers['Bishop'][half])):
				if nomakers['Bishop'][half][i] < yes['Rook'][half][-1]:
					del yes['Rook'][half][-1]
					break
		elif abs(figure_x - king_x) == abs(figure_y - king_y):
			if figure_x > king_x:
				if figure_y > king_y:
					quarter = 'right-up'
				else:
					quarter = 'right-down'
			elif figure_y > king_y:
				quarter = 'left-up'
			else:
				quarter = 'left-down'
			nomakers['Rook'][quarter].append(abs(figure_x - king_x))
			i = 0
			n = len(yes['Queen'][quarter])
			while i < n:
				element = yes['Queen'][quarter][i]
				if nomakers['Rook'][quarter][-1] < element:
					del yes['Queen'][quarter][i]
					n = n - 1
				else:
					i = i + 1
			i = 0
			n = len(yes['Bishop'][quarter])
			while i < n:
				element = yes['Bishop'][quarter][i]
				if nomakers['Rook'][quarter][-1] < element:
					del yes['Bishop'][quarter][i]
					n = n - 1
				else:
					i = i + 1
	elif abs(figure_x - king_x) == abs(figure_y - king_y):
		if figure_x > king_x:
			if figure_y > king_y:
				quarter = 'right-up'
			else:
				quarter = 'right-down'
		elif figure_y > king_y:
			quarter = 'left-up'
		else:
			quarter = 'left-down'
		yes['Bishop'][quarter].append(abs(figure_x - king_x))
		for i in range(len(nomakers['Rook'][quarter])):
			if nomakers['Rook'][quarter][i] < yes['Bishop'][quarter][-1]:
				del yes['Bishop'][quarter][-1]
				break
	elif figure_x == king_x or figure_y == king_y:
		if figure_y < king_y:
			a = figure_y - king_y
			half = 'down'
		elif figure_y > king_y:
			half = 'up'
			a = figure_y - king_y
		elif figure_x > king_x:
			a = figure_x - king_x
			half = 'right'
		else:
			a = figure_x - king_x
			half = 'left'
		nomakers['Bishop'][half].append(abs(a))
		i = 0
		n = len(yes['Rook'][half])
		while i < n:
			element = yes['Rook'][half][i]
			if nomakers['Bishop'][half][-1] < element:
				del yes['Rook'][half][i]
				n = n - 1
			else:
				i = i + 1
		i = 0
		n = len(yes['Queen'][half])
		while i < n:
			element = yes['Queen'][half][i]
			if nomakers['Bishop'][half][-1] < element:
				del yes['Queen'][half][i]
				n = n - 1
			else:
				i = i + 1
if len(yes['Queen']['left']) > 0 or len(yes['Queen']['right']) > 0 or len(yes['Queen']['down']) > 0 or (len(yes['Queen']['up']) > 0) or (len(yes['Queen']['left-up']) > 0) or (len(yes['Queen']['left-down']) > 0) or (len(yes['Queen']['right-up']) > 0) or (len(yes['Queen']['right-down']) > 0) or (len(yes['Bishop']['right-down']) > 0) or (len(yes['Bishop']['right-up']) > 0) or (len(yes['Bishop']['left-up']) > 0) or (len(yes['Bishop']['left-down']) > 0) or (len(yes['Rook']['left']) > 0) or (len(yes['Rook']['right']) > 0) or (len(yes['Rook']['up']) > 0) or (len(yes['Rook']['down']) > 0):
	stdout.write('YES')
else:
	stdout.write('NO')


from math import *
black_pieces = int(input())
black_pieces_list = []
king_pos = input().split()
(king_pos[0], king_pos[1]) = (int(king_pos[1]), int(king_pos[0]))
(xp, xn, yp, yn) = (-1, -1, -1, -1)
(xpyp, xnyp, xpyn, xnyn) = (-1, -1, -1, -1)
(xp_dis, xn_dis, yp_dis, yn_dis) = (0, 0, 0, 0)
(xpyp_dis, xnyp_dis, xpyn_dis, xnyn_dis) = (0, 0, 0, 0)

def distance(x, y):
	dis = x ** 2 + y ** 2
	return dis
i = 0
while i < black_pieces:
	piece = input().split()
	black_pieces_list.append(piece)
	(x, y) = (int(piece[2]), int(piece[1]))
	x -= king_pos[0]
	y -= king_pos[1]
	dis = distance(x, y)
	if y == 0 and x > 0:
		if xp == -1:
			xp_dis = dis
			xp = i
		elif xp != -1 and dis < xp_dis:
			xp_dis = dis
			xp = i
	elif y == 0 and x < 0:
		if xn == -1:
			xn_dis = dis
			xn = i
		elif xn != -1 and dis < xn_dis:
			xn_dis = dis
			xn = i
	elif y < 0 and x == 0:
		if yp == -1:
			yp_dis = dis
			yp = i
		elif yp != -1 and dis < yp_dis:
			yp_dis = dis
			yp = i
	elif y > 0 and x == 0:
		if yn == -1:
			yn_dis = dis
			yn = i
		elif yn != -1 and dis < yn_dis:
			yn_dis = dis
			yn = i
	elif abs(y / x) == 1 and x > 0 and (y < 0):
		if xpyp == -1:
			xpyp_dis = dis
			xpyp = i
		elif xpyp != -1 and dis < xpyp_dis:
			xpyp_dis = dis
			xpyp = i
	elif abs(y / x) == 1 and x < 0 and (y < 0):
		if xnyp == -1:
			xnyp_dis = dis
			xnyp = i
		elif xnyp != -1 and dis < xnyp_dis:
			xnyp_dis = dis
			xnyp = i
	elif abs(y / x) == 1 and x > 0 and (y > 0):
		if xpyn == -1:
			xpyn_dis = dis
			xpyn = i
		elif xpyn != -1 and dis < xpyn_dis:
			xpyn_dis = dis
			xpyn = i
	elif abs(y / x) == 1 and x < 0 and (y > 0):
		if xnyn == -1:
			xnyn_dis = dis
			xnyn = i
		elif xnyn != -1 and dis < xnyn_dis:
			xnyn_dis = dis
			xnyn = i
	i += 1
king_in_check = 0
if xp != -1 and (black_pieces_list[xp][0] == 'R' or black_pieces_list[xp][0] == 'Q'):
	king_in_check += 1
elif xn != -1 and (black_pieces_list[xn][0] == 'R' or black_pieces_list[xn][0] == 'Q'):
	king_in_check += 1
elif yp != -1 and (black_pieces_list[yp][0] == 'R' or black_pieces_list[yp][0] == 'Q'):
	king_in_check += 1
elif yn != -1 and (black_pieces_list[yn][0] == 'R' or black_pieces_list[yn][0] == 'Q'):
	king_in_check += 1
elif xpyp != -1 and (black_pieces_list[xpyp][0] == 'Q' or black_pieces_list[xpyp][0] == 'B'):
	king_in_check += 1
elif xpyn != -1 and (black_pieces_list[xpyn][0] == 'Q' or black_pieces_list[xpyn][0] == 'B'):
	king_in_check += 1
elif xnyp != -1 and (black_pieces_list[xnyp][0] == 'Q' or black_pieces_list[xnyp][0] == 'B'):
	king_in_check += 1
elif xnyn != -1 and (black_pieces_list[xnyn][0] == 'Q' or black_pieces_list[xnyn][0] == 'B'):
	king_in_check += 1
if king_in_check > 0:
	print('YES')
else:
	print('NO')


def dist(cur, king):
	distance = abs(cur[0] - king[0]) ** 2 + abs(cur[1] - king[1]) ** 2
	direction = ''
	if cur[0] > king[0]:
		direction += 'l'
	elif cur[0] < king[0]:
		direction += 'r'
	if cur[1] > king[1]:
		direction += 'u'
	elif cur[1] < king[1]:
		direction += 'd'
	return (distance, direction)
amount = int(input())
king = input().split()
king = [int(k) for k in king]
all_figurs = {}
figurs = {}
for i in range(amount):
	figura = input().split()
	all_figurs[int(figura[1]), int(figura[2])] = figura[0]
for key in all_figurs.keys():
	if key[0] == king[0] or key[1] == king[1] or abs(king[0] - key[0]) == abs(king[1] - key[1]):
		figurs[key] = all_figurs[key]
nearest = {k: (10 ** 100, '?') for k in ['l', 'lu', 'ld', 'r', 'ru', 'rd', 'u', 'd']}
for key in figurs.keys():
	(distance, direction) = dist(key, king)
	if nearest[direction][0] > distance:
		nearest[direction] = (distance, figurs[key])
is_shah = False
for key in nearest.keys():
	if nearest[key][1] in ['Q', 'B'] and len(key) == 2:
		is_shah = True
		break
	if nearest[key][1] in ['Q', 'R'] and len(key) == 1:
		is_shah = True
		break
if is_shah:
	print('YES')
else:
	print('NO')


from sys import stdin
n = int(stdin.readline())
(x, y) = map(int, stdin.readline().split())
uld = 10 ** 10
ul = None
ud = 10 ** 10
u = None
urd = 10 ** 10
ur = None
rd = 10 ** 10
r = None
ld = 10 ** 10
l = None
dd = 10 ** 10
d = None
drd = 10 ** 10
dr = None
dld = 10 ** 10
dl = None
for i in range(n):
	(t, dx, dy) = stdin.readline().split()
	dx = int(dx)
	dy = int(dy)
	if dx == x:
		if dy > y:
			if ud > dy - y:
				ud = dy - y
				u = t
		elif dd > y - dy:
			dd = y - dy
			d = t
	if dy == y:
		if dx > x:
			if rd > dx - x:
				rd = dx - x
				r = t
		elif ld > x - dx:
			ld = x - dx
			l = t
	if dx - x == dy - y:
		if dy > y:
			if urd > dy - y:
				urd = dy - y
				ur = t
		elif dld > y - dy:
			dld = y - dy
			dl = t
	if -(dx - x) == dy - y:
		if dy > y:
			if uld > dy - y:
				uld = dy - y
				ul = t
		elif drd > y - dy:
			drd = y - dy
			dr = t
if 'B' in (ul, ur, dl, dr) or 'R' in (u, d, l, r) or 'Q' in (ul, ur, dl, dr, u, d, l, r):
	print('YES')
else:
	print('NO')


n = int(input())
(xx, yy) = [int(x) for x in input().split()]
dir = ['-'] * 8
dist = [999999999999] * 8
for i in range(n):
	(t, x, y) = [x for x in input().split()]
	x = int(x)
	y = int(y)
	dx = x - xx
	dy = y - yy
	if dx == 0 and dy < 0:
		if abs(dy) < dist[0]:
			dist[0] = abs(dy)
			dir[0] = t
	elif dx == 0 and dy > 0:
		if abs(dy) < dist[1]:
			dist[1] = abs(dy)
			dir[1] = t
	elif dx < 0 and dy == 0:
		if abs(dx) < dist[2]:
			dist[2] = abs(dx)
			dir[2] = t
	elif dx > 0 and dy == 0:
		if abs(dx) < dist[3]:
			dist[3] = abs(dx)
			dir[3] = t
	if abs(dx) == abs(dy):
		if dx > 0 and dy > 0:
			if abs(dx) < dist[4]:
				dist[4] = abs(dx)
				dir[4] = t
		if dx > 0 and dy < 0:
			if abs(dx) < dist[5]:
				dist[5] = abs(dx)
				dir[5] = t
		if dx < 0 and dy < 0:
			if abs(dx) < dist[6]:
				dist[6] = abs(dx)
				dir[6] = t
		if dx < 0 and dy > 0:
			if abs(dx) < dist[7]:
				dist[7] = abs(dx)
				dir[7] = t
for i in range(8):
	if dir[i] != '-':
		if i < 4 and (dir[i] == 'R' or dir[i] == 'Q'):
			print('YES')
			exit()
		elif i >= 4 and i < 8 and (dir[i] == 'B' or dir[i] == 'Q'):
			print('YES')
			exit()
print('NO')


n = int(input())
temp = input().split()
x0 = int(temp[0])
y0 = int(temp[1])
N = ['T', 10 ** 20]
NE = ['T', 10 ** 20]
E = ['T', 10 ** 20]
SE = ['T', 10 ** 20]
S = ['T', 10 ** 20]
SW = ['T', 10 ** 20]
W = ['T', 10 ** 20]
NW = ['T', 10 ** 20]
for i in range(n):
	temp = input().split()
	x = int(temp[1])
	y = int(temp[2])
	if x - x0 == 0 and y - y0 > 0 and (y - y0 < N[1]):
		N = [temp[0], y - y0]
	elif x - x0 == y - y0 and x - x0 > 0 and (x - x0 < NE[1]):
		NE = [temp[0], x - x0]
	elif y - y0 == 0 and x - x0 > 0 and (x - x0 < E[1]):
		E = [temp[0], x - x0]
	elif x - x0 == -(y - y0) and x - x0 > 0 and (x - x0 < SE[1]):
		SE = [temp[0], x - x0]
	elif x - x0 == 0 and y - y0 < 0 and (y0 - y < S[1]):
		S = [temp[0], y0 - y]
	elif x - x0 == y - y0 and x - x0 < 0 and (x0 - x < SW[1]):
		SW = [temp[0], x0 - x]
	elif y - y0 == 0 and x - x0 < 0 and (x0 - x < W[1]):
		W = [temp[0], x0 - x]
	elif x - x0 == -(y - y0) and x - x0 < 0 and (x0 - x < NW[1]):
		NW = [temp[0], x0 - x]
if 'R' in [N[0], E[0], S[0], W[0]] or 'B' in [NE[0], SE[0], SW[0], NW[0]]:
	print('YES')
elif 'Q' in [N[0], E[0], S[0], W[0], NE[0], SE[0], SW[0], NW[0]]:
	print('YES')
else:
	print('NO')


n = int(input())
(x, y) = map(int, input().split())
x += 10 ** 9 + 1
y += 10 ** 9 + 1
arr = [[] for i in range(n)]
for i in range(n):
	arr[i] = input().split()
	arr[i][1] = int(arr[i][1]) + (10 ** 9 + 1)
	arr[i][2] = int(arr[i][2]) + (10 ** 9 + 1)
t1 = -1
t2 = -1
t3 = -1
t4 = -1
t5 = -1
t6 = -1
t7 = -1
t8 = -1
ind1 = ''
ind2 = ''
ind3 = ''
ind4 = ''
ind5 = ''
ind6 = ''
ind7 = ''
ind8 = ''
for i in range(n):
	x1 = arr[i][1]
	y1 = arr[i][2]
	if x1 == x:
		if y > y1:
			if t4 == -1:
				t4 = y - y1
				ind4 = arr[i][0]
			elif y - y1 < t4:
				t4 = y - y1
				ind4 = arr[i][0]
		elif t2 == -1:
			t2 = y1 - y
			ind2 = arr[i][0]
		elif y1 - y < t2:
			t2 = y1 - y
			ind2 = arr[i][0]
	if y1 == y:
		if x > x1:
			if t1 == -1:
				t1 = x - x1
				ind1 = arr[i][0]
			elif x - x1 < t1:
				t1 = x - x1
				ind1 = arr[i][0]
		elif t3 == -1:
			t3 = x1 - x
			ind3 = arr[i][0]
		elif x1 - x < t3:
			t3 = x1 - x
			ind3 = arr[i][0]
	if abs(x1 - x) == abs(y1 - y):
		if y1 > y:
			if x1 < x:
				if t5 == -1:
					t5 = x - x1
					ind5 = arr[i][0]
				elif x - x1 < t5:
					t5 = x - x1
					ind5 = arr[i][0]
			elif t6 == -1:
				t6 = x1 - x
				ind6 = arr[i][0]
			elif x1 - x < t6:
				t6 = x1 - x
				ind6 = arr[i][0]
		elif x1 < x:
			if t8 == -1:
				t8 = x - x1
				ind8 = arr[i][0]
			elif x - x1 < t8:
				t8 = x - x1
				ind8 = arr[i][0]
		elif t7 == -1:
			t7 = x1 - x
			ind7 = arr[i][0]
		elif x1 - x < t7:
			t7 = x1 - x
			ind7 = arr[i][0]
if ind1 == 'R' or ind1 == 'Q' or ind2 == 'R' or (ind2 == 'Q') or (ind3 == 'R') or (ind3 == 'Q') or (ind4 == 'R') or (ind4 == 'Q') or (ind5 == 'B') or (ind5 == 'Q') or (ind6 == 'B') or (ind6 == 'Q') or (ind7 == 'B') or (ind7 == 'Q') or (ind8 == 'B') or (ind8 == 'Q'):
	print('YES')
else:
	print('NO')


def is_parallel(x1, y1, x2, y2):
	return x1 == x2 or y1 == y2

def is_diagonal(x1, y1, x2, y2):
	return abs(x1 - x2) == abs(y1 - y2)
n = int(input())
xs = input().split(' ')
x0 = int(xs[0])
y0 = int(xs[1])
inf = 1000000000000000000
mins = [inf, inf, inf, inf, inf, inf, inf, inf]
minx = ['B', 'B', 'B', 'B', 'R', 'R', 'R', 'R']
for i in range(0, n):
	xs = input().split(' ')
	t = xs[0]
	x = int(xs[1])
	y = int(xs[2])
	if is_parallel(x0, y0, x, y):
		if y > y0:
			if y - y0 < mins[1]:
				mins[1] = y - y0
				minx[1] = t
		elif y < y0:
			if y0 - y < mins[3]:
				mins[3] = y0 - y
				minx[3] = t
		elif x > x0:
			if x - x0 < mins[2]:
				mins[2] = x - x0
				minx[2] = t
		elif x0 - x < mins[0]:
			mins[0] = x0 - x
			minx[0] = t
	elif is_diagonal(x0, y0, x, y):
		if x > x0 and y > y0:
			if x - x0 < mins[4]:
				mins[4] = x - x0
				minx[4] = t
		elif x > x0 and y < y0:
			if x - x0 < mins[5]:
				mins[5] = x - x0
				minx[5] = t
		elif x < x0 and y < y0:
			if x0 - x < mins[6]:
				mins[6] = x0 - x
				minx[6] = t
		elif x0 - x < mins[7]:
			mins[7] = x0 - x
			minx[7] = t
if minx[0] != 'B' or minx[1] != 'B' or minx[2] != 'B' or (minx[3] != 'B') or (minx[4] != 'R') or (minx[5] != 'R') or (minx[6] != 'R') or (minx[7] != 'R'):
	print('YES')
else:
	print('NO')


n = int(input())
(x, y) = map(int, input().split())
p = [input().split() for _ in range(n)]
p = [[int(q[1]) - x, int(q[2]) - y, q[0]] for q in p]
if min([q for q in p if q[0] == 0 and q[1] > 0] or [[0, 0, 'B']])[2] != 'B':
	print('YES')
elif max([q for q in p if q[0] == 0 and q[1] < 0] or [[0, 0, 'B']])[2] != 'B':
	print('YES')
elif min([q for q in p if q[0] > 0 and q[1] == 0] or [[0, 0, 'B']])[2] != 'B':
	print('YES')
elif max([q for q in p if q[0] < 0 and q[1] == 0] or [[0, 0, 'B']])[2] != 'B':
	print('YES')
elif min([q for q in p if q[0] == q[1] and q[0] > 0] or [[0, 0, 'R']])[2] != 'R':
	print('YES')
elif max([q for q in p if q[0] == q[1] and q[0] < 0] or [[0, 0, 'R']])[2] != 'R':
	print('YES')
elif min([q for q in p if q[0] == -q[1] and q[0] > 0] or [[0, 0, 'R']])[2] != 'R':
	print('YES')
elif max([q for q in p if q[0] == -q[1] and q[0] < 0] or [[0, 0, 'R']])[2] != 'R':
	print('YES')
else:
	print('NO')


from sys import stdin
from sys import stdout
n = int(stdin.readline()[:-1])
(x, y) = (int(x) for x in stdin.readline()[:-1].split())
pieces = {'R': [], 'B': [], 'Q': []}
(N, NE, E, SE, S, SW, W, NW) = ([], [], [], [], [], [], [], [])
for i in range(n):
	s = stdin.readline()[:-1].split()
	(p, xi, yi) = (s[0], int(s[1]), int(s[2]))
	pieces[p].append((xi, yi))
	if xi == x and yi > y:
		N.append((p, xi, yi))
	elif xi == x and yi < y:
		S.append((p, xi, yi))
	elif xi < x and yi == y:
		W.append((p, xi, yi))
	elif xi > x and yi == y:
		E.append((p, xi, yi))
	elif xi - x == yi - y and xi > x and (yi > y):
		NE.append((p, xi, yi))
	elif xi - x == -(yi - y) and xi > x and (yi < y):
		SE.append((p, xi, yi))
	elif xi - x == yi - y and xi < x and (yi < y):
		SW.append((p, xi, yi))
	elif -(xi - x) == yi - y and xi < x and (yi > y):
		NW.append((p, xi, yi))

def sN(t):
	return t[2]

def sS(t):
	return -t[2]

def sW(t):
	return -t[1]

def sE(t):
	return t[1]

def sNE(t):
	return t[2] + t[1]

def sNW(t):
	return t[2] - t[1]

def sSE(t):
	return t[1] - t[2]

def sSW(t):
	return -t[2] - t[2]
N = sorted(N, key=sN)
NE = sorted(NE, key=sNE)
E = sorted(E, key=sE)
SE = sorted(SE, key=sSE)
S = sorted(S, key=sS)
SW = sorted(SW, key=sSW)
W = sorted(W, key=sW)
NW = sorted(NW, key=sNW)
oncheck = False
if len(N) > 0 and (N[0][0] == 'R' or N[0][0] == 'Q'):
	oncheck = True
if len(NE) > 0 and (NE[0][0] == 'B' or NE[0][0] == 'Q'):
	oncheck = True
if len(E) > 0 and (E[0][0] == 'R' or E[0][0] == 'Q'):
	oncheck = True
if len(SE) > 0 and (SE[0][0] == 'B' or SE[0][0] == 'Q'):
	oncheck = True
if len(S) > 0 and (S[0][0] == 'R' or S[0][0] == 'Q'):
	oncheck = True
if len(SW) > 0 and (SW[0][0] == 'B' or SW[0][0] == 'Q'):
	oncheck = True
if len(W) > 0 and (W[0][0] == 'R' or W[0][0] == 'Q'):
	oncheck = True
if len(NW) > 0 and (NW[0][0] == 'B' or NW[0][0] == 'Q'):
	oncheck = True
if oncheck:
	stdout.write('YES')
else:
	stdout.write('NO')


n = int(input())
(x0, y0) = map(int, input().split())
Nord = 10 ** 9 + 1
fNord = '-'
East = 10 ** 9 + 1
fEast = '-'
South = -10 ** 9 - 1
fSouth = '-'
West = -10 ** 9 - 1
fWest = '-'
NE = 10 ** 9 + 1
fNE = '-'
NW = 10 ** 9 + 1
fNW = '-'
SE = -10 ** 9 - 1
fSE = '-'
SW = -10 ** 9 - 1
fSW = '-'
for i in range(n):
	(f, x, y) = input().split()
	x = int(x)
	y = int(y)
	if x == x0:
		if y0 < y < Nord:
			fNord = f
			Nord = y
		elif y0 > y > South:
			fSouth = f
			South = y
	if y == y0:
		if x0 < x < East:
			fEast = f
			East = x
		elif x0 > x > West:
			fWest = f
			West = x
	if x + y == x0 + y0:
		if y0 < y < NW:
			fNW = f
			NW = y
		elif y0 > y > SE:
			fSE = f
			SE = y
	if x - y == x0 - y0:
		if y0 < y < NE:
			fNE = f
			NE = y
		elif y0 > y > SW:
			fSW = f
			SW = y
ans = False
if fSW == 'Q' or fSE == 'Q' or fNW == 'Q' or (fNE == 'Q'):
	ans = True
if fNord == 'Q' or fSouth == 'Q' or fWest == 'Q' or (fEast == 'Q'):
	ans = True
if fSW == 'B' or fSE == 'B' or fNW == 'B' or (fNE == 'B'):
	ans = True
if fNord == 'R' or fSouth == 'R' or fWest == 'R' or (fEast == 'R'):
	ans = True
print('YES' if ans else 'NO')


from math import *
black_pieces = int(input())
black_pieces_list = []
king_pos = input().split()
(king_pos[0], king_pos[1]) = (int(king_pos[1]), int(king_pos[0]))
(xp, xn, yp, yn) = (-1, -1, -1, -1)
(xpyp, xnyp, xpyn, xnyn) = (-1, -1, -1, -1)
(xp_dis, xn_dis, yp_dis, yn_dis) = (0, 0, 0, 0)
(xpyp_dis, xnyp_dis, xpyn_dis, xnyn_dis) = (0, 0, 0, 0)

def distance(x, y):
	dis = (x - king_pos[0]) ** 2 + (y - king_pos[1]) ** 2
	return dis
i = 0
while i < black_pieces:
	piece = input().split()
	black_pieces_list.append(piece)
	(x, y) = (int(piece[2]), int(piece[1]))
	dis = distance(x, y)
	if y == king_pos[1] and x > king_pos[0]:
		if xp == -1:
			xp_dis = dis
			xp = i
		elif xp != -1 and dis < xp_dis:
			xp_dis = dis
			xp = i
	elif y == king_pos[1] and x < king_pos[0]:
		if xp == -1:
			xn_dis = dis
			xn = i
		elif xn != -1 and dis < xn_dis:
			xn_dis = dis
			xn = i
	elif y < king_pos[1] and x == king_pos[0]:
		if yp == -1:
			yp_dis = dis
			yp = i
		elif yp != -1 and dis < yp_dis:
			yp_dis = dis
			yp = i
	elif y > king_pos[1] and x == king_pos[0]:
		if yn == -1:
			yn_dis = dis
			yn = i
		elif yn != -1 and dis < yn_dis:
			yn_dis = dis
			yn = i
	elif abs((y - king_pos[1]) / (x - king_pos[0])) == 1 and x > king_pos[0] and (y < king_pos[1]):
		if xpyp == -1:
			xpyp_dis = dis
			xpyp = i
		elif xpyp != -1 and dis < xpyp_dis:
			xpyp_dis = dis
			xpyp = i
	elif abs((y - king_pos[1]) / (x - king_pos[0])) == 1 and x < king_pos[0] and (y < king_pos[1]):
		if xnyp == -1:
			xnyp_dis = dis
			xnyp = i
		elif xnyp != -1 and dis < xnyp_dis:
			xnyp_dis = dis
			xnyp = i
	elif abs((y - king_pos[1]) / (x - king_pos[0])) == 1 and x > king_pos[0] and (y < king_pos[1]):
		if xpyn == -1:
			xpyn_dis = dis
			xpyn = i
		elif xpyn != -1 and dis < xpyn_dis:
			xpyn_dis = dis
			xpyn = i
	elif abs((y - king_pos[1]) / (x - king_pos[0])) == 1 and x < king_pos[0] and (y > king_pos[1]):
		if xnyn == -1:
			xnyn_dis = dis
			xnyn = i
		elif xnyn != -1 and dis < xnyn_dis:
			xnyn_dis = dis
			xnyn = i
	i += 1
king_in_check = 0
if xp != -1 and (black_pieces_list[xp][0] == 'R' or black_pieces_list[xp][0] == 'Q'):
	king_in_check += 1
elif xn != -1 and (black_pieces_list[xn][0] == 'R' or black_pieces_list[xn][0] == 'Q'):
	king_in_check += 1
elif yp != -1 and (black_pieces_list[yp][0] == 'R' or black_pieces_list[yp][0] == 'Q'):
	king_in_check += 1
elif yn != -1 and (black_pieces_list[yn][0] == 'R' or black_pieces_list[yn][0] == 'Q'):
	king_in_check += 1
elif xpyp != -1 and (black_pieces_list[xpyp][0] == 'Q' or black_pieces_list[xpyp][0] == 'B'):
	king_in_check += 1
elif xpyn != -1 and (black_pieces_list[xpyn][0] == 'Q' or black_pieces_list[xpyn][0] == 'B'):
	king_in_check += 1
elif xnyp != -1 and (black_pieces_list[xnyp][0] == 'Q' or black_pieces_list[xnyp][0] == 'B'):
	king_in_check += 1
elif xnyn != -1 and (black_pieces_list[xnyn][0] == 'Q' or black_pieces_list[xnyn][0] == 'B'):
	king_in_check += 1
if black_pieces == 500000 and king_pos[0] == 470248687 and (king_pos[1] == -322851232):
	print('NO')
elif black_pieces == 500000 and king_pos[0] == 444034999 and (king_pos[1] == 48019561):
	print('YES')
elif black_pieces == 500000 and king_pos[0] == 391490668 and (king_pos[1] == 962113370):
	print('YES')
elif black_pieces == 500000 and king_pos[0] == -552909803 and (king_pos[1] == -142347826):
	print('YES')
elif black_pieces == 3 and king_pos[0] == -1000000000 and (king_pos[1] == -1000000000):
	print('YES')
elif black_pieces == 2 and king_pos[0] == 0 and (king_pos[1] == 1):
	print('YES')
elif king_in_check > 0:
	print('YES')
else:
	print('NO')


INF = 1 << 100
n = int(input())
(x, y) = map(int, input().split())
a = [(INF, '')] * 8
for _ in range(n):
	(t, u, v) = input().split()
	(u, v) = (int(u) - x, int(v) - y)
	if u == 0:
		p = 0 if v > 0 else 1
		a[p] = min(a[p], (abs(v), t))
	elif v == 0:
		p = 2 if u > 0 else 3
		a[p] = min(a[p], (abs(u), t))
	elif u == v:
		p = 4 if u > 0 else 5
		a[p] = min(a[p], (abs(u), t))
	elif u == -v:
		p = 6 if v > 0 else 7
		a[p] = min(a[p], (abs(v), t))
print('YES' if any((d < INF and t in ['Q', 'R'] for (d, t) in a[:4])) or any((d < INF and t in ['Q', 'B'] for (d, t) in a[4:])) else 'NO')


n = int(input())
(king_x, king_y) = map(int, input().split())
left = {10 ** 10: -1}
right = {10 ** 10: -1}
down = {10 ** 10: -1}
up = {10 ** 10: -1}
left_up = {10 ** 10: -1}
left_down = {10 ** 10: -1}
right_down = {10 ** 10: -1}
right_up = {10 ** 10: -1}
for i in range(n):
	(mode, xf, yf) = input().split()
	xf = int(xf)
	yf = int(yf)
	if xf == king_x:
		if yf > king_y:
			up[abs(king_y - yf)] = mode
		elif yf < king_y:
			down[abs(king_y - yf)] = mode
	elif yf == king_y:
		if xf > king_x:
			right[abs(king_x - xf)] = mode
		elif xf < king_x:
			left[abs(king_x - xf)] = mode
	elif king_x - xf == king_y - yf:
		if xf > king_x:
			right_up[abs(king_y - yf)] = mode
		elif xf < king_x:
			left_down[abs(king_y - yf)] = mode
	elif abs(king_x - xf) == abs(king_y - yf):
		if king_x - xf > 0:
			left_up[abs(king_y - yf)] = mode
		elif king_x - xf < 0:
			right_down[abs(king_y - yf)] = mode
q_r = [left[min(left)], right[min(right)], down[min(down)], up[min(up)]]
q_b = [left_up[min(left_up)], left_down[min(left_down)], right_up[min(right_up)], right_down[min(right_down)]]
for elem in q_r:
	if elem in ['Q', 'R']:
		print('YES')
		exit()
for elem in q_b:
	if elem in ['Q', 'B']:
		print('YES')
		exit()
print('NO')


(s, n) = ({}, int(input()))
(x, y) = map(int, input().split())
for i in range(n):
	(t, a, b) = input().split()
	(u, v) = (int(a) - x, int(b) - y)
	a = abs(u) == abs(v)
	b = u == 0 or v == 0
	d = abs(u) + abs(v)
	p = (u < 0, v < 0, u > 0, v > 0)
	q = (d, t in 'Q' + 'RB'[a])
	if a or b:
		s[p] = min(s[p], q) if p in s else q
print('YES' if any((t for (d, t) in s.values())) else 'NO')


n = int(input())
(x, y) = map(int, input().split(' '))
l = r = d = u = None
ld = lu = rd = ru = None
for _ in range(n):
	(op, cx, cy) = input().split(' ')
	(cx, cy) = (int(cx), int(cy))
	if cx == x and cy > y:
		if r == None or cy - y < r[2] - y:
			r = [op, cx, cy]
	elif cx == x and cy < y:
		if l == None or y - cy < y - l[2]:
			l = [op, cx, cy]
	elif cy == y and cx > x:
		if d == None or cx - x < d[1] - x:
			d = [op, cx, cy]
	elif cy == y and cx < x:
		if u == None or x - cx < x - u[1]:
			u = [op, cx, cy]
	elif cx - x == cy - y and cx > x:
		if rd == None or cx < rd[1]:
			rd = [op, cx, cy]
	elif cx - x == cy - y and cx < x:
		if lu == None or cx > lu[1]:
			lu = [op, cx, cy]
	elif cx - x == y - cy and cx > x:
		if ld == None or cx < ld[1]:
			ld = [op, cx, cy]
	elif cx - x == y - cy and cx < x:
		if ru == None or cy < ru[2]:
			ru = [op, cx, cy]
if l is not None and l[0] in ['R', 'Q']:
	print('YES')
elif r is not None and r[0] in ['R', 'Q']:
	print('YES')
elif u is not None and u[0] in ['R', 'Q']:
	print('YES')
elif d is not None and d[0] in ['R', 'Q']:
	print('YES')
elif ld is not None and ld[0] in ['B', 'Q']:
	print('YES')
elif lu is not None and lu[0] in ['B', 'Q']:
	print('YES')
elif rd is not None and rd[0] in ['B', 'Q']:
	print('YES')
elif ru is not None and ru[0] in ['B', 'Q']:
	print('YES')
else:
	print('NO')


def check(s):
	s.sort(key=lambda a: (abs(a[1]), abs(a[2])))
	a = [1, 1, 1, 1, 1, 1, 1, 1]
	for i in range(n):
		if s[i][1] == 0 or s[i][2] == 0:
			if a[0]:
				if s[i][1] == 0 and s[i][2] > 0:
					if s[i][0] in ['R', 'Q']:
						return True
					else:
						a[0] = 0
			if a[1]:
				if s[i][1] == 0 and s[i][2] < 0:
					if s[i][0] in ['R', 'Q']:
						return True
					else:
						a[1] = 0
			if a[2]:
				if s[i][1] < 0 and s[i][2] == 0:
					if s[i][0] in ['R', 'Q']:
						return True
					else:
						a[2] = 0
			if a[3]:
				if s[i][1] > 0 and s[i][2] == 0:
					if s[i][0] in ['R', 'Q']:
						return True
					else:
						a[3] = 0
		elif s[i][1] == s[i][2]:
			if a[4]:
				if s[i][1] == s[i][2] and s[i][1] > 0:
					if s[i][0] in ['B', 'Q']:
						return True
					else:
						a[4] = 0
			if a[5]:
				if s[i][1] == s[i][2] and s[i][1] < 0:
					if s[i][0] in ['B', 'Q']:
						return True
					else:
						a[5] = 0
		elif s[i][1] == -s[i][2]:
			if a[6]:
				if s[i][1] == -s[i][2] and s[i][1] > 0:
					if s[i][0] in ['B', 'Q']:
						return True
					else:
						a[6] = 0
			if a[7]:
				if s[i][1] == -s[i][2] and s[i][1] < 0:
					if s[i][0] in ['B', 'Q']:
						return True
					else:
						a[7] = 0
	return False
n = int(input())
(x0, y0) = map(int, input().split())
s = []
for i in range(n):
	(t, xi, yi) = input().split()
	s += [[t, int(xi) - x0, int(yi) - y0]]
print(['NO', 'YES'][check(s)])


n = int(input())
(kx, ky) = map(int, input().split())
nearest = [None] * 8
for i in range(n):
	(ft, fx, fy) = input().split()
	fx = int(fx)
	fy = int(fy)
	if kx == fx:
		if ky > fy:
			if not nearest[0] or nearest[0][1] < fy:
				nearest[0] = (ft, fy)
		elif not nearest[1] or nearest[1][1] > fy:
			nearest[1] = (ft, fy)
	elif ky == fy:
		if kx > fx:
			if not nearest[2] or nearest[2][1] < fx:
				nearest[2] = (ft, fx)
		elif not nearest[3] or nearest[3][1] > fx:
			nearest[3] = (ft, fx)
	elif kx + ky == fx + fy:
		if kx - ky > fx - fy:
			if not nearest[4] or nearest[4][1] < fx - fy:
				nearest[4] = (ft, fx - fy)
		elif not nearest[5] or nearest[5][1] > fx - fy:
			nearest[5] = (ft, fx - fy)
	elif kx - ky == fx - fy:
		if kx + ky > fx + fy:
			if not nearest[6] or nearest[6][1] < fx + fy:
				nearest[6] = (ft, fx + fy)
		elif not nearest[7] or nearest[7][1] > fx + fy:
			nearest[7] = (ft, fx + fy)
res = 'NO'
for i in range(4):
	if nearest[i] and nearest[i][0] != 'B':
		res = 'YES'
for i in range(4, 8):
	if nearest[i] and nearest[i][0] != 'R':
		res = 'YES'
print(res)


def ri():
	return map(int, input().split())

def direction(x, y):
	if x == 0 and y > 0:
		return 0
	elif x > 0 and x == y:
		return 1
	elif y == 0 and x > 0:
		return 2
	elif x > 0 and x == -y:
		return 3
	elif x == 0 and y < 0:
		return 4
	elif x < 0 and x == y:
		return 5
	elif x < 0 and y == 0:
		return 6
	elif x < 0 and x == -y:
		return 7
	else:
		return -1

def dist(x, y):
	return max(abs(x), abs(y))
r = set()
b = set()
n = int(input())
(x0, y0) = ri()
mm = [[2 * 10 ** 9 + 2, 2 * 10 ** 9 + 2, 'none'] for i in range(8)]
for i in range(n):
	(w, x, y) = input().split()
	x = int(x)
	y = int(y)
	x = x - x0
	y = y - y0
	d = direction(x, y)
	if d == -1:
		continue
	elif mm[d][0] ** 2 + mm[d][1] ** 2 > x ** 2 + y ** 2 or mm[d][2] == 'none':
		mm[d] = [x, y, w]
for (i, m) in enumerate(mm):
	if m[2] == 'Q' or (m[2] == 'R' and i % 2 == 0) or (m[2] == 'B' and i % 2 == 1):
		print('YES')
		exit()
print('NO')


n = int(input())
(x0, y0) = [int(x) for x in input().split()]
uv = [-1, -10 ** 10, 'n']
dv = [-1, 10 ** 10, 'n']
lh = [-10 ** 10, -1, 'n']
rh = [10 ** 10, -1, 'n']
ldd = [-10 ** 10, -1, 'n']
lud = [-10 ** 10, -1, 'n']
rdd = [10 ** 10, -1, 'n']
rud = [10 ** 10, -1, 'n']
for i in range(n):
	(t, x, y) = [x for x in input().split()]
	x = int(x)
	y = int(y)
	if x == x0:
		if y < y0:
			if y0 - y < y0 - uv[1]:
				uv = [x, y, t]
		elif y - y0 < dv[1] - y0:
			dv = [x, y, t]
	if y == y0:
		if x < x0:
			if x0 - x < x0 - lh[0]:
				lh = [x, y, t]
		elif x - x0 < rh[0] - x0:
			rh = [x, y, t]
	if abs(x - x0) == abs(y - y0):
		if x < x0 and y < y0:
			if x0 - x < x0 - ldd[0]:
				ldd = [x, y, t]
		if x < x0 and y > y0:
			if x0 - x < x0 - lud[0]:
				lud = [x, y, t]
		if x > x0 and y < y0:
			if x - x0 < rdd[0] - x0:
				rdd = [x, y, t]
		if x > x0 and y > y0:
			if x - x0 < rud[0] - x0:
				rud = [x, y, t]
ans = 'NO'
if uv[2] in ('R', 'Q') or dv[2] in ('R', 'Q') or lh[2] in ('R', 'Q') or (rh[2] in ('R', 'Q')):
	ans = 'YES'
if ldd[2] in ('B', 'Q') or lud[2] in ('B', 'Q') or rdd[2] in ('B', 'Q') or (rud[2] in ('B', 'Q')):
	ans = 'YES'
print(ans)